Sei sulla pagina 1di 135

Ganpat University

U.V Patel College of Engineering


Mechanical Engineering Department

LABORATORY MANUAL

Computer Aided Design

B.Tech – Mechanical Engineering

th
VII Semester
E8-Batch

U. V. PATEL COLLEGE OF ENGINEERING


GANPAT UNIVERSITY
KHERVA-384012, DIST. MEHSANA.
Certificate

This is to certify that,

______________________________________________________________, the student of


th
7 Semester Mechanical Engineering Roll
No._____________________ , has satisfactorily completed the course
in “2ME 704- Computer Aided Design” within four
walls of U. V. Patel college of Engineering, Kherva, in
year of 2017.
Date of Submission_____________ Staff in charge

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

SR.NO. DESCRIPTION DATE PAGE SIGN


1 INTRODUCTION TO CAD

2 TO UNDERSTAND AND MAKE A PROGRAM OF DDA LINE


ALGORITHM BY USING C-LANGUAGE
3 TO UNDERSTAND AND MAKE A PROGRAM OF
BRESENHAM’S LINE ALGORITHM BY USING C-LANGUAGE
4 TO UNDERSTAND AND MAKE A PROGRAM OF CIRCLE
ALGORITHM BY USING C-LANGUAGE
5 TO UNDERSTAND AND MAKE A PROGRAM OF ELLIPSE
ALGORITHM BY USING C-LANGUAGE
6 TO UNDERSTAND AND IMPLEMENTATION OF 2D
TRANSFORMATION (TRANSLATION) BY USING MATLAB
7 TO UNDERSTAND AND IMPLEMENTATION OF 2D
TRANSFORMATION (ROTATION) BY USING MATLAB
8 TO UNDERSTAND AND IMPLEMENTATION OF 2D
TRANSFORMATION (SCALING) BY USING MATLAB
9 TO UNDERSTAND AND IMPLEMENTATION OF 2D
TRANSFORMATION (REFLECTION) BY USING MATLAB
10 TO UNDERSTAND AND IMPLEMENTATION OF 2D
TRANSFORMATION (SHEARING) BY USING MATLAB
11 TO UNDERSTAND AND IMPLEMENTATION OF 3D
TRANSFORMATION (TRANSLATION, ROTATION,SCALING
REFLECTION, SHEARING) BY USING MATLAB
12 ANSYS PROBLEM NO.: 1

13 ANSYS PROBLEM NO.: 2

14 ANSYS PROBLEM NO.: 3

15 ANSYS PROBLEM NO.: 4

16 ANSYS PROBLEM NO.:5

LAB INCHARGE
GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 1 DATE:___/___/______

Aim: - Introduction to CAD.


INTRODUCTION:

 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:

The Following are some of the listed capabilities:

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 provides the flexibility to make quick alterations to drawings


 Some of the editing capabilities are such as; move or copy drawing elements, enlarge or reduce
size of a drawing, make multiple copies of a drawing, change units of measure and etc.

3. Units and accuracy level:

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.

4. Storage and access of drawings:

COMPUTER AIDED DESIGN Page 1


INTRODUCTION

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.

5. Sharing CAD drawings:

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:

The computer can be used to prepare project reports.

7. Engineering analysis:

There is a separate category of programs called CAE that can use CAD drawings for engineering
analysis.

8. Computer aided manufacturing (CAM):

  CAM is a common method of manufacturing used by large corporations.


 These systems import CAD drawings into CAM programs to automate the manufacturing process.

CAD MODELS:

  A CAD model is a computer representation of an object or part


 It contains all of the design information including geometry, dimensions, tolerances, materials
 and manufacturing information.
  CAD models replace the paper blueprints and engineering drawings
 The simplest model used in CAD is a 2D model. This model is essentially the computer graphics
 equivalent to an orthographic projection
 A 3D model is the most general model used in CAD software. This model is equivalent to an
 isometric view
 2 basic types of 3D models are wire frame and surface models.
  In a 3D wire frame model, only edges of the object are represented.
 A 3D surface model defines the object in terms of surfaces such as plates (flat) and shells
(curved) in addition to edges.

USE OF SOLID 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.

COMPUTER AIDED DESIGN Page 2


INTRODUCTION

TYPICAL PRODUCT CYCLE:

COMPUTER AIDED DESIGN Page 3


INTRODUCTION

CAD/CAM CONTENTS AND TOOLS:


 Manufacturing process begins with the process planning.

 Process planning is the backbone of the manufacturing process.

 The outcome of the process planning is a production plan, tools procurement, material order, and
machine programming.

 The geometric model to CAD is analogous to the mathematical model to engineering analysis

 The core of the CAD tools is geometric modeling and graphics applications.

TYPICAL CAD PROCESS:

Definition of
Geometric Model

Definition of
Translator

Geometric Model

Interface Algorithms

Design and Analysis


Algorithms

Drafting and
Detailing

Documentation

To CAM Process

DESIGN PROCESS AND CAD TOOLS:


COMPUTER AIDED DESIGN Page 4
INTRODUCTION

Design phase Required cad tool (s)

Geometric modeling techniques, graphics aids,


Design conceptualization
manipulation and visualization

Same as above, animation, assemblies, special


Design modeling and simulation
modeling packages

Analysis packages, customized programs and


Design analysis
packages

Design optimization Customized applications, structural optimization

Dimensioning, tolerances, bill of materials,


Design evaluation
NC

Design communication and


Drafting and detailing, shaded images
documentation

COMPUTER AIDED DESIGN Page 5


INTRODUCTION

TYPICAL CAM PROCESS:

Geometric Model

Interface Algorithms

Process Planning

NC Program

Inspection

Assembly

Packaging

To shipping and marketing


MANUFACTURING PROCESS AND CAM TOOLS:

Manufacturing phase Required cam tool (s)

Capp techniques, cost analysis, materials and


Process planning
tooling specification

Part programming NC programming

Inspection Inspection software

Assembly Robotics simulation and programming

COMPUTER AIDED DESIGN Page 6


INTRODUCTION

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

CAD/CAM MARKET IN US:

COMPUTER AIDED DESIGN Page 7


INTRODUCTION

CAD/CAM MARKET TRANDS:


 Microcomputers and engineering workstations (EWS).

 Traditional turnkey systems.

 The key factor to the future success of CAD/CAM is the development of versatile tools for
design and manufacturing applications
DEFINITIONS OF CAD/CAM TOOLS:
 CAD tools can vary from geometric tools, such as manipulations of graphics entities and
interference checking, on one extreme,

 To customized (domain specific) application programs, such as developing analysis and
optimization routines, on the other extreme
DEFINITION OF CAD TOOLS BASED ON CONSTITUENTS AND IMPLEMENTATION:

DEFINITION OF CAM TOOLS BASED ON CONSTITUENTS AND IMPLEMENTATION:


COMPUTER AIDED DESIGN Page 8
INTRODUCTION

 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.

COMPUTER AIDED DESIGN Page 9


INTRODUCTION

DEFINITION OF CAD-CAM TOOLS BASED ON CONSTITUENTS AND


IMPLEMENTATION:

INDUSTRIAL LOOK AT CAD/CAM:


 Thus far, technology driven.
  Learning the generic basic concepts behind different CAD/CAM systems is valuable.
 3 types of modeling: wireframe, surfaces, solid

COMPUTER AIDED DESIGN Page 10


INTRODUCTION

 If the system's standard software cannot handle the problem, a customized software may be
developed using the programming language (Macro, API programming)

TYPICAL UTILIZATION OF TYPICAL CAD/CAM SYSTEMS:

COMPUTER AIDED DESIGN Page 11


INTRODUCTION

BASIC CONCEPT OF THE FINITE ELEMENT METHOD:


INTRODUCTION:
The finite elements method (FEM), sometime referred to as finite element analysis (FEA), is a
computational techniques used to obtain approximate solution of boundary value problems of
engineering. simply stated, a boundary value problem is a mathematical problem in which one or more
dependent variable must satisfy a differential equation everywhere within a known domain of
independent variable and satisfy specific condition on boundary of the domain .Boundary value problems
are also sometime called field problem .the field is the domain of interest and most often represents a
physical structure. The fields variables are the dependent variable of interest governed by the differential
equation .the boundary condition are the specified value of the field variable (or related variables such as
derivatives) on the boundaries of the field. Depending on the type of physical problem being analyzed,
the field variables may include displacement, temperature, heat flux, and fluid velocity to name only a
few.

HOW DOES THE FINITE ELEMENT METHOD WORK?


The general technique and terminology of finite element analysis will be introduced with reference to
figure 1.1. The figure depicts a volume of some material or materials having known physical properties.
The volume represents the domain of a boundary value problem to be solved. For simplicity , at this point
, we assume a two dimensional case with a single field variable to be determined at every point P(x,y)
such that known governing equation (or equations) is satisfied exactly at every such point. Not that this
implies an exact mathematical solution is obtained; that is, the solution is close-form algebraic expression
of the independent variable. In practical problem, the domain may be geometrically complex as is, often,
the governing equation and the likelihood of obtaining an exact closed –form solution is very low.
Therefore approximate solution based on numerical techniques and digital computations are most often
obtained in engineering analyses of complex problem. Finite element analysis is a powerful technique of
obtaining such approximate solution with good accuracy.

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.

COMPUTER AIDED DESIGN Page 12


INTRODUCTION

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

COMPUTER AIDED DESIGN Page 13


INTRODUCTION

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

  x, y  N x, y N x, y  N x, y


1 1 2 2 3 3

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.

COMPUTER AIDED DESIGN Page 14


INTRODUCTION

COMPARISON OF FINITE ELEMENT AND EXACT SOLUTION:

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.

Figure: - 1.1 (A) & (B)


a) Arbitrary curved boundary domain model using square elements .A total 41 elements is shown.
b) Refined finite element mesh showing reduction of the area not included in the model. A total 192
elements is shown.

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

COMPUTER AIDED DESIGN Page 15


INTRODUCTION

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

(A) Displacement at X=L for tapered cylinder in tension of figure 1.3.


(B) Comparison of the exact solution for a tapered cylinder in tension.

A GENERALPROCEDURE FOR FINITE ELEMENT ANALYSIS:

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.

COMPUTER AIDED DESIGN Page 16


INTRODUCTION

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.

COMPUTER AIDED DESIGN Page 17


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 2 DATE:___/___/______

Aim:- To understand and make a program of DDA line algorithm by


using c-language.
INTRODUCTION:

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

COMPUTER AIDED DESIGN Page 18


DDA ALGORITHM

round up your result.


2. A line with a non positive slope i.e. m < 1 you calculate x instead of y
and take increment in y = 1 and compute successive x values using the equation:

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).

COMPUTER AIDED DESIGN Page 19


DDA ALGORITHM

FLOW CHART:
Line with Positive slope processed from left to right

Start

Input two endpoints


(x0,y0) & (xn,yn)

m <= 1 dy = 1
False xk+1 = xk+ (1/m)
True
dx = 1
Repeat dx
yk+1 = yk + m
times

(xn,yn)

End

COMPUTER AIDED DESIGN Page 18


DDA ALGORITHM

Line with Negative slope processed from left to right

Start

Input two endpoints


(x0,y0) & (xn,yn)

m <= 1 dy = -1
False xk+1 = xk - (1/m)
True
dx = -1
Repeat dx
yk+1 = yk - m
times

(xn,yn)

End

COMPUTER AIDED DESIGN Page 21


DDA ALGORITHM

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;

COMPUTER AIDED DESIGN Page 22


DDA ALGORITHM

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:

COMPUTER AIDED DESIGN Page 23


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 3 DATE:___/___/______

Aim:- To understand and make a program of Bresenham’s line


algorithm by using c-language.

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)

COMPUTER AIDED DESIGN Page 24


BRESENHAM’S LINE ALGORITHM

Figure: 3.2

If di < 0,then only x is incremented


xi+1 = xi + 1
The next d is calculated as,
di+1 = di + 2dy

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

COMPUTER AIDED DESIGN Page 25


BRESENHAM’S LINE ALGORITHM

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

Input two endpoints (x0,y0) &


(xn,yn)

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)

Repeat dx times Pk+1 = pk+ 2dy

(xn,yn)

End

COMPUTER AIDED DESIGN Page 26


BRESENHAM’S LINE ALGORITHM

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);
};

int lines::sign(int xx)


{
if(xx<0)
return -1;
if(xx==0)
return 0;
if(xx>0)
return 1;
return 0;
}
lines::lines()
{
x=0;y=0;
cout<<"Enter The Co-Ordinates (x1,y1) :=";

COMPUTER AIDED DESIGN Page 27


BRESENHAM’S LINE ALGORITHM

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;

COMPUTER AIDED DESIGN Page 28


BRESENHAM’S LINE ALGORITHM

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();

COMPUTER AIDED DESIGN Page 29


BRESENHAM’S LINE ALGORITHM

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");

COMPUTER AIDED DESIGN Page 30


BRESENHAM’S LINE ALGORITHM

outtextxy(320,450,"-Y");
outtextxy(100,240,"-X");
outtextxy(320,30,"Y");
a.showline();
closegraph();

OUTPUT:

COMPUTER AIDED DESIGN Page 31


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 4 DATE:___/___/______

Aim:- To understand and make a program of Circle


algorithm by using c-language.
CIRCLE:

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

P1=(x,y) P2 =(y,x) P3 =(-y,x) P4 =(-x,y) P5 =(-x,-y) P6 =(-y,-x) P7=(y,-x) P8=(x,-y)


Any point on circle can be defined efficiently by Bresenham,s circle algorithm and Midpoint circle
algorithm.

COMPUTER AIDED DESIGN Page 32


CIRCLE ALGORITHM

BRESENHAM’S CIRCLE ALGORITHM:

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:

COMPUTER AIDED DESIGN Page 33


CIRCLE ALGORITHM

= 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

If T is chosen pixel (meaning that < 0) then = and so

= +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;

Otherwise, the next point along the circle is (x+1, y-1)


and p=p+4(x-y)+2;

4. Determine symmetry points in the other seven octants.


5. Move each calculated pixel position (x, y) onto the circular path
Centred at (xc , yc ) and plot the coordinate values:
x = x + xc , y = y + yc
6. Repeat steps 3 through 5 until x ≥ y.

COMPUTER AIDED DESIGN Page 34


CIRCLE ALGORITHM

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

Find next co-ordinates

Determine points in seven


remaining octants

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();
}

COMPUTER AIDED DESIGN Page 36


CIRCLE ALGORITHM

OUTPUT:

MID-POINT CIRCLE ALGORITHM:

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:

<0 for (x,y) inside the circle


2 2 2
f(x,y)=x +y -r =0 for (x,y) on the circle
>0 for (x,y) outside the circle

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

COMPUTER AIDED DESIGN Page 37


CIRCLE ALGORITHM

If pi<0, the midpoint is inside the circle and we choose pixel T


If pi>=0, the midpoint is on or outside of circle and we choose pixel S
2 2
Next decision parameter: pi+1=(xi+1+1) + (yi+1-(1/2)) -
2
r Since xi+1+=xi+1,
2 2
pi+1 = pi + 2(xi+1) +1+ (yi+1 -yi ) - (yi+1-yi)
If T pixel is chosen than yi+1=yi and if S pixel is chosen than yi+1=yi-1.Thus,

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;

Otherwise, the next point along the circle is (x+1, y-1)


and p=p+2(x-y)+1;

4. Determine symmetry points in the other seven octants.


5. Move each calculated pixel position (x, y) onto the circular
path Cantered at (xc , yc ) and plot the coordinate values:
x = x + xc , y = y + yc
6. Repeat steps 3 through 5 until x ≥ y.

COMPUTER AIDED DESIGN Page 38


CIRCLE ALGORITHM

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

Find next co-ordinates

Determine points in seven


remaining octants

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();

COMPUTER AIDED DESIGN Page 39


CIRCLE ALGORITHM

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();
}

COMPUTER AIDED DESIGN Page 40


CIRCLE ALGORITHM

OUTPUT:

COMPUTER AIDED DESIGN Page 41


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 5 DATE:___/___/______

Aim: To understand and make a program of Ellipse algorithm


by using c-language.
Ellipse

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

COMPUTER AIDED DESIGN Page 42


ELLIPSE ALGORITHM

BRESENHAM’S MIDPOINT ELLIPSE ALGORITHM:

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

Which has following properties?


f ellipse ( x, y)  If <0 ( x , y) is inside the ellipse boundary
If =0 ( x , y) is on the ellipse boundary
If >0 ( x , y) is outside the ellipse boundary

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

COMPUTER AIDED DESIGN Page 43


ELLIPSE ALGORITHM

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 / 4r 2
0 y x y x

3. At each x k position in region 1, starting at k = 0, perform the following test.


If p1k <0, the next point along the ellipse cantered on (0, 0)
is xk 1 , yk and p1k 1  p1k  2r y xk 1  r
2 2
y

Otherwise, the next point along the ellipse is xk  1, yk  1  and


p1  p1  2r 2 x  2r 2 y  r 2
k1 k y k 1 x k 1 y
2 2 2 2 2 2
With 2r y xk 1  2r y xk  2r y , 2r x yk 1  2r x yk  2r x and continue
2 2
until 2r y x 2r x y .

For region 2
4. Calculate the initial value of the decision parameter in region 2 as
p2  r 2 x  1/ 22  r 2 (y  1) 2 r 2 r 2
0 y 0 x 0 x y

Where (x 0 , y 0 ) is the last position calculated in region 1.


5. At each yk position in region 2, starting at k = 0, perform the following
>0, the next point along the ellipse centred on (0, 0) is xk , yk  1  and
2
Test. If p k

p2  p2  2r 2x y k 1  r 2x
k 1 k

Otherwise, the next point along the ellipse is xk  1 , yk  1 and


p2 k1  p2 k  2r 2y xk 1  2r 2 x y k 1  r 2x
Using the same incremental calculations for x and y as in region 1.
Continue until y = 0.
6. For both regions, determine symmetry points in the other three quadrants.
7. Move each calculated pixel position (x, y) onto the elliptical path centred
On xc , yc  and plot the coordinate values:
x  x  xc , y  y  yc
2 2
8. Repeat the steps for region 1 until 2r y x  2r xy .

COMPUTER AIDED DESIGN Page 45


ELLIPSE ALGORITHM

FLOW CHART:

COMPUTER AIDED DESIGN Page 46


ELLIPSE ALGORITHM

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
{

COMPUTER AIDED DESIGN Page 47


ELLIPSE ALGORITHM

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:

COMPUTER AIDED DESIGN Page 48


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 6 DATE:___/___/______

AIM:- To understand and implementation of 2d


Transformation (Translation) by using matlab.
TRANSLATIONS:

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 'xt y 'yt
x y (A)

Translation matrix is given below:

 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   

COMPUTER AIDED DESIGN Page 49


2D Transformation-(Translation)

This allows us to write the 2D translation equation-(C) in the matrix form:

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)

The Inverse Translation in 2D:

To do inverse or back translation by use of translation matrix tx & ty

COMPUTER AIDED DESIGN Page 50


2D Transformation-(Translation)

Inverse translation matrix is given below:

 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 0s 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 

Which when multiplied out yields

 x f (1  sx ) 0 0
 
 0 y f (1  sy ) 0
 
 0 0 1

So a scaled point [x y 1] becomes

 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:

COMPUTER AIDED DESIGN Page 51


2D Transformation-(Translation)

MATLAB code for 2D translation:

% 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

enter the value of translation in x co-ordinate4

COMPUTER AIDED DESIGN Page 52


2D Transformation-(Translation)

xt =

enter the value of translation in y co-ordinate6

yt =

6
Output:

T =

1 0 0
0 1 0
4 6 1

pn =

4 6 1
14 26 1
24 16 1

Figure:

COMPUTER AIDED DESIGN Page 53


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 7 DATE:___/___/______

AIM:- To understand the concept and implementation of


2d Transformation (Rotation).
ROTATION:

Rotations alter the orientation of an object: They are a little more complex than scales. Starting in
two dimensional rotations is easiest.

Rotations in Two Dimensions:

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.

FIG (A) -Rotation of object through angle  about pivot point ( xr , y r )

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 

COMPUTER AIDED DESIGN Page 54


2D-Transformation-(Rotation)

R is the constant distance of the origin, angle  is the original angular position from the horizontal,
 is the rotationangle. We can express the transformed coordinate in terms of angles  &  as:

x  r cos(   )  r cos  cos   r sin  sin  (C)

y '  r sin(   )  r cos  sin   r sin  cos (D)

The original coordinate of the point in polar coordinates are:

x  r cos y =r sin  (E)

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:

x  x cos   y sin


(F)
y  =y cos   x sin

With the column vector representation for coordinate position, we can write the rotation equation in
the matrix form:
'
P R P (G)

Where the rotation matrix is

 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 ):

COMPUTER AIDED DESIGN Page 55


2D-Transformation-(Rotation)

H): Rotating a point from position(x, y) to position (x’, y’) through angle θ about
rotation point ( xr , yr ).

x  r cos(   )  r cos  cos   r sin  sin


(I)
y  r sin(   )  r cos  sin   r sin  cos
'

The General Pivot point of a Rotation:

The following sequence of translate –rotate – translate operations:

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.

Original position Translation Rotation about origin Translation of


Object so that
The pivot point
Returned- ( xr , yr )

The composite transformation matrix for this sequence is obtained with concatenation:

COMPUTER AIDED DESIGN Page 56


2D-Transformation-(Rotation)

1 0 xr   cos  sin  0   1 0 x 


     r 
 0 1 y
r   sin  cos  0   0 1 y
r 

     
 0 0 1   0 0 1   0 0 1 

 cos   sin  x (1  cos  )  yr sin  


 r 
sin  cos  y (1  cos  )  x sin  
r r
(J)
 
 0 0 1 

This can be expressed in the form:

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.

MATLAB code for 2D Rotation:


% 2D Transformation
(Rotation) 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 rotation')
xlabel('x axis')
ylabel('y axis')
p(:,3)=1
hold on
thet=input('enter the value of angle of rotation')
t=pi*thet/180
% Generate rotation matrix
R=[cos(t),sin(t),0;-
sin(t),cos(t),0;0,0,1] pn=p*R
% Plot new geometry after rotation
plot([pn(:,1);p(1,1)],[pn(:,2);p(1,2)],'bo-')

COMPUTER AIDED DESIGN Page 57


2D-Transformation-(Rotation)

Example of 2D Rotation:
Input:

Output:

Figure:

COMPUTER AIDED DESIGN Page 58


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 8 DATE:___/___/______

Aim:-To understand and implementation of 2d


Transformation (Scaling) by using matlab.
SCALING:

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

Here S represents scaling Matrix.

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

2-Dimensional scaling in the Matrix form is given by

COMPUTER AIDED DESIGN Page 59


2D-Transformation-(Scaling)

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.

COMPUTER AIDED DESIGN Page 60


2D-Transformation-(Scaling)

SCALE MATRIX: S = =

NEW POINT: Q = S*P = =

MATLAB code for 2D Scaling:

% 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

enter the value of scaling factor in x co-


ordinate 2

Sx =

COMPUTER AIDED DESIGN Page 61


2D-Transformation-(Scaling)

enter the value of scaling factor in y co-


ordinate 4

Sy =

Output:
S =

2 0 0
0 4 0
0 0 1

pn =

0 0 1
20 80 1
40 40 1

Figure:

COMPUTER AIDED DESIGN Page 62


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 9 DATE:___/___/______

AIM:- Write a program for 2d Transformation (Reflection).


REFLECTION
A reflection is a transformation matrix that produces a mirror image of an object. The mirror image for a two dimensional reflection is generated
relative to an axis of reflection by rotating the object 180° about the reflection axis.

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.

Reflection about the line y=0, the x axis, is


accomplished with the transformation matrix

 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.

A reflection about the y axis flips x coordinates while


keeping y coordinates the same. The matrix for this
transformation is The matrix for this transformation as
below:

Reflection of an object about the x-axis


The matrix for this transformation as below:

1 0 0
 
 0
 0 0 1
1 0


COMPUTER AIDED DESIGN Page 63


2D Transformation-(Reflection)

Reflection of the object about y-axis Reflection of an object relative to an axis


Perpendicular to the xy plane and passing
Through the coordinate origin.

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 
 

COMPUTER AIDED DESIGN Page 64


2D Transformation-(Reflection)

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°

2. Reflection about the y axis


3. Counterclockwise rotation by 45°

The resulting transformation matrix as below:

 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.

Reflection with respect to the line y = -x

COMPUTER AIDED DESIGN Page 65


2D Transformation-(Reflection)

MATLAB code for 2D Reflection:

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

chose value for reflection about


1 for X-axis
2 for Y-axis
3 for x= y
4 for x= -y= 1

t =

Output:
R =
1 0
0 -1

COMPUTER AIDED DESIGN Page 66


2D Transformation-(Reflection)

pn =

2 -3
4 -5

Figure:

[2]
Input:

p =

2 3
4 5

Chose value for reflection about


1 for X-axis
2 for Y-axis
3 for x= y
4 for x= -y= 2

t =

Output:
R =

-1 0
0 1

COMPUTER AIDED DESIGN Page 67


2D Transformation-(Reflection)

pn =

-2 3
-4 5

Figure:

[3]
Input:
p =

2 3
4 5

chose value for reflection about


1 for X-axis
2 for Y-axis
3 for x=y
4 for x=-y
=

t =

Output:
R =

0 1
1 0

COMPUTER AIDED DESIGN Page 68


2D Transformation-(Reflection)

pn =

3 2
5 4

Figure:

[4]
Input:
p =

2 3
4 5

chose value for reflection about


1 for X-axis
2 for Y-axis
3 for x=y
4 for x=-y
=4

t =

Output:
R =

0 -1
-10

pn =

-3 -2
-5 -4

COMPUTER AIDED DESIGN Page 69


2D Transformation-(Reflection)

Figure:

COMPUTER AIDED DESIGN Page 70


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 10 DATE:___/___/______

AIM:-To understand and implementation of 2d


Transformation (Shearing) by using matlab.
SHEAR
A transformation that distorts the shape of an object such that the transformed shape appears as if the
object were composed of internal layers that had been caused to slide over each other is called a
shear. Two common Shearing transformations are those that shift coordinate x values and those that
shift y values.

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.

COMPUTER AIDED DESIGN Page 71


2D Transformation-(Shearing)

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.

COMPUTER AIDED DESIGN Page 72


2D Transformation-(Shearing)

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.

MATLAB code for 2D Shearing:

% 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

COMPUTER AIDED DESIGN Page 73


2D Transformation-(Shearing)

pn=p*S
% Plot new geometry after shearing
plot([pn(:,1);pn(1, 1)], [pn(:,2);pn(1,2)], 'bo-')

Example of 2D Shear in X direction:

[1]

Input:
p =

0 0 1
10 20 1
20 10 1

enter 1 for shear in X-axis


or enter 2 for shear in Y-axis
1

t =

enter the value of shear in X direction4

a =

Output:
S =

1 4 0
0 1 0
0 0 1

pn =

0 0 1
10 60 1
20 90 1

COMPUTER AIDED DESIGN Page 74


2D Transformation-(Shearing)

Figure:

[2]

Input:
p =

0 0 1
10 20 1
20 10 1

enter 1 for shear in X-axis


or enter 2 for shear in Y-axis
2

t =

enter the value of shear in Y direction3

b =

Output:
S =

1 0 0
3 1 0
0 0 1

COMPUTER AIDED DESIGN Page 75


2D Transformation-(Shearing)

pn =

0 0 1
70 20 1
50 10 1

Figure:

COMPUTER AIDED DESIGN Page 76


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO:11 DATE:___/___/______

AIM:-To understand and implementation of 3d Transformation


(Translation, Rotation, Scaling, Reflection, Shearing) by using matlab.
TRASLATION:

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.

For y-axis rotation the matrix is represented as,

COMPUTER AIDED DESIGN Page 77


3D Transformation

 x '   cos 0 sin 0  x 


     
1 0 0  y
y '   0 .  
 z '  =  sin 0 cos 0  z 
     
0 0 1  1 
 1   0

P’=Ry (θ).P

Coordinate-Axes Rotations:

The 2-D z-axis rotation equations are easily extended to 3-D:

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.

x '  x cos   y sin 



y '  x sin   y cos
z '  z

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:

COMPUTER AIDED DESIGN Page 78


3D Transformation

 x '   cos  sin  0 0 x 


     
y' sin  cos  0 0 y
  .  
 z '   0 0 1 0  z 
     
1   0 0 0 1  1 

General 3-D Rotations:

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.

A unit vector u is defined along the rotation axis as


V
u| V |  ( a , b, c)
Here the components a,b and c of unit vector u are the direction cosines for the rotation
Axis:

COMPUTER AIDED DESIGN Page 79


3D Transformation

x 2  x1 y2y1 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.

 x '   Sx 0 0 0  x


     
y' 0 Sy 0 0 y
  .  
 z '   0 0 Sz 0  z
     
1   0 0 0 1  1

P’=S.P

COMPUTER AIDED DESIGN Page 80


3D Transformation

Scaling with respect to a selected fixed position ( xf ,yf ,zf ) can be represented with
the following transformation sequence:

Translate the fixed point to the origin..


Scale the object relative to the coordinate origin.
Translate the fixed point back to its original position.

This sequence of transformations is demonstrated and the matrix representation for an


Arbitrary fixed-point scaling can be expressed as the concatenation of these translate-
Scale-translate transformations as

 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:

The reflection of an image of a 3D point is obtained by taking the reflection of the


point about three different planes:

1. X-Y plane
2. Y-Z plane
3. Z-X plane

COMPUTER AIDED DESIGN Page 81


3D Transformation

A 3D Reflection can be performed with respect to a selected reflection plane.


Reflections relative to a given axis are equivalent to 180˚ rotations about that axis.
Reflections with respects to a plane are equivalent to 180˚ rotations in four-dimensional
space. The matrix representation for reflection of points relative to the XY plane is

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.

MATLAB code for 3D Transformations (Using Switch Case):


[Translation, Rotation, Scaling, Shearing, Reflection]

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);

COMPUTER AIDED DESIGN Page 82


3D Transformation

case 3
pn = Scaling(p);

case 4
pn = Reflection(p);

case 5
pn = Shearing(p);

otherwise
pn= Translation(p);
end

%%function for Translation%%


function [pn] = Translation(p)
p= load('point a.txt')
p(:,4)=1
tx= input('enter the translation in x axis \n')
ty= input('enter the translation in y axis \n')
tz= input('enter the translation in z axis \n')
T=[1,0,0,0;0,1,0,0;0,0,1,0;tx,ty,tz,1] pn = p*T

plot3([pn(:,1);pn(1,1)],[pn(:,2);pn(1,2)],[pn(:,3);pn(1,3)],'bo-')
Return

%%function for Rotation%%


function [pn] = Rotation(p)
p= load('point a.txt');
p(:,4)= 1;
hold on
th = input('enter the angle of
rotation\n'); th=th*pi/180;
t=input('enter 1 for x-axis rotation\n2 for y-axis rotation\nand 3 for z-
axis rotation\n');
if t==1
R=[1 0 0 0;0 cos(th) sin(th) 0;0 -sin(th) cos(th) 0;0 0 0
1]; elseif t==2
R=[cos(th) 0 -sin(th) 0;0 1 0 0;sin(th) 0 cos(th) 0;0 0 0
1]; else
R=[cos(th) sin(th) 0 0;-sin(th) cos(th) 0 0;0 0 1 0;0 0 0 1];
end
pn=p*R;
plot3([pn(:,1);pn(1,1)],[pn(:,2);pn(1,2)],[pn(:,3);pn(1,3)],'bo-');
Return

%%function for Scaling%%


function [pn] = Scaling(p)
p= load('point a.txt')
p(:,4)= 1
Sx= input('enter the scaling factor in x axis
\n') Sy= input('enter the scaling factor in y
axis \n') Sz= input('enter the scaling factor in
z axis \n')
S=[Sx,0,0,0;0,Sy,0,0;0,0,Sz,0;0,0,0,1] pn = p*S
plot3([pn(:,1);pn(1,1)],[pn(:,2);pn(1,2)],[pn(:,3);pn(1,3)],'bo-')
end

%%function for Reflection%%

COMPUTER AIDED DESIGN Page 83


3D Transformation

function [pn] = Reflection(p)


p=load('point a.txt')
hold on
t=input('enter 1 for X-axis reflection\n2 for Y-axis reflection\n3 for Z-
axis reflection\n')
if t==1
R=[1 0 0;0 -1 0;0 0 1]
else if t==2
R=[-1 0 0;0 1 0;0 0 1]
else
R=[0 1 0;1 0 0;0 0 1]
end
end
pn=p*R
plot3([pn(:,1);pn(1,1)],[pn(:,2);pn(1,2)],[pn(:,3);pn(1,3)],'bo-')
end

%%function for Shearing%%


function [pn] = Shearing(p)
p=load('point a.txt')
hold on
disp('Enter your choice for shear in different plane')
t=input( '1 for xy plane\n2 for yz plane\n3 for xz
plane\n=') if t==1
Sx=input('enter the value of shear in X direction=')
Sy=input('enter the value of shear in Y direction=')
S=[1 0 0 ;0 1 0;Sx Sy 0]
else if t==2
Sy=input('enter the value of shear in Y
direction=') Sz=input('enter the value of shear in
Z direction=') S=[1 Sy Sz;0 1 0;0 0 1]
else
Sx=input('enter the value of shear in X direction=')
Sz=input('enter the value of shear in Z direction=')
S=[1 0 0;Sx 1 Sz;0 1 1]
end
end
pn=p*S
plot3([pn(:,1);pn(1,1)],[pn(:,2);pn(1,2)],[pn(:,3);pn(1,3)],'bo-')
end

Example of 3D Transformations (Using Switch Case):

[1] Translation:

Input:
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing
enter your choice =1

COMPUTER AIDED DESIGN Page 84


3D Transformation

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

enter the translation in x axis


10

tx =

10

enter the translation in y axis


15

ty =

15

enter the translation in z axis


20

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

COMPUTER AIDED DESIGN Page 85


3D Transformation

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

COMPUTER AIDED DESIGN Page 86


3D Transformation

enter the angle of rotation


90

th =

90

th =

1.5708

enter 1 for x-axis rotation


2 for y-axis rotation
and 3 for z-axis rotation
2

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 =

10.0000 10.0000 -10.0000 1.0000


20.0000 20.0000 -20.0000 1.0000
30.0000 30.0000 -30.0000 1.0000
40.0000 30.0000 -10.0000 1.0000
30.0000 50.0000 -20.0000 1.0000
20.0000 70.0000 -30.0000 1.0000

COMPUTER AIDED DESIGN Page 87


3D Transformation

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

enter the scaling factor in x axis


2

COMPUTER AIDED DESIGN Page 88


3D Transformation

Sx =

enter the scaling factor in y axis


2

Sy =

enter the scaling factor in z axis


2

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

COMPUTER AIDED DESIGN Page 89


3D Transformation

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

enter 1 for X-axis reflection


2 for Y-axis reflection
3 for Z-axis reflection
3

t =

COMPUTER AIDED DESIGN Page 90


3D Transformation

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:

COMPUTER AIDED DESIGN Page 91


3D Transformation

[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

Enter your choice for shear in different plane


1 for xy plane
2 for yz plane
3 for xz plane
=3

t =

enter the value of shear in X direction=2

Sx =

enter the value of shear in Z direction=4

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

COMPUTER AIDED DESIGN Page 92


3D Transformation

Figure:

COMPUTER AIDED DESIGN Page 93


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO:12 DATE:___/___/______

Aim:-Ansys problem no.:-1.


PROBLEM STATEMENT

Determine the nodal deflections, reaction forces, and stress for the truss system shown below (E =
2
200GPa, A = 3250mm ).

PREPROCESSING: DEFINING THE PROBLEM

1. Give the Simplified Version a Title (such as 'Bridge Truss


Tutorial'). In the Utility menu bar select File > Change Title:
Enter the title and click 'OK'. This title will appear in the bottom left corner of the 'Graphics'
Window once you begin. Note: to get the title to appear immediately, select Utility Menu >
Plot >Replot.

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

COMPUTER AIDED DESIGN Page 94


Truss – Bridge Problem

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

o (these key-points are depicted by numbers in the above figure)


o From the 'ANSYS Main Menu' select:
Preprocessor > Modeling > Create >Key-points> In Active CS
o Enter key-point number 1 in the appropriate box, and enter the x,y coordinates: 0,
0 in their appropriate boxes (as shown above).
Click 'Apply' to accept what you have typed.
o Enter the remaining key-points using the same method.

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.

3. There are two types of approaching method


  
Top To Bottom approach
 
Bottom To Top approach

I. Bottom To Top approach :-


In this method connection between key points is done in to two steps.

1. Creating The Nodes:

In this step the key points are defined as nodes.


o In the main menu select: Preprocessor > Modeling > Create>Nodes. The following
will be appearing.
o Use the keyboard to enter the value of the x,y,z co-ordinate of the key points in the
given boxes one by one and nodes will be created at the key points.

COMPUTER AIDED DESIGN Page 95


Truss – Bridge Problem

2. Creating The Line Element:

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.

COMPUTER AIDED DESIGN Page 96


Truss – Bridge Problem

II. Top To Bottom approach:-

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.

COMPUTER AIDED DESIGN Page 97


Truss – Bridge Problem

4. Define the Type of Element

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.

5. Define Geometric Properties

We now need to specify geometric properties for our elements:


o In the Preprocessor menu, select Real Constants > Add/Edit/Delete
o Click Add... and select 'Type 1 LINK1' (actually it is already selected). Click on
'OK'.
o Enter the cross-sectional area (3250mm):
o Click on 'OK'.
o 'Set 1' now appears in the dialog box. Click on 'Close' in the 'Real Constants' window.

COMPUTER AIDED DESIGN Page 98


Truss – Bridge Problem

6. Element Material Properties

You then need to specify material properties:


o In the 'Preprocessor' menu select Material Props > Material Models
o Double click on Structural > Linear > Elastic > Isotropic
o We are going to give the properties of Steel.
o Set these properties and click on 'OK'. Note: You may obtain the note 'PRXY will be
set to 0.0'. This is poisson's ratio and is not required for this element type. Click 'OK'
on the window to continue. Close the "Define Material Model Behavior" by clicking
on the 'X' box in the upper right hand corner.

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

Now the frame can be meshed.


o In the 'Preprocessor' menu select Meshing > Mesh > Lines and click 'Pick All' in
the 'Mesh Lines' Window
Your model should now appear as shown in the following window

COMPUTER AIDED DESIGN Page 99


Truss – Bridge Problem

Plot Numbering

To show the line numbers, key-point numbers, node numbers...


 From the Utility Menu (top of screen) select PlotCtrls> Numbering...
 Fill in the Window as shown below and click 'OK'

Saving Your Work

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

SOLUTION PHASE: ASSIGNING LOADS AND SOLVING

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').

COMPUTER AIDED DESIGN Page 100


Truss – Bridge Problem

1. Define Analysis Type

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.

COMPUTER AIDED DESIGN Page 101


Truss – Bridge Problem

4. Solving the System

We now tell ANSYS to find the solution:

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.

POSTPROCESSING: VIEWING THE RESULTS

1. Results Using ANSYS

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'

COMPUTER AIDED DESIGN Page 102


Truss – Bridge Problem

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'.

COMPUTER AIDED DESIGN Page 103


Truss – Bridge Problem

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'.

COMPUTER AIDED DESIGN Page 104


Truss – Bridge Problem

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

MAXIMUM ABSOLUTE VALUES

NODE 7 4
VALUE 3.1334 -7.2363

COMPUTER AIDED DESIGN Page 105


Truss – Bridge Problem

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.

COMPUTER AIDED DESIGN Page 106


Truss – Bridge Problem

Utility Menu >PlotCtrls> Style > Contours > Uniform Contours ...

Again, you may wish to select more appropriate intervals for the contour plot

o List the Stresses

  From the 'Element Table' menu, select 'List Elem Table'


 From the 'List Element Table Data' window which appears ensure 'SAXL' is
 highlighted
 Click 'OK'

COMPUTER AIDED DESIGN Page 107


Truss – Bridge Problem

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

COMPUTER AIDED DESIGN Page 108


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 13 DATE:___/___/______

Aim:-Ansys problem no.:-2.

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.

DEFINING THE PROBLEM:-

1. Open preprocessor menu/PRE7


Give example a title
Utility Menu > File > > change Title..
2. Create key points
Preprocessor > Modeling > create > Key points > In Active CS K, #, x, y
We are going to define 2 key points (the beam vertices) for this structure as given in the following
table:
Key point Coordinates(x,y)
1 (0,0)

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…

COMPUTER AIDED DESIGN Page 109


Cantilever Beam Problem

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.

1. Define Element Material Properties.


Preprocessor > Material Props > Material Models > Structural > Linear > Elastic >
Isotropic
In the window that appear,
Enter the following geometric properties for steel:

i. Young‟s Modulus EX : 200000


ii. Poisson‟s Ratio : 0.3.
2. Define Mesh Size.
Preprocessor > Meshing > Size Cntrls > Manual Size > Lines > All lines.
For this example we will use an element length of 100mm.
3. Mesh the frame
Preprocessor > Meshing > Mesh > Lines > All Lines…
For This example we will use an element length of 100mm.
4. Plot Elements.
Utility Menu > Plot > Elements

ASSIGNING LOADS AND SOLVING.

1. Define Analysis Type


Solution > Analysis Type > New Analysis > Static
2. Apply Constraints
Solution > Define loads > Apply > Structural > Displacement > on Key points.
Pin Key points 1 (i.e. UX and UY constrained) and fix key point 2 in the y direction
(UY constrained).
3. Apply Loads.
We will apply a distributed load, of 1000N/m or 1N/mm, over the entire length of the
beam. Solution > Define Loads > Apply > Structural > pressure > on Beams.
4. Solve the system.
Solution > Solve > Current LS Solve

VIEWING THE RESULTS

1. Plot Deformed shape


General Postproc > Plot Results > Deformed Shape
The applied loads and constraints should now appear as shown in the figure.

COMPUTER AIDED DESIGN Page 110


Cantilever Beam Problem

Solution under the given conditions is shown in figure.

COMPUTER AIDED DESIGN Page 111


Cantilever Beam Problem

Solution is shown in figure below

2. Plot Principle stress distribution.

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

COMPUTER AIDED DESIGN Page 112


Cantilever Beam Problem

3. The below table shows the displacement values at each nodes.

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

MAXIMUM ABSOLUTE VALUES

NODE 0 8 0 8
VALUE 0.0000 -32.400 0.0000 32.400

COMPUTER AIDED DESIGN Page 113


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 14 DATE:___/___/______

Aim:-Ansys problem no.:-3.


PROBLEM STATEMENT:

Determine the temperature distribution in composite wall given below?

PREPROCESSING: DEFINING THE PROBLEM

1. Give the Simplified Version a Title (such as 'Bridge Truss Tutorial').


In the Utility menu bar select File > Change Title:
Enter the title and click 'OK'. This title will appear in the bottom left corner of the 'Graphics'
Window once you begin. Note: to get the title to appear immediately, select Utility Menu >
Plot >Replot

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:

COMPUTER AIDED DESIGN Page 114


2D Thermal Problem - Composite Wall

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 „2D CONDUCTION 32‟&‟
CONVECTION 34‟type .then click on Add ….
o Then click to „OK‟.

3. Define Geometric Properties:


We now need to specify geometric properties for our elements:
o In the Preprocessor menu, select Real Constants > Add/Edit/Delete
o Click Add... and select 'Type 1 LINK1' (actually it is already selected). Click on 'OK'. o Enter the area 1 2.
o Click on 'OK'.
o 'Set 1' now appears in the dialog box. Click on 'Close' in the 'Real Constants' window.

4. Element Material Properties :

You then need to specify material properties:


o In the 'Preprocessor' menu select Material Props > Material Models
o Double click on Thermal > conductivity > Isotropic
o We are going to give the properties of Solid.
o Set these properties and click on 'OK'. Enter the value of bulk modulus as 0.08 Click
'NEW MODEL' on the window to continue for new material. For new material the
value of bulk modulus will be0.0074 and for third material it is 0.72
o Again double click on Thermal>convection
o Enter value of coffieicent of convection as 40
o Close the "Define Material Model Behavior" by clicking on the 'X' box in the upper
right hand corner (or by exit).

5. Element modeling:

o From the 'ANSYS Main Menu' select:


Preprocessor > Modeling > Create > Nodes

COMPUTER AIDED DESIGN Page 115


2D Thermal Problem - Composite Wall

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)

o In the main menu select:Preprocessor>Modelling>Create>Lines>Auto no>Thru


nodes.The following will 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 Coord' window and minimize
the 'Lines' menu and the 'Create' menu. Your ANSYS Graphics window should look
similar to the following figure.

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℃)

COMPUTER AIDED DESIGN Page 116


2D Thermal Problem - Composite Wall

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

 the 'Element Table' menu, select 'List Elem Table'


 From the 'List Element Table Data' window which appears ensure 'SAXL' is From highlighted
 Click 'OK'

COMPUTER AIDED DESIGN Page 117


2D Thermal Problem - Composite Wall

NODAL SOLUTION PER NODE

NODE TEMPERATURE
1 200
2 157.5
3 115
4 72.5
5 30

MAXIMUM ABSOLUTE VALUES


NODE 1
VALUE 200

COMPUTER AIDED DESIGN Page 118


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO:15 DATE:___/___/______

Aim:-Ansys problem no.:-4.


PROBLEM STATEMENT:

Determine the temperature distribution inside the chimney whose dimensions are given below?

PREPROCESSING: DEFINING THE PROBLEM

1. Give the Simplified Version a Title (such as 'Bridge Truss


Tutorial'). In the Utility menu bar select File > Change Title:
Enter the title and click 'OK'. This title will appear in the bottom left corner of the 'Graphics'
Window once you begin. Note: to get the title to appear immediately, select Utility Menu >
Plot > Replot

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.

COMPUTER AIDED DESIGN Page 119


3D Thermal Problem - Chimney

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‟.

3. Define Geometric Properties:


We now need to specify geometric properties for our elements:
o In the Preprocessor menu, select Real Constants > Add/Edit/Delete
o Click Add... and select 'Type 1 LINK1' (actually it is already selected). Click on
'OK'. o Enter the thickness (1mm):
o Click on 'OK'.
o 'Set 1' now appears in the dialog box. Click on 'Close' in the 'Real Constants' window.

4. Element Material Properties:


You then need to specify material properties:
o In the 'Preprocessor' menu select Material Props > Material
Models o Double click on Thermal > conductivity > Isotropic
o We are going to give the properties of Solid.
o Set these properties and click on 'OK'. Note: You may obtain the note 'PRXY will be
set to 0.01' and Poisson‟s ratio and is not required for this element type. Click 'NEW
MODEL' on the window to continue for new material. For new material the value of
PRXY will be0.0057. Close the "Define Material Model Behavior" by clicking on the
'X' box in the upper right hand corner (or by exit).

5. Element modeling:

o From the 'ANSYS Main Menu' select:


Preprocessor > Modeling > Create > Area> Rectangle >By dimension
o Coordinate values :

-150 150

-150 150

o It will create a square of size 300*300.


o Then again select „By dimension’ and give the values:

COMPUTER AIDED DESIGN Page 120


3D Thermal Problem - Chimney

-60 60

-60 60

o Then it will again create a square of 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...

COMPUTER AIDED DESIGN Page 121


3D Thermal Problem - Chimney

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‟

COMPUTER AIDED DESIGN Page 122


3D Thermal Problem - Chimney

o VECTOR PLOT→THERMAL GRID

COMPUTER AIDED DESIGN Page 123


3D Thermal Problem - Chimney

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

COMPUTER AIDED DESIGN Page 124


GANPAT UNIVERSITY
DEPARTMENT OF MECHANICAL ENGINEERING
U V PATEL COLLEGE OF ENGINEERING
COMPUTER AIDED DESIGN
PRACTICAL NO: 16 DATE:___/___/______

Aim:-Ansys problem no.5:-


PROBLEM STATEMENT:

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?

PREPROCESSING: DEFINING THE PROBLEM

1. Give the Simplified Version a Title (such as 'Plate Problem'). In


the Utility menu bar select File > Change Title:
Enter the title and click 'OK'. This title will appear in the bottom left corner of the 'Graphics'
Window once you begin. Note: to get the title to appear immediately, select Utility Menu >
Plot > Replot

COMPUTER AIDED DESIGN Page 125


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:
IN THE MENU,SELECT PREPROCESSOR PREFENCES > STRUCTURE

o In the Preprocessor menu, select Element type>Add/Edit/Delete.

o Click Add... and select 'PALNE 183' then click on Add ….

3. Element Material Properties :


o GO TO Material properties>Structural>Linear>isotropic

Enter the value of: Ex=2e5

Prxy=0.3

4. Element Modeling:

o Modelling>creat>area>rectangle , select BY 2 CORNER

Enter value : width =200, Height=100

o Modelling>creat>area>solid circle >

o Operate>Booleans >subtract>area
o Select Rectangle plate then APPLY, select CIRCLE then APLLY>OK

COMPUTER AIDED DESIGN Page 126


5. MESH SIZE:

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:

Go to Load >define load >apply load> structure >displacement>on lines

o Select line and give ALL DOF=0,


o Displacement Value=0,then Apply> OK
o Pressure > online > select line >Apply > Enter value : -1

COMPUTER AIDED DESIGN Page 127


7. Solution Phase :

o solution >solve>current LS >OK

8. General POSTPROCESSOR:

o General Postproc >plot result >deform shape > def+Undef shape:

COMPUTER AIDED DESIGN Page 128


o General Postproc>plot results>contour Plot>Nodal solu.>stress > X-Comp Stress:

COMPUTER AIDED DESIGN Page 129


o General Postproc>plot results>contour Plot>Nodal solu.>stress> Von mises stress

COMPUTER AIDED DESIGN Page 130


COMPUTER AIDED DESIGN Page 131

Potrebbero piacerti anche