CAD/CAM Principles and
Applications
Ch 3 Computer Graphics
CAD/CAM Principles and 1
Applications by P N Rao, 2nd Ed
Objectives
• Convert vector straight lines to raster images to be displayed on
a raster terminal utilizing the pixel information
• Understand the problems associated with displaying vectorial
information on a raster terminal
• Various types of coordinate systems used in displaying CAD
information
• The data requirements of a graphic image and the database
storage methods used
• Different types of geometric transformations used during CAD
geometry generation and display and their evaluation
• Mathematics required to display a 3D image on the 2D screen of
the display device
• Understand the problems associated with the display of graphic
images in the display screen such as clipping and hidden line
elimination
CAD/CAM Principles and 2
Applications by P N Rao, 2nd Ed
3.1 Raster Scan Graphics
• DDA or Digital Differential Analyser is
one of the first algorithms developed for
rasterising the vectorial information. The
equation of a straight line is given by
• Y =m X + C
CAD/CAM Principles and 3
Applications by P N Rao, 2nd Ed
Fig. 3.1 A straight line drawing
Y
y2
y1
X
x1
x2
CAD/CAM Principles and 4
Applications by P N Rao, 2nd Ed
Fig. 3.2 Flow chart for Calculate dx = x2 - x1
dy = y2 - y1
line drawing calculation
procedure
If |dx| > |dy| Yes St = |dx|
No
ST = |dy|
dx = dx / ST
dy = dy / ST
X = xi
Y = yi
Set pixel at X, Y
X = X + dx
Y = Y + dy
End of Loop?
No
Yes
STOP
CAD/CAM Principles and 5
Applications by P N Rao, 2nd Ed
3.1.2 Bresenham's Algorithm
• Bresenham's method is an
improvement over DDA since it
completely eliminates the floating-point
arithmetic except for the initial
computations.
• All other computations are fully integer
arithmetic thus is more efficient for
raster conversion
CAD/CAM Principles and 6
Applications by P N Rao, 2nd Ed
Fig. 3-3 Line drawing using Bresenham
algorithm
Y
i+1
y d2
d1
i
i i+1
X
CAD/CAM Principles and 7
Applications by P N Rao, 2nd Ed
Calculate dx = x2 - x1
dy = y2 - y1
Fig. 3.4 Flow chart for
C1 = 2 dy
C2 = 2 (dy - dx)
line drawing calculation x = x1
y = y1
using Bresenham
p1 = 2 dy - dx
Put a pixel at (x1, y1)
procedure
x=x+1
P(i+1) = Pi + C2
If Pi < 0 No
Y(i+1) = y(i) + 1
Yes
P(i+1) = P(i) + C1
y(i+1) = y(i)
No End of loop?
Yes
STOP
CAD/CAM Principles and 8
Applications by P N Rao, 2nd Ed
3.1.3 Antialiasing lines
CAD/CAM Principles and 9
Applications by P N Rao, 2nd Ed
Fig. 3.5 The staircase effect of pixels when
drawing inclined lines
CAD/CAM Principles and 10
Applications by P N Rao, 2nd Ed
Fig. 3.6 The staircase effect of pixels when drawing
inclined lines decreases with increased resolution
CAD/CAM Principles and 11
Applications by P N Rao, 2nd Ed
Fig. 3.7 Antialiasing of pixels proportional to
the portion of pixel occupied by the line
8
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8
CAD/CAM Principles and 12
Applications by P N Rao, 2nd Ed
Fig. 3.8 Unequal number of lines displayed
with the same number of pixels
CAD/CAM Principles and 13
Applications by P N Rao, 2nd Ed
3.2 Co-ordinate systems
CAD/CAM Principles and 14
Applications by P N Rao, 2nd Ed
Fig. 3.9 A typical component to be modelled
50
90
60
40
120
40
20
30
15
0
CAD/CAM Principles and 15
Applications by P N Rao, 2nd Ed
World Co-ordinate System
• This refers to the actual co-ordinate
system used as master for the
component.
• Some times it may also be called as
model co-ordinate system.
CAD/CAM Principles and 16
Applications by P N Rao, 2nd Ed
Fig. 3.10 A typical component with its
associated WCS
Z
Y
CAD/CAM Principles and 17
Applications by P N Rao, 2nd Ed
User Co-ordinate System
• However, sometimes it becomes difficult
to define certain geometries if they are
to be defined from the WCS. In such
cases alternate co-ordinate systems
can be defined relative to the WCS.
These co-ordinate systems are termed
as user co-ordinate systems (UCS) or
working co-ordinate systems.
CAD/CAM Principles and 18
Applications by P N Rao, 2nd Ed
Fig. 3.11 A typical component with its
associated UCS
Z'
Y'
Z
Y
X'
CAD/CAM Principles and 19
Applications by P N Rao, 2nd Ed
Display Co-ordinates
• This refers to the actual co-ordinates to
be used for displaying the image on the
screen.
CAD/CAM Principles and 20
Applications by P N Rao, 2nd Ed
Fig. 3.12 A typical component with its various
view positions
TOP
Z
Y
FRONT RIGHT SIDE
CAD/CAM Principles and 21
Applications by P N Rao, 2nd Ed
Fig. 3.13 Various views generated from the
model shown in Fig 3.12
60
20
90
X
TOP
Z
50 60
120
20
40
Z Z
30
X Y
150
Y X
FRONT RIGHT SIDE
CAD/CAM Principles and 22
Applications by P N Rao, 2nd Ed
3.3 Database Structures for
Graphic Modelling
CAD/CAM Principles and 23
Applications by P N Rao, 2nd Ed
3.3 Database Structures for
Graphic Modelling
• Organisational data • Technological data
• Identification number, • Geometry,
• Drawing number, • Dimensions,
• Design origin and status • Tolerances,
of changes, • Surface finishes,
• Current status, • Material specifications
• Designer name, or reference,
• Date of design, • Manufacturing
• Scale, procedures,
• Type of projections, • Inspection procedures.
• Company.
CAD/CAM Principles and 24
Applications by P N Rao, 2nd Ed
Fig. 3.14 Data structure for geometric models
SOLID
EDGE
VERTEX SURFACE
VERTEX
SURFACE
CAD/CAM Principles and 25
Applications by P N Rao, 2nd Ed
Fig. 3.15 Complete data structure for
geometric models of products
Product
Assembly
Dimensions Attributes
Single parts
Solid body
Faces
Edges
Vertices
CAD/CAM Principles and 26
Applications by P N Rao, 2nd Ed
Fig. 3.16 Relational data structure for
geometric models
solid body Face list Edges Vertices
X Y Z
CAD/CAM Principles and 27
Applications by P N Rao, 2nd Ed
3.4 Transformation of
Geometry
• Translation
• Scaling
• Reflection or Mirror
• Rotation
CAD/CAM Principles and 28
Applications by P N Rao, 2nd Ed
Fig. 3-17 Some of the possible geometric
transformations
Y Y
dY
dX
X X
Translation Scaling
Y
Y
25
30
X
°
25
X
Rotation
Reflection
CAD/CAM Principles and 29
Applications by P N Rao, 2nd Ed
Fig. 3.18 Translation of geometry
Y'
Y P*
Z'
P X'
Z
P
Y
X
X
CAD/CAM Principles and 30
Applications by P N Rao, 2nd Ed
Fig. 3.19 Translation of geometry in 2D
Y
Y' P*
dY
P
X'
dX
X
CAD/CAM Principles and 31
Applications by P N Rao, 2nd Ed
Fig. 3.20 Scaling of geometry in 2D
P*
P
sY
Y
X
X
sX
CAD/CAM Principles and 32
Applications by P N Rao, 2nd Ed
Fig. 3.21 Reflection of geometry in 2D
Y Y
28 28
25
X -X X
25
-X X
-Y
CAD/CAM Principles and 33
Applications by P N Rao, 2nd Ed
Fig. 3.22 Example for reflection transformation
Y
y
X
-y
P*
CAD/CAM Principles and 34
Applications by P N Rao, 2nd Ed
Fig. 3-23 Example for rotation transformation
P*
P
θ
y*
r
y
α
x* X
O x
CAD/CAM Principles and 35
Applications by P N Rao, 2nd Ed
Fig. 3.24 Example
13.66 Y
10
8.66
30°
5
3.66
X
5 8.66
CAD/CAM Principles and 36
Applications by P N Rao, 2nd Ed
3.4.5 Concatenation of
transformations
• [P*] = [Tn] [Tn-1] [Tn-2] .. [T3] [T2] [T1]
CAD/CAM Principles and 37
Applications by P N Rao, 2nd Ed
3.4.6 Homogeneous
Representation
x * 1 0 dX x
[P *] = y * = 0 1 dY y
1 0 0 1 1
CAD/CAM Principles and 38
Applications by P N Rao, 2nd Ed
Rotation about an arbitrary
point
• Translate the point P to O, the origin of
the axes system.
• Rotate the object by the given angle
• Translate the point back to its original
position.
CAD/CAM Principles and 39
Applications by P N Rao, 2nd Ed
Fig. 3.25 Rotation about an arbitrary point
P*
r P
θ
r
A
dY
X
O dX
CAD/CAM Principles and 40
Applications by P N Rao, 2nd Ed
Reflection about an arbitrary
line
• Translate the mirror line along the Y-axis
such that the line passes through the origin,
O
• Rotate the mirror line such that it coincides
with the X-axis.
• Mirror the object through the X-axis.
• Rotate the mirror line back to the original
angle with X-axis.
• Translate the mirror line along the Y-axis
back to the original position.
CAD/CAM Principles and 41
Applications by P N Rao, 2nd Ed
Fig. 3.26 Example for reflection transformation
about an arbitrary line
P*
P
θ
C
X
O
CAD/CAM Principles and 42
Applications by P N Rao, 2nd Ed
3.5 3D Transformations
x * 1 0 0 dX x
y * 0 1 0 dY y
=
z * 0 0 1 dZ z
1 0 0 0 1 1
CAD/CAM Principles and 43
Applications by P N Rao, 2nd Ed
3.6 Mathematics of Projection
CAD/CAM Principles and 44
Applications by P N Rao, 2nd Ed
Fig. 3.27 The principle of projection
Projector
Drawing Object
Projecting plane
CAD/CAM Principles and 45
Applications by P N Rao, 2nd Ed
Fig. 3.28 An object enclosed in a cube to
obtain various parallel projections
B
E
C
Z
Y
A
X
D
CAD/CAM Principles and 46
Applications by P N Rao, 2nd Ed
Fig. 3.29 Orthographic projection of an object
Y
B
E
X
C TOP VIEW
Z Z
Y Z
D A C E
A Y
X X
D LEFT SIDE VIEW FRONT VIEW RIGHT SIDE VIEW REAR VIEW
BOTTOM VIEW
CAD/CAM Principles and 47
Applications by P N Rao, 2nd Ed
3.7 Clipping
CAD/CAM Principles and 48
Applications by P N Rao, 2nd Ed
Fig. 3.30 Clipping of geometry for display
T
L
R
CAD/CAM Principles and 49
Applications by P N Rao, 2nd Ed
Fig. 3.31 The 4-digit coding of the line end
points for clipping
1001 1000 1010
0001 0000 0010
0101 0100 0110
CAD/CAM Principles and 50
Applications by P N Rao, 2nd Ed
Fig. 3.32 Identical line clipping of two different
geometries
CAD/CAM Principles and 51
Applications by P N Rao, 2nd Ed
Fig. 3.33 Clipping produced for different
geometries by polygon clipping
CAD/CAM Principles and 52
Applications by P N Rao, 2nd Ed
Fig. 3.34 Back-face removal using the face
normal and projecting ray
Y
P
N
X
CAD/CAM Principles and 53
Applications by P N Rao, 2nd Ed
Summary
• In order to display the graphical information, which is vectorial in
nature, it is necessary to convert it into raster format.
• For converting lines into raster format, DDA algorithm is
simplest while Bresenham’s algorithm reduces the computations
into integer format thereby making it a faster alternative.
• It is necessary to modify the pixel information for display to get
more realistic visual experience.
• Depending upon the type of graphic display used, it is
necessary to be familiar with a number of different coordinate
systems to facilitate the graphic construction as well as display.
• In addition to the actual graphic information, a large amount of
additional data such as organizational and technological data is
stored with the product data.
CAD/CAM Principles and 54
Applications by P N Rao, 2nd Ed
Summary
• Geometric transformations can be handled conveniently using
matrix algebra. For this purpose it is necessary to use
homogenous representation of vertex data.
• Various transformations that are quite useful are translation,
rotation, scale and reflection. The 2D transformation methods
can be easily extended into 3D.
• The 3D geometry data needs to be converted into 2D by
adopting a suitable projection system such as orthographic,
isometric or perspective projection.
• Since only part of the geometric model will be displayed most of
the time, it is necessary to clip the information outside the
display window.
• Also it is necessary some times to remove the hidden lines to
make the display easier to understand. For this purpose back
face removal and depth buffer (Z) are used.
CAD/CAM Principles and 55
Applications by P N Rao, 2nd Ed