Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
LABORATORY MANUAL
th
VII Semester
E8-Batch
Head of Department
GANPAT UNIVERSITY
U.V.PATEL COLLEGE OF ENGINEERING
DEPARTMENT OF MECHANICAL ENGINEERING
B. TECH. VII SEMESTER
2ME704-COMPUTER AIDED DESIGN
EXPERIMENT LIST
LAB INCHARGE
GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 1 DATE:___/___/______
Originally CAD includes any techniques that use computers in the design process including
drafting, stress analysis and motion analysis.
But over the last 35 years, CAD has come to refer more specifically to Computer Aided Design
and Drafting.
CAD program/software is an electronic tool that enables you to make quick and accurate
drawings with the use of a computer.
Computer drawings are neat, clean, highly presentable, and can be modified easily.
With CAD, parts or components can be modeled, visualized, revised, and improve on the
computer screen before any engineering drawings have been created.
Parts that have been modeled can be assembled in the virtual environment of the computer.
The relative motion of moving parts can be animated on the computer.
The part can be analyzed computationally and redesigned.
The machine tool path or mold filling flow to fabricate the part can be modeled on the computer.
The part model can be downloaded to a rapid prototyping system that can create a physical model
of the part in a few hours with virtually no human intervention.
CAPABILITIES OF CAD:
1. Presentations:
You can create fine drawings with presentation symbols and text styles.
You can use CAD program to make on screen presentations.
2. Flexibility in editing:
CAD program allows you to work with great accuracy. You can also work with different units of
measure, such as architectural units, engineering units, scientific units and surveyor units.
It is quick and convenient to organize CAD drawings. You can have thousands of drawings on a
computer‟s hard disk and you can open any one of them within seconds.
The drawings can be shared by a number of users, allowing them to coordinate projects and work
as a team. This is accomplished by connecting different computers via a network. You can also
publish your drawings on the Internet and collaborate CAD projects using a web site.
6. Project reporting:
7. Engineering analysis:
There is a separate category of programs called CAE that can use CAD drawings for engineering
analysis.
CAD MODELS:
Can be used for stress analysis, heat transfer analysis, fluid flow analysis, and computer aided
manufacturing.
In the manufacturing process to automatically generate machine tool paths to machine an object.
To simulate the removal of material from an initial block of material on the computer
Can be linked to Computer Numerical Control CNC) machine to carry out the removal of material
automatically allowing many identical parts to be machined based directly on the solid model.
Definition of
Geometric Model
Definition of
Translator
Geometric Model
Interface Algorithms
Drafting and
Detailing
Documentation
To CAM Process
Geometric Model
Interface Algorithms
Process Planning
NC Program
Inspection
Assembly
Packaging
HISTORY OF CAD/CAM:
Phase of Developments:
1950s: Start of interactive computer graphics,
CRT (Cathode Ray Tube), NC (Numerical Control),
APT (Automatically Programmed Tools)
1960s: Critical research period for interactive computer graphics
1970s: Potential of interactive computer graphics was realized by industry,
SIGGRAPH, NCGA, IGES,
Golden era for computer drafting,
Wireframe modeling
1980s: CAD/CAM heady years of research,
Integration, Solid modeling
1990s: CIM, EDB, PDM, CALS, VR
Main
factors that determine the success of CAM implementation
The link between CAD and CAM must be a two-way route
The hardware and software networking of the various CAM elements
Timely synchronization among robots, vision systems, manufacturing cells, material handling
systems, and other shop-floor tasks is most important.
If the system's standard software cannot handle the problem, a customized software may be
developed using the programming language (Macro, API programming)
FIGURE1.1-
a) A general two dimensional domain of field variable Φ(x, y).
b) A three node finite element defined in the domain
c) Additional element showing a partial finite element meshes of the domain.
A small triangular element that encloses finite-sized sub domain of the area of interest is shown in figure
1.1b. that this element is not a differential element of size dx * dy makes this a finite element as we treat
this example as at two dimensional problem, it is assumed that the thickness in the z direction constant
and z dependency is not indicated in the differential equation. The vertices of the triangular element are
numbered to indicate that this point is nodes. A node is a specific point in the finite element at which the
value of the field variable is to be explicitly calculated. Exterior nodes are located on the boundaries of
the finite element and may be used to connect an element to adjacent finite element. Nodes that do not lie
on element boundaries are interior nodes and cannot be connected to any other element of figure 1.1b has
only exterior
Nodes. if the value of field variable are computed only a nodes, how are values obtained at other point
within a finite elements? The answer contains the crux of the finite element method: The values of the
field variable computed at the nodes are used to approximate the values at no nodal points (that is, in the
element interior) by interpolation of the nodal values. For the three node trial example, the notes are
exterior and, at any other point within the element, the field variable is described by the approximation
relation
Where, 1 , 2 , 3 are the values of the field variable at the nodes, and N1, N2 andN3
are the interpolation functions, also known as shape functions or blending functions. In the finite element
approach the nodal values of the field variable are treated as unknown constants that are to be
determined. The interpolation functions are most often polynomial forms of the independent variables,
derived to satisfy certain required condition at the nodes. This condition is discussed in detail in
subsequent chap. The major point to be made hear is that interpolation fun are predetermine, known fun
of the independent variables ; and this fun describe the variation of the field variable within the finite
elements.
The triangle element described by equation os said to have 3 degrees of freedom, as 3 nodal values of the
field variable are required to described the field variable everywhere in the element. These would be the
case if the field variables represent a scalar field, such temperature in heat transfer problem. If the
domain of fig represents a thin, solid body subjected to plan tress. The field variable becomes the
displacement vector and value of two components must be computed at each node. In the later case, the
three node triangular element has six degree of freedom. In generally the no of degree of freedom,
associated with a finite element is equal to the product of the no of nodes and the no of value of field
variable must be competed at each node.
How the element does base approach work over the entire domain of interest? Every element is
connected at its exterior nods to other elements. The finite element edge are formulated structure, at the
node connection, the value of the field variable at any connection is the same for each elements
connected to tee node. Thus, continuity of the field variable across inter element boundaries is also
ensured this future avoids the physically unacceptable possibility of gaps for avoids local separation of
the material in heat transfer, a gape, would manifest itself in the form of diff tam at the same physical
point.
Although continuity of the field variable from element to element is Inherent to the finite element
formulation, inter element continuity of gradient of the field varied does not generally exist. This is
critical observation. In most cases such derivative are of more interest than are field variables. for
example is structural problems the field VA.
Reliable is displacement but the true interest is more often in strain and stress. As strain is define in terms
of first derivative of displacement components, strain is not continuous across element boundaries.
However, the magnitude of discontinuities of derivatives can be used to excess solution accuration and
convergence ac the nu of elements is increased, ac ii illustrated by the following example.
The process of representing in physical domain while finite elements is referred to as meshing and the
resulting set of element is known as finite element mesh as most of commonly used element geometries
have state sides, it is generally impossible to include the entire physical domain in the mesh. If the
domain include curved boundary .such a situation is sown in fig.where a curved boundary domain is
meshed using square element a refine mesh for the same domain as shown in figure using smaller more
numerous element of the the same time note that the refined includes significantly more of the physical
domain in the finite element representation and the curved bounties are more closely approximated.
If the interpolation function satisfy certain mathematical requirement a finite element solution for a
particular problem convergence to the exact solution of the problem, that is ,as the no of elements is
increased and the physical dimension of the elements are decreased the finite element solution changes
incrementally .the incremental changes decrease with the refinement process and approach the exact
solution asymptotically.to illustrate convergence, we consider a relatively simple problem that has a
know solution .fig depict tapered ,solid cylinder fixed at one end area equal to average area of the
cylinder, in the two element model each element of length equals to half the total length of cylinder of
has A c/a equal to the average area of the corresponding half length of the cyclinder,where the dashed
line represents the known solution.
In most structural problem, however, we are interested primarily in stress induced by specify loading.teh
stress must be computed via the appropriated stress strain relation, and the strain component are derived
from the displacement field solution this phenomenon is characteristics of the finite element method. In
the limiting process of mesh refinement, the derived variables become closer and closer to continuity.
One example shows how the finite element soln converges known exact soln. if we know the exact soln,
we would not be applying the finite element method…so how do we assess tee accuracy of finite element
soln for a problem with an unknown solution? Conversion of a numerical method is by no means
assurance that the convergence is to the correct solution. a person using the finite element analysis
technique must examine the solution anitilicaly in terms of .(1)numerical
convergence,(2)reasonableness‟(3)whether the physical lo of the problem as satisfied,(4)whether the
discontinuities in design purpose.
(A) (B)
Figure: - 1.2
Certain steps in formulating a finite element analysis of a physical problem are common to all such
analysis, whether structural, heat transfer, fluid flow or some other problem. These steps are embodied in
commercial finite element software packages and are implicitly incorporated in this text although we do
not necessarily refer to the steps explicitly in the following chapter. The steps are described as follows.
PREPROCESSING:
The preprocessing steps are, quite generally, described as defining the model and include:
a) Define the geometric domain of the problem
b) Define the element type (s) to be used
c) Define the material properties of the element
d) Define the geometric properties of the element
e) Define the element connectivity
f) Define the physical constraints
g) Define the loading
The preprocessing steps are critical. In no case is there a better example of the computer-related axiom
garbage in, garbage out .a perfectly computed finite element solution is of absolutely no value if it wrong
problem.
SOLUTION:
During the solution phase finite element software assembles the governing algebraic equations of a
matrix form and computes the unknown values of the primary field variables. The computed values are
then used by back substitution to compute additional, derived variables such as reaction forces, element
stresses and heat flow
As it is not uncommon for a finite element model to be represented by tens of thousand of equation,
special solution techniques are used to reduce data storage requirement and computation time for static
liner problems a wave front solver based on gauss elimination is commonly used. While a complete
discussion of the various discussions in the bathe book.
POST PROCESSING:
Analysis and evaluation of the solution results referred to as post processing. Post processing software
contains routines used for sorting printing and plotting selected results from finite element solution
example of operations that can be accomplished include
a) Sort element stresses in order of magnitude
b) Check equilibrium.
c) Calculate factors of safety.
d) Plot deformed structural shape.
e) Animate dynamic model behavior.
f) Produce color – coded temperature plots.
While solution data can be manipulated many ways in post processing, the most important objective is to
apply sound engineering judgment in determine whether the solution results are physically reasonable.
First let us recall some basics about the equation of a line. Given two points in a plane ( ) and
( ), the slope-intercept form of a line can be defined as
y = mx + b
Where,
m = slope of the line
b = y intercept
One approach to rasterizing a line is through direct scan conversion, wherein each value of „x‟ in the
interval [ ] is plugged into the slope-intercept equation to get the corresponding value of „y‟.
Then we can plot the pixel (x, Round(y)) onto the display. Although, this method involves one
floating point addition and multiplication to get each y-value, there turns out a more efficient way of
accomplishing the same goal, which brings us to DDA algorithm (Digital Difference Analyzer).
DDA:
DDA or the Digital Difference Analyzer works by using the pixel coordinates last computed and the
slope. From the previous section you can easily compute how far to move over the x-axis or how far
to move up the y axis on the screen to locate your next point on the line.
dy = m dx
dx =
Given that you already know you want to move over x-axis or up y-axis a certain Number of pixels on
the screen and then plug these values into one of the two equations along with the slope and solve.
The DDA algorithm can then be broken down into the following cases:
1. A line with positive slope and 0 > m > 1 then you can take increment in x = 1
and then compute successive y values using.
= +m
Note: Remember that because „m‟ is not necessarily an integer so you must
Figure: - 2.1
ALGORITHM:
1. Input 2 end points and store the left end point in (x0,y0).
2. Load (x0,y0) into the frame buffer that plots the first point.
3. Compute dy=y2-y1 ,dx=x2-x1 & m.
4. For each value of m if m<1, consider and find out relative value of „y‟ using
yi+1=yi+m.
5. Consider y=1 and find out relative values of „x‟ by using xi+1= xi + 1/m.
6. Repeat this procedure up to (xn,yn).
FLOW CHART:
Line with Positive slope processed from left to right
Start
m <= 1 dy = 1
False xk+1 = xk+ (1/m)
True
dx = 1
Repeat dx
yk+1 = yk + m
times
(xn,yn)
End
Start
m <= 1 dy = -1
False xk+1 = xk - (1/m)
True
dx = -1
Repeat dx
yk+1 = yk - m
times
(xn,yn)
End
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int a,b,c,d,s,gm=DETECT,gd,xi,yi,i,xn,yn,x,y;
clrscr();
printf("enter a,b,c,d\n");
scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d);
x=c-a;
y=d-b;
if(x>=y)
s=x;
else
{
s=y;
}
xi=x/s;
yi=y/s;
x=a;
y=b;
initgraph(&gm,&gd,"");
line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
for(i=0;i<s;i++)
{
x=x-xi;
y=y-yi;
xn=(getmaxx()/2)+x;
yn=(getmaxy()/2)-y;
putpixel(xn,yn,WHITE);
}
for(i=0;i<s;i++)
{
x=x+xi;
y=y+yi;
xn=(getmaxx()/2)+x;
yn=(getmaxy()/2)-y;
putpixel(xn,yn,WHITE);
}
for(i=0;i<s;i++)
{
x=x-xi;
y=y-yi;
xn=(getmaxx()/2)+x;
yn=(getmaxy()/2)-y;
putpixel(xn,yn,WHITE);
}
for(i=0;i<s;i++)
{
x=x+xi;
y=y+yi;
xn=(getmaxx()/2)+x;
yn=(getmaxy()/2)-y;
putpixel(xn,yn,WHITE);
}
getch();
closegraph();
}
OUTPUT:
Figure: 3.1
It is an efficient method for scan converting a straight line which uses only integer addition,
subtraction and multiplication by 2.The computer can perform the operations of integer addition and
subtraction very rapidly. The computer is also very time efficient when performing integer
multiplication and division by powers of 2. The best approximation of the true line is by those pixels
in the raster that fall the least distance away from the true line. Then call the distance to those pixels
lying immediately above the line as Ti and the distance to those directly below it as Si. This
algorithm identifies the decision variable,
di = Si - Ti.
When di is less than 0, the closed pixel in the raster will be the pixel below the true line. Conversely,
when di is greater than or equal to 0, the pixel immediately above the true line is closest. To
implement the algorithm, all that remains is to calculate and update the various values of d i as
follows:
Initially set first value of d as d1
d1 = 2dy - dx
x1= xs, y1 =ys
Where dx= xe - xs, dy =ye - ys
The cycle for calculation is started with I = 1 to n
Where, n= xe - xs
In cyclic operation,
if di > 0,then x and y are incremented
xi+1 = xi + 1, yi+1 = yi + 1
The next d is calculated as,
di+1 = di + 2 (dy - dx)
Figure: 3.2
Figure: 3.3
In the cyclic operation, the values of x and y are calculated by the above procedure are highlighted.
This technique provides efficient method for line whose slope is less than 45 degrees. If the lines
have a slope more than 45 degrees, then the reversing of axis is carried out by making x axis as y
axis and y axis as x axis.
If slope is more than 45 degree,
Initially set first value of d as d1
d1 = 2dx - dy
x1 = xs, y1 = ys
Where dy = xe - xs, dz = ye - ys
The cycle for calculation is started with I =1 to n
Where, n= xe - xs
In cyclic operation,
If di > 0, then x and y are incremented
xi+1 = xi +1, yi+1 = yi+1
The next d is calculated as,
di+1 = di + 2 (dx - dy)
If di < 0, then only y is incremented
yi+1 = yi + 1
The next d is calculated as,
di+1 = di + 2dx
ALGORITHM:
1. Input the two endpoint and store the left endpoint in (x0,y0).
2. Load (x0,y0) into the frame buffer, that is plot the first point.
3. Calculate constants dx,dy,2dy and 2dy – 2dx,and obtain
the Starting value for the decision parameter as,
P0 =2 dy – dx
4. At each xk along the line,starting at k = 0, performs the following
Test, if pk < 0, the next piont to plot is (xk + 1, yk) and
Pk+1 = pk + 2dy
Otherwise the next point to plot is (xk + 1,yk + 1) and
Pk+1 = pk + 2dy – 2dx
5. Repeat step 4 dx times.
FLOW CHART:
start
Calculate dx,
dy,2dy, 2(dy-dx)
and obtain P0
(xk + 1,yk + 1)
False
Pk < 0 Pk+1 = pk+ 2dy
– 2dx
True
(xk + 1, yk)
(xn,yn)
End
PROGRAM:
//Program to implement Bresenhams Line Drawing Algorithm
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
class lines
{
private:
int length,x1,y1,x2,y2,x,y,dx,dy,wx,wy,w,width;
public:
lines(); //Constructor
void showline();
int sign(int);
};
cin>>x1>>y1;
cout<<"Enter The Co-Ordinates (x2,y2) :=";
cin>>x2>>y2;
cout<<"Enter The Width Of The Line :=";
cin>>width;
}
void lines::showline()
{
char *s;
int s1,s2,ic;
float temp;
x=x1;y=1;
w=width;
if(y2-y1)
wx=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(y2-y1));
if(x2-x1)
wy=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(x2-x1));
dx=abs(x2-x1);
dy=abs(y2-y1);
s1=sign(x2-x1);
s2=sign(y2-y1);
if(dy>dx)
wy=wx;
if(dy>dx)
{
temp=dy;
dy=dx;
dx=temp;
ic=1;
}
else
ic=0;
float d=2*dy-dx;
setcolor(0);
for(int i=1;i<=dx;i++)
{
for(int j=0;j<wy;j++)
putpixel((x+320),480-(y+240+j),WHITE);
for(j=0;j<wy;j++)
putpixel((x+320),480-(y+240-j),WHITE);
putpixel((x+320),480-(y+240),WHITE);
while(d>=0)
{
if(ic==1)
x+=s1;
else
y+=s2;
d-=2*dx;
}
if(ic==1)
y+=s2;
else
x+=s1;
d+=2*dy;
}
setcolor(15);
outtextxy(20,10,"The Points Are:=");
sprintf(s,"A(%d,%d)",x1,y1);
outtextxy(20,20,s);
sprintf(s,"B(%d,%d)",x2,y2);
outtextxy(20,30,s);
getch();
}
void main()
{
int gd=DETECT,gm,i,j,xx=200,xxx=470;
clrscr();
lines a;
char*mess[]={"B","R","E","S","E","N","H","A","M","'","S"," ","L","I","N","E","
","A","L","G","O","R","I","T","H","M"};
initgraph(&gd,&gm,"C:\\TURBOC3\\bgi");
cleardevice();
rectangle(120,40,320,240);
rectangle(320,40,520,240);
rectangle(120,240,320,440);
rectangle(320,240,520,440);
for(i=0,j=25;i<14,j>=12;i++,j--)
{
xx+=10;
outtextxy(xx,10,mess[i]);
xxx-=10;
outtextxy(xxx,10,mess[j]);
delay(100);
}
for(i=130;i<=510;i+=10)
for(j=50;j<=430;j+=10)
putpixel(i,j,15);
for(i=130;i<=510;i+=10)
{
if(i==320)
continue;
outtextxy(i,237,"+");
}
for(i=50;i<=430;i+=10)
{
if(i==240)
continue;
outtextxy(317,i,"-");
}
outtextxy(310,230,"O");
outtextxy(530,240,"X");
outtextxy(320,450,"-Y");
outtextxy(100,240,"-X");
outtextxy(320,30,"Y");
a.showline();
closegraph();
OUTPUT:
It is a path traced by a point when it is rotated about another point at constant distance. The circle is
designated by centre co-ordinates and radius .The circles are used for curved graphics. The scan
conversion an algorithm is used for drawing of circles.
SYMMETRY OF CIRCLE:
A circle is a symmetrical figure. Any circle generating algorithm can take the advantage of the
symmetry of circle to plot eight points for each value any algorithm calculates.
The eight-way summery is used by reflecting each calculated point around each 45degree axis as
shown in figure.
Figure: - 4.1
The best approximation of the true circle will be described by those pixels in the raster that fall the
least distance away from the true circle. If points are to be generated, each new point closest to the
true circle can be found out by using two actions.
(1) Move in the x direction by one unit.
(2) Move in the x direction one unit and move in the negative i.e. y direction by one unit.
Figure: - 4.2
Consider a true point (i) on circle, which has fractional value and hence it has to select either upper
or lower point.
Therefore, a method of selecting between these two choices is all that is necessary to find the points
closest to the true circle.
Assume that ( ) are the coordinates of the last converted pixel upon entering step i (see fig). Let
the distance from the origin to pixel T squared minus the distance to the true circle squared = D (T).
Then let the distance from the origin to pixel S squared minus the distance to the true circle squared
= D(S). As the co-ordinates of T are ( ), and those of S are ( ), the following
expressions can be developed:
D(T) = + - D(S) = + -
The function D provides a relative measurement of the distance from the center of a pixel to the true
circle. Since D (T) will always positive (T is outside the true circle) and D(S) will always be negative
(S is inside the the true circle),a decision variable di, may be defined as follows:
= D(T) + D(S)
Therefore,
= + + -2
When < 0, we have |D(T)| < |D(S)| and pixel T is chosen. When and >= 0, we have |D(T)| >= |D(S)|
pixel S is selected. We can also write the decision variable for the next step:
= + + -2
Hence
- = + + - - -
Since = , we have
= +4 +2( - )–2 )+6
= +4 +6
ON the other hand, if S is the chosen pixel (meaning that < 0) then = - 1 and so
= +4 ) + 10
Hence we have
= +4 +6 if <0
= +4 ) + 10 if ≥0
Finally we set ( 0, r ) to be the starting pixel coordinates and compute the base case value for this
recursive formula from the original definition of
=2 + + -2 = 3-2r
ALGORITHM:
1. Input radius r and circle centre (xc , yc ), then set the coordinates for the
First point on the circumference of a circle cantered on the origin as
(x, y) = (0, r )
2. Calculate the initial value of the decision parameter
as P0 = 3-2r
3. At each xk position, starting at k = 0, perform the following test. If
pk <0, the next point along the circle cantered on (0, 0) is (x+1, y ) and
p=p+4x+2;
FLOW CHART:
Start
Input
Center point=(xc,yc),Radius=r,First point=(0,r)
p=3-2r
p<0
False
True
Next point=(x+1,y-1)
p=p+4(x-y)+2
Next point=(x+1,y)
p=p+4x+2
Repeat
until x>=y
Plot
x=x+xc,y=y+yc
End
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
clrscr();
int gm=DETECT,gd;
initgraph(&gm,&gd,”C:\\Turboc3\\BGI”);
line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
int x,y,dx,dy,r,p,xc,yc;
printf(“Enter centre co-ordinate of circle xc,yc\n”);
COMPUTER AIDED DESIGN Page 35
CIRCLE ALGORITHM
scanf(“%d\n%d”,&xc,&yc);
printf(“Enter the value of radius of circle\n”);
scanf(“%d\n”,&r);
x=0;
y=r;
p=3-2*r;
putpixel(getmaxx()/2+xc,getmaxy()/2+yc,WHITE);
while(x<y)
{
x++;
if(p<0)
{
y=y;
p=p+4*x+2;
}
else
{
y=y-1;
p=p+4*(x-y)+2;
}
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc-y, WHITE);
putpixel(getmaxx()/2+xc+y,getmaxy()/2-yc-x, WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc-y, WHITE);
putpixel(getmaxx()/2+xc-y,getmaxy()/2-yc-x, WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc+y, WHITE);
putpixel(getmaxx()/2+xc-y,getmaxy()/2-yc+x, WHITE);
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc+y, WHITE);
putpixel(getmaxx()/2+xc+y,getmaxy()/2-yc+x, WHITE);
}
getch();
closegraph();
}
OUTPUT:
THEORY:
It is based on following function for testing the spatial relationship between an arbitrary point (x,y)
as a circle of radius r centred at the origin:
Now consider the co-ordinates of the point halfway between pixel T and pixel S in fig. i.e. (xi+1,yi-
(1/2))
2 2 2
Decision parameter: pi= (xi+1) + (yi-(1/2)) -r
pi + 2(xi+1) +1 if pi<0
pi+1= pi + 2(xi+1) +1-2(yi-1) if pi>=0
pi + 2(xi+1) +1 if pi<0
pi+1 = pi + 2(xi+1) +1-2(yi+1) if pi>=0
Initial value of decision parameter can be found by using original definition of pi and (0,r)
pi=(5/4)-r
It is not really an integer computation. However, when r is integer we can use pi=1-r.The error of
being ¼ less than the precise value does not prevent pi from getting appropriate sign. It does not
affect the rest of scan-conversion process either, because the decision variable is only updated with
integer increments in subsequent steps.
ALGORITH:
1. Input radius r and circle centre (xc , yc ), then set the coordinates for the
First point on the circumference of a circle cantered on the origin as
(x, y) = (0, r )
2. Calculate the initial value of the decision parameter
as P= 1-r
3. At each xk position, starting at k = 0, perform the following test. If
pk <0, the next point along the circle cantered on (0, 0) is (x+1, y ) and
p=p+2x+1;
FLOW CHART:
Start
Input
Center point=(xc,yc),Radius=r,First point=(0,r)
p=1-r
p<0
False
True
Next point=(x+1,y-1)
p=p+4(x-y)+2
Next point=(x+1,y)
p=p+4x+2
Repeat
until x>=y
Plot
x=x+xc,y=y+yc
End
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#define round(a)((int)(a+0.5))
void main()
{
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\turboc3\\BGI");
line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
float r,x,y,xc,yc,p,i;
printf("enter the radius of circle");
scanf("%f",&r);
printf("enter the valur of centre co-ordinate\n");
scanf("%f\n%f",&xc,&yc);
x=0;
y=r;
putpixel(getmaxx()/2+xc,getmaxy()/2-yc,WHITE );
p=1-r;
while(x<=y)
{
if(p<0)
{
p=p+(2*x)+3;
x++;
}
else
{
p=p+(2*x)-(2*y)+5;
x++;
y--;
}
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc-y,WHITE);
putpixel(getmaxx()/2+xc-y,getmaxy()/2-yc+x,WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc-y,WHITE);
putpixel(getmaxx()/2+xc+y,getmaxy()/2-yc+x,WHITE);
putpixel(getmaxx()/2+xc+y,getmaxy()/2-yc-x,WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc+y,WHITE);
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc+y,WHITE);
putpixel(getmaxx()/2+xc-y,getmaxy()/2-yc-x,WHITE);
}
getch();
closegraph();
}
OUTPUT:
An ellipse is defined as the set of points such that the sum of the distances from two fixed foci is the
same for all points. An ellipse may called an elongated circle so elliptical curves can be generated by
modifying circle drawing algorithm.
Ellipses are generally drawn with major and minor axes. And its equation can greatly simplify if the
major and minor axes are oriented to align with coordinate axes. Figure 1 shows the standard
position.
For the standard ellipse shown in figure can be written in terms of ellipse centre coordinates and
parameters r and r as:
x y
x x 2 y y 2
c
c
(1)
r r
x y
Using polar coordinates r and θ, ellipse can also described in standard position with equations:
x x r cos
c x
y y r sin (2)
c y
Figure: - 5.1
Standard Ellipse Orientation
The mid point ellipse method is applied throughout the first quadrant in two parts.
Figure2 shows the division of quadrant according to slope of an ellipse rx ry .
Figure: - 5.2
SYMMETRY OF AN ELLIPSE
Region 1 and 2 can be proceeding from multiple ways. We can start at point (0, ry ) and step
clockwise along elliptical path in first quadrant, shifting unit steps in y when the slope becomes less
than -1. Else we can start with point (0, ry ) and select points in a counterclockwise order, shifting
from unit steps in to y to unit steps in x when the slope becomes greater than -1.
Ellipse function from equation (1) with xc , yc = (0, 0) as
f ( x, y ) r 2x 2 r 2 y 2 r 2 r 2
(3)
ellipse y x x y
The ellipse function serves as the decision parameter in the midpoint algorithm. Starting at (0, ry ) ,
by taking unit steps in the x direction until we reach the boundary between region 1 and region. So at
every point the values of slope need to be taken in to account. The ellipse slope can be calculated by
equation (3)
dy 2r 2 x
y
dx 2r 2 y
x
dy
At the boundary between region 1 and region 2, -1 and
dx
2 r 2 y r 2x
x y
2
And if RHS of above condition getting more than LHS region 1 will complete.
So determination of the next point by assuming that initial point at ( xk , y k ) , we need decision
parameter at this midpoint:
1
p f ellipse x 1, y k
1k k
2
1 2
p1k ry
2
xk 1 r x ( y k
2 2
2) rx ry
2 2
If p1k <0 the midpoint is inside the ellipse and the pixel on the scan line yk , otherwise, the pixel will
be yk 1.
Next decision parameter evaluated as
p1k 1 f (x 1, y 1 )
ellipse k 1 k 1
2
p1k 1 p1k 2 ry 2 xk 1 ry 2 rx 2 [( y k 1 1 ) 2 ( yk
1) 2 ] 2
Where yk 1 is either if p <0 then yk
1k
p >0 then yk 1
if 1k
So in region 1 value of initial decision parameter is obtained by evaluating start position in ellipse
function as x0 , y0 = (0, ry )
p f (1, r 1 )
10 ellipse
y
2
p r 2 r 2 r 1 r 2
10 y x y x
4
Similarly over region 2, the values of decision parameters can be found. The only difference between
region 1 and region 2 is in region 2 there is a unit decrement in y direction and midpoint is now taken
between horizontal pixels at each step.
COMPUTER AIDED DESIGN Page 44
ELLIPSE ALGORITHM
ALGORITHM:
For region 1
1. Input rx , ry , and ellipse centre xc , yc , and obtain the first point on an Ellipse
Centred on the origin as (x0 , y0 ) = (0, ry )
2. Calculate the initial value of the decision parameter in region 1 as
p1 r 2 r 2 r 1 / 4r 2
0 y x y x
For region 2
4. Calculate the initial value of the decision parameter in region 2 as
p2 r 2 x 1/ 22 r 2 (y 1) 2 r 2 r 2
0 y 0 x 0 x y
p2 p2 2r 2x y k 1 r 2x
k 1 k
FLOW CHART:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#define round(a)((int)(a+0.5))
void main()
{
clrscr();
int gm=DETECT,gd;
initgraph(&gm,&gd,"C:\\Turboc3\\BGI");
line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
float xc,rx,yc,ry,x,y,dx,dy,p;
printf("enter co-ordinate of center point xc,yc\n");
scanf("%f\n%f",&xc,&yc);
printf("enter value of rx,ry\n");
scanf("%f\n%f",&rx,&ry);
dx=0;
dy=2*rx*rx*ry;
x=0;
y=ry;
p=round((ry*ry)-(rx*rx*ry)+(0.25*rx*rx));
putpixel(getmaxx()/2+xc,getmaxy()/2-yc,WHITE);
while(dx<dy)
{
x++;
dx=2*ry*ry*x;
if (p<0)
{
y=y;
dy=2*rx*rx*y;
p=p+2*ry*ry*x+ry*ry;
}
else
{
y=y-1;
dy=2*rx*rx*y;
p=p+2*ry*ry*x-2*rx*rx*y+ry*ry;
}
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc-y, WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc+y, WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc-y, WHITE);
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc+y, WHITE);
delay(50);
}
p=round(ry*ry*(x+0.5)*(x+0.5)+rx*rx*(y-1)*(y-1)-rx*rx-ry*ry);
while (y>0)
{
y--;
if(p>0)
{
x=x;
p=p-2*rx*rx*y+rx*rx;
}
else
{
x=x+1;
p=p-2*rx*rx*y+2*ry*ry*x+rx*rx;
}
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc-y,WHITE);
putpixel(getmaxx()/2+xc+x,getmaxy()/2-yc+y, WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc-y, WHITE);
putpixel(getmaxx()/2+xc-x,getmaxy()/2-yc+y, WHITE);
delay(50);
}
getch();
closegraph();
}
OUTPUT:
A translation is applied to an object by repositioning it along a straight line path from one coordinate
location to another. We translate a 2D point by adding translation distance, tx & ty to the original
coordinate position(x, y) to move the point to a new position.
x 'xt y 'yt
x y (A)
1 0 t x
0 1 t y
0 0 1
The translation distance pair ( tx & ty ) is called translation vector. We can express the translation
equation-(A) as a single matrix equation by using column vectors to represents coordinate positions
and the translation vector: as shown in figure(B) below.
Fig (B): Translating a point from position P to position p with translation vector T.
'
'
x1 x1 t x
'
x2
'
P= p = x T= t y
2
P ' P T (C)
Translation is a rigid body transformation that moves object without deformation. That is ,every point
on the object is translated by the same amount straight line segment is translated by applying the
transformation equation to each of the line end points and redrawing the line between the new end
point positions .
Polygons are translated by adding the translation vector to the coordinate position of vertex and
regenerating the polygon using the new set of vertex coordinates and the current attribute settings.
Below figure the application of the specified translation vector to move an object from one position to
any other. As shown in figure (D) below.
Fig (D) Moving a polygon from position (a) to position (b) with translation
vector (-5.50, 3.75)
1 0 tx
1
T = t
0 1 y
0 0 1
We can now complete scaling about an arbitrary fixed point and rotation about an arbitrary pivot. To
scale about F [ x f y f ] use the composition of matrices
x f 0 0s 0 0 x f 0 0
x
0 yf
0 s y 0 0
y f 0
10
0 0 0 0 1 0 0 1
x f (1 sx ) 0 0
0 y f (1 sy ) 0
0 0 1
x f (1 sx ) 0 0
0 yf (1 sy ) 0
[ x ' y '1] = [x y 1]
0 0 1
= [ x x (1 s ) s yy (1 s ) s 1]
f x x f y y
As an example, consider a triangle defined by three vertices (20, 0), (60, 0), and (40, 100) being
translated 100 units to the right along the x-axis ( tx = 100) and 10 units up along the y-axis (ty = 10).
The new vertices are (120, 10), (160, 10), and (140, 110), see figure below:
% 2D Transformation
(Translation) clear all
clc
% Load co-ordinates of
points p=load('point.txt');
% Plot original geometry
plot([p(:,1);p(1, 1)], [p(:,2);p(1,2)], 'ro--')
% Display title and axis
labels title('2D Translation')
xlabel('X-Axis') ylabel('Y-
Axis')
p(:,3)=1
hold on
xt=input('enter the value of translation in x co-ordinate')
yt=input('enter the value of translation in y co-ordinate')
% Generate translation matrix
T=[1 0 0;0 1 0;xt yt 1]
pn=p*T
% Plot new geometry after translation
plot([pn(:,1);pn(1, 1)], [pn(:,2);pn(1,2)], 'bo-')
Example of 2D Translation:
Input:
p =
0 0 1
10 20 1
20 10 1
xt =
yt =
6
Output:
T =
1 0 0
0 1 0
4 6 1
pn =
4 6 1
14 26 1
24 16 1
Figure:
Rotations alter the orientation of an object: They are a little more complex than scales. Starting in
two dimensional rotations is easiest.
A two dimensional rotation is applied an object by repositioning it along a circular path in the xy
plane. To generate a rotation, we specify a rotation angle &the position of the rotation point about
which the object is to be rotated. Positive values for the rotation angle define counterclockwise
rotation about the pivot the pivot point as in the figure (A) below.
We first determine the transformation equation for rotation of a point position P when the pivot point
is at the coordinate origin. The angular and coordinate relationship of the original and transformed
point position are shown in figure (B) below.
FIG (B) -Rotation of point from position(x, y) to position (x’, y’) through an angle
R is the constant distance of the origin, angle is the original angular position from the horizontal,
is the rotationangle. We can express the transformed coordinate in terms of angles & as:
Substituting expressions (C, D) in to (E), we obtain the transformation equation for rotating a point
at position(x, y) through an angle about the origin:
With the column vector representation for coordinate position, we can write the rotation equation in
the matrix form:
'
P R P (G)
cos Sin
R
sin
cos
When coordinate position are represented as row vectors instead of column vectors, the matrix
product in rotation equation (G) is transposed so that the transformed row coordinate vector [x‟y‟] is
calculated as
'T T
P ( R P)
'T T T
P ( P ) ( R)
Where, ( P )T =[x, y], the transpose ( R)T of matrix R is obtained by simply changing the sign of the
sine terms.
Rotation of a point about an arbitrary pivot position is illustrated in figure (H) below. Using the
trigonometric relationship in this figure, we can generalize equation (F) obtain the transformation
equation of a point about any specified rotation position ( xr , yr ):
H): Rotating a point from position(x, y) to position (x’, y’) through angle θ about
rotation point ( xr , yr ).
1. Translate the object so that the pivot point position is moved to the coordinate origin.
2. Rotate the object about the coordinate origin.
3. Translate the object so that the pivot point position is returned to its original position.
4. This transformation sequence is illustrated in figure (a), (b), (c), (d) below.
The composite transformation matrix for this sequence is obtained with concatenation:
0 0 1 0 0 1 0 0 1
T ( x , y ) R ( ) T ( x , y ) R ( x , y , )
r r r r r r
1
Where, T ( xr , yr ) T ( xr , yr )
In general, a rotate function can be set up to accept parameter for pivot point coordinates as well as
the rotation angle, and to generate automatically the rotation matrix of equation (J) above.
Example of 2D Rotation:
Input:
Output:
Figure:
Scaling is a kind of transformation in which the size of an object is changed. Remember the change
is size does not mean any change in shape. This kind of Transformation can be carried out for
polygons by multiplying each coordinate of the polygon by the scaling factor. Sx and Sy which in
turn produces new coordinate of (x,y) as (x‟,y‟). The equation would look like,
Or
Note: If the values of scaling factor are greater than 1 then the object is enlarged and if it is less that
1 it reduces the size of the object. Keeping value as 1 does not change the size of object.
Uniform Scaling: To achieve uniform scaling the values of scaling factor must be kept equal.
Differential scaling: Unequal or Differential scaling is produce increase when values for scaling
factor are not equal.
As per usual phenomenon of scaling an object moves closer to origin when the values of scaling
factor are less than 1.
Let Sx and Sy be the scale in the positive x and y directions respectively. Then the scaled vertex is
given by
Lengths and distances from the origin are scaled by multiplying the coordinates of each endpoint by
the scaling factors.
Below we see a triangle and a house that been doubled in both width and height (note the
area is more than doubled)
The scaling for the X dimension does not have to be the same as the y dimension. If these
are different, then the object is distorted.
SCALE MATRIX: S = =
% 2D Transformation (Scaling)
clear all
clc
% Load co-ordinates of points
p=load('point.txt');
% Plot original geometry
plot([p(:,1);p(1, 1)], [p(:,2);p(1,2)], 'ro--')
% Display title and axis
labels title('2D Scaling')
xlabel('X-Axis') ylabel('Y-
Axis')
p(:,3)=1
hold on
Sx=input('enter the value of scaling factor in x co-ordinate\n')
Sy=input('enter the value of scaling factor in y co-ordinate\n')
% Generate scaling matrix
S=[Sx 0 0;0 Sy 0;0 0 1]
pn=p*S
% Plot new geometry after Scaling
plot([pn(:,1);pn(1, 1)], [pn(:,2);pn(1,2)], 'bo-')
Example of 2D Translation:
Input:
p =
0 0 1
10 20 1
20 10 1
Sx =
Sy =
Output:
S =
2 0 0
0 4 0
0 0 1
pn =
0 0 1
20 80 1
40 40 1
Figure:
When the reflection axis is a line in the xy plane, the rotation path about this axis is in a plane
perpendicular to the xy plane. For reflection axes that are perpendicular to the xy plane, the rotation
path is in the xy plane.
1 0 0
0 1 0
0 0 1
This transformation keeps the x values the same, but
“flips” the y values of coordinate positions. The
resulting orientation of an object after it has been
reflected about the x axis is shown in figure 1.
1 0 0
0
0 0 1
1 0
Fig 2. Illustrates the change in position of an object that has reflected about the line x=0.
We flip both the x and y coordinates of a point by reflecting relative to an axis that is perpendicular
to the xy plan and that passes through the coordinate origin. This transformation referred to as
reflection relative to the coordinate origin, has a matrix representation.
1 0 0
0 1 0
0 0 1
An example of reflection about the origin is shown in figure 3. Reflection can be generalized to any reflection point in the xy plane. This reflection is
the same as a 180° rotation in the xy plane using the reflection point as the pivot point.
If we chose the reflection axis as the diagonal line y=x, the reflection matrix is
0 1 0
1 0 0
0 0 1
To obtain a transformation matrix for reflection about the diagonal y=-x, we could concatenate
matrices for the transformation sequence:
1. Clockwise rotation by 45°
0 1 0
1 0 0
0 0 1
Figure (a, b, c) shows the original and final positions for an object transformed with this reflection
matrix.
Reflection about any line y=mx+b in the xy plane can be accomplished with a combination of
translate-rotate-reflect transformation.
clear all
clc
p=load('a.txt')
plot([p(:,1);p(1,1)],[p(:,2);p(1,2)],'ro-')
title('2D reflection')
xlabel ('X-axis')
ylabel ('Y-axis')
zlabel ('Z-axis')
hold on
disp('chose value for reflection about')
t=input('1 for X-axis\n2 for Y-axis\n3 for x=y\n4 for x=-y\n=')
if t==1
R=[1 0;0 -1]
else if t==2
R=[-1 0;0 1]
else if t==3
R=[0 1;1 0]
else if t==4
R=[0 -1;-1 0]
end
end
end
end
pn=p*R
plot([pn(:,1);pn(1,1)],[pn(:,2);pn(1,2)],'bo-')
Example of 2D Reflection:
[1]
Input:
p =
2 3
4 5
t =
Output:
R =
1 0
0 -1
pn =
2 -3
4 -5
Figure:
[2]
Input:
p =
2 3
4 5
t =
Output:
R =
-1 0
0 1
pn =
-2 3
-4 5
Figure:
[3]
Input:
p =
2 3
4 5
t =
Output:
R =
0 1
1 0
pn =
3 2
5 4
Figure:
[4]
Input:
p =
2 3
4 5
t =
Output:
R =
0 -1
-10
pn =
-3 -2
-5 -4
Figure:
An x-direction shear relative to the x axis is produced with the transformation matrix,
1 sh 0
x
0 1 0
0 0 1
This transforms coordinate positions as:
'
x x sh
'
x y, y y
Any real number can be assigned to the shear parameter shx. A coordinate position (x,y) is then
shifted horizontally by an amount proportional to its distance (y value) from the x axis (y=0). Setting
shx to 2, for example, changes the square in figure into a parallelogram. Negative values for sh x shift
coordinate positions to the left.
A unit square (a) is converted to parallelogram (b) using x direction shear matrix with shx=2
We can generate x-direction shears relative to other reference to other reference lines
with y' y, x' shx y yref x
With coordinate positions transformed as
y y, x ' sh y y
'
x
x ref
An example of this shearing transformation is given in figure for a shear parameter value of ½
relative to the line yref = -1.
A unit square (a) is transformed to shifted parallelogram (b) with shx=1/2 and yref = -1 in the shear
matrix
A y-direction shear relative to the line x = xref is generated with the transformation matrix.
1 0 0
sh 1 sh x
y y ref
0 0 1
This generates transformed coordinate positions :
x‟ = x, y‟ = shy(x-xref) + y
This transformation shifts a coordinate position vertically by an amount proportional to its distance
from the reference line x = xref. figure 5-25 illustrates the conversion of a square into a parallelogram
with shy=1/2 and xref=-1.
Shearing operation can be expressed as sequences of basics transformation.
A unit square (a) is turned into a shifted parallelogram (b) with parameter values shy = ½ and xref =
-1 in the y-direction using shearing transformation 5-57
The x-direction shear matrix, for example, can be return as a composite transformation involving a
series of rotation and scaling matrices that would scale the unit square of figure along its diagonal,
while maintaining the original lengths and orientations of edges parallel to the x-axis. Shift in the
position of objects relative to shearing reference lines are equivalent to translations.
% 2D Transformation
(Shearing) clear all
clc
% Load co-ordinates of
points p=load('point.txt');
% Plot original geometry
plot([p(:,1);p(1, 1)], [p(:,2);p(1,2)], 'ro--')
% Display title and axis
labels title('2D Shearing')
xlabel('X-Axis') ylabel('Y-
Axis')
p(:,3)=1
hold on
%check the condition
t=input('enter 1 for shear in X-axis\nor enter 2 for shear in Y-
axis\n') if t==1
%Generate the shear matrix
a=input('enter the value of shear in X
direction') S=[1 a 0;0 1 0;0 0 1]
else
%Generate the shear matrix
b=input('enter the value of shear in Y direction')
S=[1 0 0;b 1 0;0 0 1]
end
pn=p*S
% Plot new geometry after shearing
plot([pn(:,1);pn(1, 1)], [pn(:,2);pn(1,2)], 'bo-')
[1]
Input:
p =
0 0 1
10 20 1
20 10 1
t =
a =
Output:
S =
1 4 0
0 1 0
0 0 1
pn =
0 0 1
10 60 1
20 90 1
Figure:
[2]
Input:
p =
0 0 1
10 20 1
20 10 1
t =
b =
Output:
S =
1 0 0
3 1 0
0 0 1
pn =
0 0 1
70 20 1
50 10 1
Figure:
Translations change the position of an object. A pure (three dimensional) translation can not be
implemented using a 3x matrix. We must alter our notation of a point to accommodate translations.
A three dimensional point P=[x y z] will be embedded in three dimensional homogeneous space and
represented as Ph=[x y z w].
x ' 1 0 0 t x x
y' 0 1 0 ty y
.
z ' 0 0 1 tz z
1 0 0 0 1 1
P’= T.P
Parameters tx, ty and tz specifying translation distances for the coordinate directions x, y and z are
assigned any real values. The matrix representation is equivalent to three equations,
x ' x tx
y ' y ty
z ' z tz
An object is translated in three dimensions by transforming each of the defining points of the object
.For an object represented as a set of polygon surfaces, we translate each vertex of each surface and
redraw the polygon in the new position.
ROTATION:
To generate a rotation transformation for an object, we must designate an axis of rotation and the
amount of angular rotation. Unlike two-dimensional applications, where all transformations are
carried out in the xy plane, a three-dimensional rotation can be specified around any line in space.
By convention, positive rotation angles produce counterclockwise rotations about a coordinate axis,
if we are looking along the positive half of the axis towards the coordinate origin.
P’=Ry (θ).P
Coordinate-Axes Rotations:
FIGURE 1: (a), (b), (c): Positive rotation directions about the coordinate axes are
counterclockwise, when looking towards the origin from a positive coordinate position
on each axis.
Here there is positive rotation directions about the coordinate axes are counterclockwise, when
looking towards the origin from a positive coordinate position on each axis.
Parameter θ specifies the rotation angle. In homogeneous coordinate form, the 3-D z-axis rotation
equations are expressed as:
A rotation matrix of any axis does not coincide with a coordinate axis can be set up as a
Composite transformation involving combinations of translations and the coordinate-axes
Rotations.
Given the specifications for the rotation axis and the rotation angle, we can accomplish the required
rotation in five steps:
FIGURE2: Five transformation steps for obtaining a composite matrix for rotation about an arbitrary
axis, with the rotation axis projected onto the z-axis.
x 2 x1 y2y1 z 2 z1
a , b , c
|V| |V| |V|
An axis of rotation defined with points P1 and P2.The direction for the unit axis vector
u is determined by the specified rotation direction.
1 0 0 x1
0 1 0 y1
T
0 0 1 z1
0 0 0 1
SCALING:
The matrix expression for the scaling transformation of a position P=(x, y, z) relative
to the coordinate origin can be written as
Doubling the size of an object with transformation also moves the object from origin.
P’=S.P
Scaling with respect to a selected fixed position ( xf ,yf ,zf ) can be represented with
the following transformation sequence:
sx 0 0 (1 sx )xf
0 sy 0 (1 sy ) yf
T ( xf , yf , zf ).S ( sx , sy , sz ).T ( xf , yf , z f )
0 0 sz (1 sz )zf
0 0 0 1
REFLECTION:
1. X-Y plane
2. Y-Z plane
3. Z-X plane
1 0 0 0
0 1 0 0
RFZ
0 0 1 0
0 0 0 1
SHEAR:
Shearing transformations can be used to modify object shapes. They are also useful in 3-D viewing
for obtaining general projection transformation. In 3-D we can generate shears relative to z-axis. The
transformation producing z-axis shearing is as under:
1 0 a 0
0 1 b 0
SHz
0 0 1 0
0 0 0 1
Parameters a and b can be assigned any real values. The effect of this transformation is to alter x and
y coordinate values by an amount that is proportional to z value, while leaving the z coordinate
unchanged.
clear all
clc
p= load('point a.txt');
plot3([p(:,1);p(1,1)],[p(:,2);p(1,2)],[p(:,3);p(1,3)],'ro-');
title('3D Transformation');
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
p(:,4)= 1;
hold on
disp('1. Translation' );
disp('2. Rotation');
disp('3. Scaling');
disp('4. Reflection' );
disp('5. Shearing')
choice = input('\ enter your choice =');
switch (choice)
case 1
pn = Translation(p);
case 2
pn = Rotation(p);
case 3
pn = Scaling(p);
case 4
pn = Reflection(p);
case 5
pn = Shearing(p);
otherwise
pn= Translation(p);
end
plot3([pn(:,1);pn(1,1)],[pn(:,2);pn(1,2)],[pn(:,3);pn(1,3)],'bo-')
Return
[1] Translation:
Input:
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing
enter your choice =1
p =
10 10 10
20 20 20
30 30 30
10 30 40
20 50 30
30 70 20
p =
10 10 10 1
20 20 20 1
30 30 30 1
10 30 40 1
20 50 30 1
30 70 20 1
tx =
10
ty =
15
tz =
20
Output:
T =
1 0 0 0
0 1 0 0
0 0 1 0
10 15 20 1
pn =
20 25 30 1
30 35 40 1
40 45 50 1
20 45 60 1
30 65 50 1
40 85 40 1
Figure:
[2] Rotation:
Input:
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing
enter your choice =2
p =
10 10 10
20 20 20
30 30 30
10 30 40
20 50 30
30 70 20
p =
10 10 10 1
20 20 20 1
30 30 30 1
10 30 40 1
20 50 30 1
30 70 20 1
th =
90
th =
1.5708
t =
Output:
R =
0.0000 0 -1.0000 0
0 1.0000 0 0
1.0000 0 0.0000 0
0 0 0 1.0000
pn =
Figure:
[3] Scaling:
Input:
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing
enter your choice =3
p =
10 10 10
20 20 20
30 30 30
10 30 40
20 50 30
30 70 20
p =
10 10 10 1
20 20 20 1
30 30 30 1
10 30 40 1
20 50 30 1
30 70 20 1
Sx =
Sy =
Sz =
Output:
S =
2 0 0 0
0 2 0 0
0 0 2 0
0 0 0 1
pn =
20 20 20 1
40 40 40 1
60 60 60 1
20 60 80 1
40 100 60 1
60 140 40 1
Figure:
[4] Reflection:
Input:
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing
enter your choice =4
p =
10 10 10
20 20 20
30 30 30
10 30 40
20 50 30
30 70 20
t =
Output:
R =
0 1 0
1 0 0
0 0 1
pn =
10 10 10
20 20 20
30 30 30
30 10 40
50 20 30
70 30 20
Figure:
[5] Shearing:
Input:
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing
enter your choice =5
p =
10 10 10
20 20 20
30 30 30
10 30 40
20 50 30
30 70 20
t =
Sx =
Sz =
Output:
S =
1 0 0
2 1 4
0 1 1
pn =
30 20 50
60 40 100
90 60 150
70 70 160
120 80 230
170 90 300
Figure:
Determine the nodal deflections, reaction forces, and stress for the truss system shown below (E =
2
200GPa, A = 3250mm ).
2. Enter Key-points
The overall geometry is defined in ANSYS using key-points which specify various principal
coordinates to define the body. For this example, these key-points are the ends of each truss.
o We are going to define 7 key-points for the simplified structure as given in the
following table
coordinate
Key-point X y
1 0 0
2 1800 3118
3 3600 0
4 5400 3118
5 7200 0
6 9000 3118
7 10800 0
Units
Note the units of measure (ie mm) were not specified. It is the responsibility of the user to
ensure that a consistent set of units are used for the problem; thus making any conversions
where necessary.
Correcting Mistakes When defining key-points, lines, areas, volumes, elements,
constraints and loads you are bound to make mistakes. Fortunately these are easily corrected
so that you don't need to begin from scratch every time an error is made! Every 'Create'
menu for generating these various entities also has a corresponding 'Delete' menu for fixing
things up.
In this step the key points which are now defined as nodes are to be connected by the
help of line element.
o In the main menu select: Preprocessor > Modeling > Create > Lines> Auto
No>Thru Nodes. The following will be appearing.
o Now use the mouse point to click on the nodes as in the order to create the
connection as it want to be (i.e. click on point 1 and then on point 2). Now the line
will be appear between the 1 and 2 node.
o Use the same method to create the other connection and your screen will be
appearing as below.
o When you're done, click on 'OK' in the 'Lines in Active Co-ord' window and
minimize the 'Lines' menu and the 'Create' menu. Your ANSYS Graphics window
should look similar to the following figure.
Form Lines
The key-points must now be connected
We will use the mouse to select the key-points to form the lines.
o In the main menu select: Preprocessor > Modeling > Create > Lines > Lines > In
Active Co-ord. The following window will then appear:
o Use the mouse to pick key-point #1 (i.e. click on it). It will now be marked by a
small yellow box.
o Now move the mouse toward key-point #2. A line will now show on the screen
joining these two points. Left click and a permanent line will appear.
o Connect the remaining key-points using the same method.
o When you're done, click on 'OK' in the 'Lines in Active Co-ord' window, minimize
the 'Lines' menu and the 'Create' menu. Your ANSYS Graphics window should look
similar to the following figure.
It is now necessary to create elements. This is called 'meshing'. ANSYS first needs to know
what kind of elements to use for our problem:
o From the Preprocessor Menu, select: Element Type > Add/Edit/Delete. The
following window will then appear:
o For this example, we will use the 2D spar element as selected in the above figure.
Select the element shown and click 'OK'. You should see 'Type 1 LINK1' in the
'Element Types' window.
o Click on 'Close' in the 'Element Types' dialog box.
7. Mesh Size
The last step before meshing is to tell ANSYS what size the elements should be. There are a
variety of ways to do this but we will just deal with one method for now.
o In the Preprocessor menu select Meshing > Size Cntrls>ManualSize> Lines > All
Lines
o In the size 'NDIV' field, enter the desired number of divisions per line. For this
example we want only 1 division per line, therefore, enter '1' and then click 'OK'.
Note that we have not yet meshed the geometry, we have simply defined the element
sizes.
8. Mesh
Plot Numbering
Save the model at this time, so if you make some mistakes later on, you will at least be able to come
back to this point. To do this, on the Utility Menu select File > Save as.... Select the name and
location where you want to save your file
You have now defined your model. It is now time to apply the load(s) and constraint(s) and solve
the resulting system of equations.
Open up the 'Solution' menu (from the same 'ANSYS Main Menu').
First you must tell ANSYS how you want it to solve this problem:
o From the Solution Menu, select Analysis Type > New Analysis.
o Ensure that 'Static' is selected; i.e. you are going to do a static analysis on the truss as
opposed to a dynamic analysis, for example.
o Click 'OK'.
2. Apply Constraints
It is necessary to apply constraints to the model otherwise the model is not tied down or
grounded and a singular solution will result. In mechanical structures, these constraints will
typically be fixed, pinned and roller-type connections. As shown above, the left end of the
truss bridge is pinned while the right end has a roller connection.
o In the Solution menu, select Define Loads > Apply > Structural > Displacement >
On Key-points
o Select the left end of the bridge (Key-point 1) by clicking on it in the Graphics
Window and click on 'OK' in the 'Apply U,ROT on KPs' window.
o This location is fixed which means that all translational and rotational degrees of
freedom (DOFs) are constrained. Therefore, select 'All DOF' by clicking on it and
enter '0' in the Value field and click 'OK'. You will see some blue triangles in the
graphics window indicating the displacement constraints.
o Using the same method, apply the roller connection to the right end (UY
constrained). Note that more than one DOF constraint can be selected at a time in the
"Apply U,ROT on KPs" window. Therefore, you may need to 'deselect' the 'All
DOF' option to select just the 'UY' option.
3. Apply Loads
As shown in the diagram, there are four downward loads of 280kN, 210kN, 280kN, and
360kN at key-points 1, 3, 5, and 7 respectively.
o Select Define Loads > Apply > Structural > Force/Moment > on Key-points.
o Select the first Key-point (left end of the truss) and click 'OK' in the 'Apply F/M on
KPs' window.
o Select FY in the 'Direction of force/mom'. This indicate that we will be applying the
load in the 'y' direction
o Enter a value of -280000 in the 'Force/moment value' box and click 'OK'. Note that
we are using units of N here, this is consistent with the previous values input.
o The force will appear in the graphics window as a red
arrow. o Apply the remaining loads in the same manner.
The applied loads and constraints should now appear as shown below.
o In the 'Solution' menu select Solve > Current LS. This indicates that we desire the
solution under the current Load Step (LS).
o The above windows will appear. Ensure that your solution options are the same as
shown above and click 'OK'.
o Once the solution is done the following window will pop up. Click 'Close' and close
the /STATUS Command Window.
Reaction Forces
A list of the resulting reaction forces can be obtained for this element
o from the Main Menu select General Postproc> List Results > Reaction Solu.
o Select 'All strucforc F' as shown above and click 'OK'
Deformation
o In the General Postproc menu, select Plot Results > Deformed Shape.
o Select 'Def + undef edge' and click 'OK' to view both the deformed and the
undeformed object.
o Observe the value of the maximum deflection in the upper left hand corner
(DMX=7.409). One should also observe that the constrained degrees of freedom
appear to have a deflection of 0 (as expected!)
Deflection
o From the 'General Postproc' menu select Plot results > Contour Plot > Nodal
Solution. The following window will appear.
o Select 'DOF solution' and 'USUM' as shown in the above window. Leave the other
selections as the default values. Click 'OK'.
o Looking at the scale, you may want to use more useful intervals. From the Utility
Menu select Plot Controls > Style > Contours > Uniform Contours...
o Fill in the following window as shown and click 'OK'.
o The deflection can also be obtained as a list as shown below. General Postproc>
List Results > Nodal Solution select 'DOF Solution' and 'ALL DOFs' from the lists
in the 'List Nodal Solution' window and click 'OK'. This means that we want to see a
listing of all degrees of freedom from the solution.
NODE UX UY
1 0.000 0.000
2 3.0836 -3.5033
3 0.74604 -6.5759
4 1.5916 -7.2363
5 2.3127 -6.9923
6 -0.49E-01 -3.7338
7 3.1334 0.000
NODE 7 4
VALUE 3.1334 -7.2363
o Are these results what you expected? Note that all the degrees of freedom were
constrained to zero at node 1, while UY was constrained to zero at node 7.
o If you wanted to save these results to a file, select 'File' within the results window (at
the upper left-hand corner of this list window) and select 'Save as'.
Axial Stress
For line elements (ie links, beams, spars, and pipes) you will often need to use the Element Table
to gain access to derived data (ie stresses, strains). For this example we should obtain axial stress to
compare with the hand calculations. The Element Table is different for each element, therefore, we
need to look at the help file for LINK1 (Type help link1 into the Input Line). From Table 1.2 in
the Help file, we can see that SAXL can be obtained through the ETABLE, using the item 'LS,1'
o From the General Postprocessor menu select Element Table > Define
Table o Click on 'Add...'
o Enter 'SAXL' in the 'Lab' box. This specifies the name of the item you are defining.
Next, in the 'Item, Comp‟ boxes, select 'By sequence number' and 'LS,'. Then enter 1
after LS, in the selection box
o Click on 'OK' and close the 'Element Table Data' window.
o Plot the Stresses by selecting Element Table > Plot Elem Table
o The following window will appear. Ensure that 'SAXL' is selected and click 'OK'
o Because you changed the contour intervals for the Displacement plot to "User
Specified" - you need to switch this back to "Auto calculated" to obtain new values
for VMIN/VMAX.
Utility Menu >PlotCtrls> Style > Contours > Uniform Contours ...
Again, you may wish to select more appropriate intervals for the contour plot
ELEM SMAXI
1 -82.900
2 41.447
3 82.900
4 -82.900
5 -8.2900
6 87.038
7 8.2900
8 -91.183
9 91.189
10 45.591
11 -91.189
MINIMUM VALUES
ELEM 11
VALUE -91.189
MAXIMUM VALUES
ELEM 9
VALUE 91.189
PROBLEM STATEMENT
A load of 1000 N/m (1 N/mm) will be applied to a solid steel beam with a rectangular cross section
supported by cantilever beam have a length 1000 m. The cress-section of the beam is 10mm x 10mm
while the modulus of elasticity of the steel is 200GPa.
3. Define lines
Preprocessor > Modeling > create > lines > Lines > Straight Lines
4. Define Element Types
Preprocessor > Element Type > Add/Edit/Delete...
For this problem we will use the BEAM3 element. This element has 3 degrees of freedom
(translation along the X and Y axis's, and rotation about the Z axis). With only 3 degrees of
freedom, the BEAM3 element can only be used in 2D analysis.
5. Define Real Constants…>Add
Preprocessor > Real Constants…> Add…
In the „Real Constants for BEAM3‟ window, enter the following geometric properties:
i. Cross sectional area AREA : 100
ii. Area Moment of Inertia IZZ : 833.333
iii. Total beam height HEIGHT : 10.
This defines an element with a solid rectangular cross section 10mm x 10mm.
ELEM SMAXI
1 750.00
2 405.00
3 120.00
4 105.00
5 270.00
6 375.00
7 420.00
8 405.00
9 330.00
10 195.00
MINIMUM VALUES
ELEM 4
VALUE 105.00
MAXIMUM VALUES
ELEM 1
VALUE 750.00
DISPLACEMENT
NODE UX UY UZ USUM
1 0.0000 0.0000 0.0000 0.0000
2 0.0000 0.0000 0.0000 0.0000
3 0.0000 -3.1500 0.0000 3.1500
4 0.0000 -10.400 0.0000 10.400
5 0.0000 -18.900 0.0000 18.900
6 0.0000 -26.400 0.0000 26.400
7 0.0000 -31.250 0.0000 31.250
8 0.0000 -32.400 0.0000 32.400
9 0.0000 -29.400 0.0000 29.400
10 0.0000 -22.400 0.0000 22.400
11 0.0000 -12.150 0.0000 12.150
NODE 0 8 0 8
VALUE 0.0000 -32.400 0.0000 32.400
Units
Note the units of measure (ie mm) were not specified. It is the responsibility of the user to
ensure that a consistent set of units are used for the problem; thus making any conversions
where necessary.
Correcting-Mistakes
When defining key points, lines, areas, volumes, elements, constraints and loads you are bound
to make mistakes. Fortunately these are easily corrected so that you don't need to begin from
scratch every time an error is made! Every 'Create' menu for generating these various entities
also has a corresponding 'Delete' menu for fixing things up.
2. Define element:
o Click Add... and select 'SOLID ELEMENT ' in that select „2D CONDUCTION 32‟&‟
CONVECTION 34‟type .then click on Add ….
o Then click to „OK‟.
5. Element modeling:
o NODES o COORDINATES(X,Y)
o 1 o (0,0)
o 2 o (0.05,0)
o 3 o (0.20,0)
o 4 o (0.30,0)
o 5 o (0.30,0)
6. Loads:
o From the 'ANSYS Main Menu' select:
o
Preprocessor>load>define load>Apply>Thermal>On nodes
Apply load on boundary conditions(i.e on node 1=300℃ and on node 5=30℃)
7. SOLUTION:
o From the 'ANSYS Main Menu' select:
SOLUTION>ANALYSIS TYPE>NEW ANALYSIS>STEADY STATE
8. SOLVE:
o From the 'ANSYS Main Menu' select:
SOLVE>CURRENT LS.
9. GENERAL POSTPROCESSOR:
o READ RESULT->LAST SET
o THEN CLICK ON „PLOT RESULT →COUNTER PLOT→NODAL
SOLUTION→DOF→NODAL TEMPERATURE
NODE TEMPERATURE
1 200
2 157.5
3 115
4 72.5
5 30
Determine the temperature distribution inside the chimney whose dimensions are given below?
Units
Note the units of measure (ie mm) were not specified. It is the responsibility of the user to
ensure that a consistent set of units are used for the problem; thus making any conversions
where necessary.
Correcting Mistakes
When defining key points, lines, areas, volumes, elements, constraints and loads you are
bound to make mistakes. Fortunately these are easily corrected so that you don't need to
begin from scratch every time an error is made! Every 'Create' menu for generating these
various entities also has a corresponding 'Delete' menu for fixing things up.
2. Define element:
We need to define the element:
o In the preprocessor menu, select Element type>Add/Edit/Delete.
o Click Add... and select 'SOLID ELEMENT' in that select„QUAD NODE 55‟type
.then click on Add ….
o Then click to „Option‟ then change the axis to „Plan thickness‟
o Then click to „OK‟.
5. Element modeling:
-150 150
-150 150
-60 60
-60 60
6. OPERATIONS:
o From the 'ANSYS Main Menu' select:
Preprocessor > Modeling > Create
>OPERATE>BOOLEAN>SUBTRACT>AREA
o Select the outer surface first then click on „OK‟. o
Then select the inner surface then click on „OK‟.
[Again have to create a square of 120*120 and 100*100 then do the same subtraction operation on
it.]
7. GLUE OPERATION:
o From the 'ANSYS Main Menu' select:
Preprocessor > Modeling > Create >OPERATE>BOOLEAN>GLUE>AREA
o Select the outer surface and then inner surface then click on „OK‟.
8. Mesh Size :
o From the 'ANSYS Main Menu' select:
Preprocessor>meshing>mesh attributes>picked area.
o Select all the surfaces of inner and outer
square. o In the Preprocessor menu select
Preprocessor>Meshing > Size Controls > Global Size >size
o Then give the size as 50.so it will dive the inner and dimension by
50. o Then mesh tool:
Preprocessor>meshing>mesh
tool o Select free mesh.
o Then pick all...
9. Loads:
o From the 'ANSYS Main Menu' select:
Preprocessor>load>define load>apply>thermal>convection>on line
o Pick all the walls of inner surface.
o Then there will be a block comes, which ask for the values of film co-efficient and
bulk temperature for surface 1.then the value for film coefficient is 0.208 and bulk
temperature is 637C .then click on ‟OK‟.
o Then select all the outer surfaces, then change the surface from 1->2 and give the
value of film coefficient as 0.0068 and bulk temp as 253C.then click on „OK‟.
SOLUTION PHASE:
10. SOLUTION:
o From the 'ANSYS Main Menu' select:
SOLUTION>ANALYSIS TYPE>NEW ANALYSIS>STEADY STATE
11. SOLVE:
o From the 'ANSYS Main Menu' select:
SOLVE>CURRENT LS.
12. GENERAL POSTPROCESSOR:
o READ RESULT->LAST SET
o THEN CLICK ON „PLOT RESULT →COUNTER PLOT→NODAL
SOLUTION→DOF MODEL‟
LIST RESULT:-
NODE TEMP NODE TEMP NODE TEMP NODE TEMP NODE TEMP
1 224.25 18 169.24 35 132.36 52 148.63 69 412.86
2 224.04 19 209.16 36 138.18 53 123.69 70 398.61
3 70.133 20 69.949 37 133.11 54 139.62 71 398.61
4 91.814 21 91 .821 38 120.98 55 151.89 72 412.77
5 129.23 22 129.39 39 125 56 116.02 73 477.67
6 169.2 23 169.21 40 157.13 57 144.32 74 477.67
7 209.08 24 208.95 41 134.63 58 138.64 75 371.66
8 223.85 25 138.13 42 134.63 59 139.5 76 477.66
9 69 .962 26 136.01 43 152.23 60 132.17 77 371.67
10 91 .882 27 132.41 44 130.18 61 492.58 78 477.66
11 129.26 28 136.81 45 154.29 62 491.34
12 169.32 29 137.69 46 132.37 63 398.88
13 208.9 30 135.2 47 140.1 64 412.86
14 223.99 31 139.7 48 125.62 65 491.34
15 72.181 32 136.3 49 137.29 66 406.06
16 91.245 33 133.96 50 146.79 67 406.06
17 129.19 34 142.89 51 137.43 68 494.89
The plate 200*100 mm area and 10mm thickness is given. The plate has centre hole with 10mm
diameter as shown in figure. The Right side of the plate is subjected to 1MPa force and the left side
of the plate of fixed. The modulus of elasticity of the material is 200GPa. Determine the stress and
deformation in plate given below?
Correcting Mistakes
When defining key points, lines, areas, volumes, elements, constraints and loads you are bound
to make mistakes. Fortunately these are easily corrected so that you don't need to begin from
scratch every time an error is made! Every 'Create' menu for generating these various entities
also has a corresponding 'Delete' menu for fixing things up.
2. Define element:
We need to define the element:
IN THE MENU,SELECT PREPROCESSOR PREFENCES > STRUCTURE
Prxy=0.3
4. Element Modeling:
o Operate>Booleans >subtract>area
o Select Rectangle plate then APPLY, select CIRCLE then APLLY>OK
o Go to Meshing> size control> Manual Size >area>all area: Enter element edge length=4.
o Meshing >Meshtool >Select two area then ,OK
6. LOADS:
8. General POSTPROCESSOR: