CAD CAM CIM - (Chapter 3. Principles of Computer Graphics)
CAD CAM CIM - (Chapter 3. Principles of Computer Graphics)
PRINCIPLES OF
COMPUTER GRAPHICS !
The display of the drawing or the geometric model of the component in CAD uses the
technology of computer graphics. The techniques of raster technology, scan conversion,
clipping, removal of hidden lines and hidden surfaces, color, shading and texture, necessary
to understand the complex process of computer graphics are briefly dealt in this chapter.
3.1 INTRODUCTION
Traditionally drawings are prepared on plane drawing sheets. This has several limitations.
The sketches have to be made only in two dimensions. Though the depth can be represented
by pictorial projections like isometric and perspective projections, the projections have to
be necessarily reduced to two dimensions.
Use of computer graphics has opened up tremendous possibilities for the designer.
Some of them are listed below:
• The object is represented by its geometric model in three dimensions (X, Y and Z).
• The mathematical representation reduces creation of views like orthographic,
isometric, axonometric or perspective projections into simple viewing
transformations.
• Though the size of the screen is limited, there is no need to scale the drawings.
• Drawings can be made very accurate.
• The geometric models can be represented in color and can be viewed from any
angle.
Copyright © 2008. New Age International Ltd. All rights reserved.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
42 CAD/CAM/CIM
Modern computer graphics displays are simple in construction. They consist of basically
three components.
i. Monitor
ii. Digital Memory or Frame Buffer
iii. Display Controller
Most of the computer graphics displays use raster CRT which is a matrix of discrete
cells each of which can be made bright. A graphic entity like line or circle is represented as
a series of “points or dots” on the screen. Therefore, it is called as a point plotting device.
The video display screen is divided into very small rectangular elements called a picture
element or pixel. This happens to be the smallest addressable screen element. Graphic
images are formed by setting suitable intensity and color to the pixels which compose the
image. Depending upon the resolution screens may have varying number of pixels. For
example, an SVGA monitor with a resolution of 1024 x 768 will have 1024 pixels in every
row (X - direction) and 768 pixels in every column (Y-direction). Monitors of larger size
will have resolution of 1024 x 1024 or more. A raster scan system displays the image on a
CRT in a certain fixed sequence.
The refresh rate is the number of complete images or frames scanned per second. In
the case of interlaced refresh cycle odd numbered raster lines are refreshed during 1/60th
of a second. Even numbered raster lines are refreshed during the next 1/60th of a second.
In non-interlaced displays, all lines are refreshed in 1/60th of a second. The quality of non-
interlaced display is hence, superior. These systems, however, require expensive frame
buffer memory and display controller.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 43
CIRCLE LINE
ARC
LINE
Chapter 3
LINE
LINE
end points of the line segment are known, there are several schemes for selecting the pixels
between the end pixels. One method of generating a line segment is a symmetrical digital
differential analyzer (DDA).
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
44 CAD/CAM/CIM
In the real world of limited precision displays, addressable pixels only must be
generated. This can be done by rounding to the next integer after each incremental step.
After rounding, a pixel is displayed at the resultant X and Y locations. An alternative to
rounding is the use of arithmetic overflow. X and Y are kept in registers that have integer
and fractional parts. The incrementing values which are less than unity are repeatedly
added to the fractional part and whenever the result overflows the corresponding integer
part is incremented. The integer parts of X and Y are used to plot the line. This would
normally have the effect of truncating. The DDA is therefore initialized by adding 0.5 in
each of the fractional parts to achieve true rounding.
The symmetrical DDA generates reasonably accurate lines since a displayed pixel is
never away from a true line by half the pixel unit. A Pascal procedure for a simple DDA is
given below :
Procedure DDA (X1, Y1, X2, Y2 : integer) ;
length : var ;
i : integer;
X, Y, X-incr, Y-incr : real ;
begin
length : = abs (X2– X1) ;
if abs (Y2–Y1) < length then length: = abs (Y2–Y1);
X - incr : = (X2 – X1) /length ;
Y - incr : = (Y2 – Y1) /length ;
X : = X1 + 0.5 ; Y = Y1 + 0.5 ;
for i : = 1 to length do
begin
plot (trunc (X) ; trunc(Y) ;
X : = X + X - incr ;
Y : = Y + Y - incr ;
end;
Copyright © 2008. New Age International Ltd. All rights reserved.
end.
3.4.2 EXAMPLE
To draw a straight line from connecting two points (2, 7) and (15, 10)
X1 = 2, X2 = 15 abs(X2 – X1) = 13
Y1 = 7, Y2 = 10 abs(Y2 – Y1) = 3
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 45
Length = 13
X2–X1 13
X incr = = =1
Length 13
Y2–Y1 3
Y incr = = = 0.23
Chapter 3
Length 13
Initial values of X and Y are
X = 2.5 Y = 7.5
The X and Y are tabulated in Table 3.1 and Fig. 3.2 shows a plot of the line.
10
9
8
Copyright © 2008. New Age International Ltd. All rights reserved.
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
46 CAD/CAM/CIM
It can be noted that lines drawn on a raster display may have a jagged or staircase
appearance unless the lines are vertical or horizontal. This is because the points that are
plotted must be pixel grid points and many of these may not lie on the actual line.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 47
end ;
Chapter 3
begin
writln(enter xc,yc,radius);
readln(xc);
readln(yc);
readln(radius);
clrscr;
graphcolormode;
palette(3);
dcircle(xc,yc,radius)
end of a circle.
determined by examining the distance (error) between the actual line location and the
nearest grid location. Only the sign of this error needs be examined.
Consider the line of slope m = 0.4 and passing through (0,0) in Fig 3.3 (a). The error
team e is initialized to –1/2. The next raster point can be determined by adding the slope
(m) to the error term.
i.e. e = e+m
e = – 0.5 + 0.4 = – 0.1
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
48 CAD/CAM/CIM
Since e is negative, the line will pass below the middle of the pixel. Hence the pixel is
at the same horizontal level i.e., (0,1). For the next location X is incremented to 2. Error e =
-0.1 + 0.4 = 0.3. Since e is positive the line passes above the middle of the raster line. Hence
the location of pixel is (2,1). Before examining the next pixel location the error term has to
be re-initialized as its value is positive. Re-initialization is done by subtracting one from
the current e value. Hence e = 0.3 - 1 = -0.7. Adding the slope 0.4 we get e = -0.3. Table 3.2
shows the computed values and the location of pixels. A plot of the pixel location is shown
in Fig. 3.3 (b).
Table 3.2 Calculation of Pixel Position
X Error Y Rem arks
0 – 0.5 0 initial pixel
1 – 0.5 + 0 .4 = – 0 .1 0
2 – 0.1 + 0 .4 = 0 .3 1
0.3 – 1 = – 0 .7 rein itialize the erro r b y
3 – 0.7 + 0 .4 = – 0 .3 1 sub tra cting on e
4 – 0.3 + 0 .4 = 0 .1 2
0.1 – = – 0 .9
– 0.9 + 0 .4 = – 0 .5 2
5 – 0.5 + 0 .4 = – 0 .1 2
6
L2
0,1 1,1
L1
(Slope <0.5) 0
0 1 2 3
0,0 1,0
Fig. 3.3 (a) Location of Pixels Using Fig. 3.3 (b) Pixels for Line of
Bresenham Algorithm Slope, m = 0.4
The speed of the Bresenham’s algorithm can be increased by using integer arithmetic
Copyright © 2008. New Age International Ltd. All rights reserved.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 49
Chapter 3
x starts at 0
y starts at 0
plot a pixel at plotx, ploty
increment x using ix
increment y using iy
plot is false
if x is greater than inc
plot is true
decrement x using inc
increment plotx if dx is positive
decrement plotx id dx is negative
if y is greater than inc
plot is true
decrement y using inc
increment ploty if dy is positive
decrement ploty if dy is negative
if plot is true, plot a pixel at plotx, ploty
increment i.
{
draw line (100, 100, 50, 50) ;
}
void draw line (int x1, int y1, int x2 m int y2)
{
int dx, dy, inc, ix, iy, x, y, plot, plotx, ploty, i ;
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
50 CAD/CAM/CIM
int gd, gm ;
gd = DETECT ;
initgraph (&gd, &gm, “ “) ;
dx = x1 – x2 ;
dy = y1 – y2 ;
ix = abs (dx) ;
iy = abs (dy) ;
inc = max (ix, iy) ;
x=y=0;
plot x = x1 ;
plot y = y1 ;
for (i = 0 ; i <inc ; i ++)
{
x + = ix ;
y + iy ;
plot = 0
if (x > inc)
{
plot = 1 ;
x – = inc ;
if (dx < 0)
plot x – = 1 ;
else
plotx + = 1 ;
}
if (y > inc)
{
plot = 1 ;
y – = inc ;
Copyright © 2008. New Age International Ltd. All rights reserved.
if (dy)
ploty – = 1 ;
else
ploty + = 1 ;
}
if (plot)
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 51
Chapter 3
3.5.1 BRESENHAM’S CIRCLE ALGORITHM
An efficient algorithm for generating a circle has been developed by J. Bresenham. Values
of a circle centred at the origin are computed in the sector X = 0 to X = R /2 where R is the
radius of the circle. The symmetry of the circle is used to obtain the pixels corresponding
to other sectors.
Bresenham’s circle algorithm can be explained as follows:
Consider an origin-centred circle. The algorithm begins at X = 0 and Y = R. In the first
quadrant of the circle, Y is a monotonically decreasing function of X. Referring to Fig. 3.4,
(Xi, Yi) is a point on the circle. For clockwise generation of the circle there are only three
possible selections of the next pixel, which represents the circle. These positions are also
shown in Fig. 3.4. The algorithm is designed to choose the pixel which minimizes the
square of the distance between one of these pixels and the true circle, i.e., the minimum of
H = [ (Xi + 1) 2 + (Yi)2 – R 2]
V = [ (Xi ) 2 + ( Yi – 1) 2 – R 2 ]
D = [ ( Xi + 1) 2 + ( Yi – 1 ) 2 – R 2 ]
Xi, Yi Xi+1, Yi
H
V D
A flow chart to obtain the pixel values for representing a circle is given in Fig. 3.5. It is
sufficient to obtain the pixel values for 1/8th of a circle, the remaining obtained by symmetry.
A program which implements Bresenham’s algorithm follows.
include <stdio.h>
include <graphics.h>
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
52 CAD/CAM/CIM
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 53
y end = (y + 1) * ratio
for (x out = x start ; x out < x end ; ++ x out)
{
put pixel (x out + xc, y + yc, 1 ) ;
put pixel (x out + xc, –y + yc, 1) ;
Chapter 3
put pixel (-x out + xc, –y + yc, 1) ;
put pixel (-x out + xc, y + yc, 1) ;
}
(y out = y start ; y out < y end ; ++y out)
{
put pixel (y out + xc, x + yc, 1 ) ;
put pixel (y out + xc, –x + yc, 1) ;
put pixel (-y out + xc, –x + yc, 2) ;
put pixel (-y out + xc, x + yc, 1) ;
}
Start
X =0,Y = R
= 2(1 -R )
Lim it=0
P lot(X,Y )
Ye s Ye s E nd
Y <= Lim it
No
<0 Ye s
No
=2 +2Y – 1
Ye s
<0
Ye s No
No =< 0
= 2 – 2X – 1
X =X +1
Y =Y – 1
Copyright © 2008. New Age International Ltd. All rights reserved.
–0 = + 2X – 2Y +2
X =X +1
= + 2X+ 1
Y =Y – 1
= –2Y + 1
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
54 CAD/CAM/CIM
i X Y Plot
-18 0 10 0, 10
-15 -17 1 10 1, 10
-10 -11 2 10 2, 10
- 3 -1 3 10 3, 10
-14 13 4 9 4, 9
- 3 -11 5 9 5, 9
- 3 3 6 8 6, 8
- 1 5 7 7 7, 7
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 55
9
8
Y 7
6
5
4
3
Chapter 3
2
1
0
0 1 2 3 4 5 6 7 8 9
X
3.6 ELLIPSE
The ellipse is a variation of a circle. Stretching a circle in one direction produces an ellipse.
The polar equations for an ellipse with centre at XC, YC are:
X = XC + a * cos (θ)
Y = YC + b * sin (θ)
The above equations can be used to plot an ellipse in a manner similar to that of
generating a circle.
are called default co-ordinates. A user co-ordinate system is one in which the designer can
specify his own co-ordinates for a specific design application. These screen independent co-
ordinates can have large or small numeric range, or even negative values, so that the model
can be represented in a natural way. It may, however, happen that the picture is too crowded
with several features to be viewed clearly on the display screen. Therefore, the designer may
want to view only a portion of the image, enclosed in a rectangular region called a window.
Different parts of the drawing can thus be selected for viewing by placing the windows. Portions
inside the window can be enlarged, reduced or edited depending upon the requirements.
Figure 3.7 shows the use of windowing to enlarge the picture.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
56 CAD/CAM/CIM
WIND OW
OR IGIN AL
D RAW IN G
1 3 0 ,1 0 0 View Port 2
View Port 1
Fig. 3.8 View Port Fig. 3.9 Use of Multiple View Ports
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 57
3.10.1 SCALING
Changing the dimensions of window and view port, it is possible to alter the size of
drawings. This technique is not satisfactory in all cases. A drawing can be made bigger by
increasing the distance between the points of the drawing. In general, this can be done by
multiplying the co-ordinates of the drawing by an enlargement or reduction factor called
Chapter 3
scaling factor, and the operation is called scaling. Referring to Fig. 3.10, P1 (30, 20) represents
a point in the XY plane. In matrix form, P1 can be represented as:
P1 = [30, 20]
If we multiply this by a matrix
2 0
0 3
we get a new point P2 (60, 60). The matrix is called the scaling matrix. In general, the
scaling matrix can be represented as:
S x 0
0 S y
where Sx and Sy are scaling factors in X and Y directions.
10
9
8
Y 7
P2 (6,6)
6
5
4
3
P (3,2)
2 1
1
0
Copyright © 2008. New Age International Ltd. All rights reserved.
0 1 2 3 4 5 6 7 8 9
X
An example of scaling in the case of a triangle is shown in Fig. 3.11. Fig. 3.11 (a) shows
the original picture before scaling. Fig. 3.11 (b) shows the triangle after the co-ordinates
are multiplied by the scaling matrix.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
58 CAD/CAM/CIM
10 10 C 1 (6,1 0)
9 9
8 8
7 7
6 6
5 C (3,5) 5
4 4
B 1 (2,4)
3 3
2 2
1 B (1,2) 1
A (4,0) A1 (8,0)
0 0
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
3.10.2 TRANSLATION
Moving drawing or model across the screen is called translation. This is accomplished by
adding to the co-ordinates of each corner point the distance through which the drawing is
to be moved (translated). Fig. 3.12 shows a rectangle (Fig. 3.12 (a)) being moved to a new
position (Fig. 3.12 (b)) by adding 40 units to X co-ordinate values and 30 units to Y co-
ordinate values. In general, in order to translate drawing by (TX , TY ) every point X, Y will
be replaced by a point X1 , Y1 where
X1 = X + TX
Y = Y + TY
10 10
9 9 (5 ,8 ) (8 ,8 )
8 8
7 7
Y 6 Y 6
1 ,5 ) (4 ,5 )
5 5
4 4
(5 ,4 ) (8 ,4 )
3 3
2 2
1 1
(1 ,1 ) (4 ,1 )
0 0
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
X X
Copyright © 2008. New Age International Ltd. All rights reserved.
Fig. 3.12(a) Original Rectangle Fig. 3.12 (b) Rectangle After Translation
3.10.3 ROTATION
Another useful transformation is the rotation of a drawing about a pivot point. Consider
Fig. 3.13. Point P1 (40, 20) can be seen being rotated about the origin through an angle, θ =
45°, in the anti-clockwise direction to position P2. The co-ordinates of P2 can be obtained
by multiplying the co-ordinates of P1 by the matrix:
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 59
Cosθ Sin θ
–Sin θ Cosθ
The new co-ordinates are
Chapter 3
= [40
0.707 0.707
= [40 20] –0.707 0.707
= [14.14 42.42]
For rotating drawings in anticlockwise direction positive angles are used.
50
P2 (14.14, 42.42)
40
Y
30
45
20 ° P1 (4,2)
10
0 10 20 30 40 50
X
3.10.4 SHEARING
A shearing transformation produces distortion of an object or an entire image. There are
Copyright © 2008. New Age International Ltd. All rights reserved.
two types of shears: X-shear and Y-shear. A Y-shear transforms the point (X, Y) to the point
(X1, Y1) by a factor Sh1, where
X1 = X
Y1 = Sh1. X + Y
Fig. 3.14 shows Y shear applied to a drawing.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
60 CAD/CAM/CIM
C1
D1
10 AFTER Y-SHEAR
9
8
Y E1 D ORIGINAL
7 B1
PART
6
5
E C
4
3 A1
2
1
0 A B
0 1 2 3 4 5 6 7 8 9
X
10
AFTER X-SHEAR
9
8
Y D D1 ORIGINAL
7
PART
6
5
E1 C1
E C
4
3
2
1 A1
A B B1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13
X
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 61
by a 3 X 3 matrix, another homogeneous row vector is obtained [X1 Y1 1]. The first two
terms in this vector are the co-ordinate pair which is the transform of (X, Y). This three
dimensional representation of a two dimensional plane is called homogeneous co-
ordinates and the transformation using the homogeneous co-ordinates is called
homogeneous transformation. The matrix representations of the four basic
transformations are given below.
Chapter 3
Translation:
1 0 0
0 1 0
[X1 Y1 1] = [ X Y 1]
Tx Ty 1
Rotation
Cosθ Sinθ 0
−Sinθ Cosθ 0
[ X1 Y1 1] = [ X Y 1]
0 0 1
Scaling
Sx 0 0
0 Sy 0
[ X1 Y1 1] = [ X Y 1]
0 0 1
X-shear
1 0 0
Sh 0 0
[ X1 Y1 1] = [ X Y 1] x
0 0 1
Y-shear
1 Shy 0
0 1 0
[ X1 Y1 1] = [ X Y 1]
0 0 1
Copyright © 2008. New Age International Ltd. All rights reserved.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
62 CAD/CAM/CIM
Cosθ Sinθ 0
−Sinθ Cosθ 0
0 0 1
and
1 0 0
0 1 0
Tx Ty 1
The same effect can be achieved using the concatenated (combined) matrix given below:
1 0 0 Cosθ Sinθ 0
0 1 0 −Sinθ Cosθ 0
[X1 Y1 1] = [X Y 1] X
−Tx −Ty 1 0 0 1
1 0 0
0 1 0
Tx Ty 1
Since matrix operations are not commutative, care must be taken to preserve the order
in which they are performed while combining the matrices.
10 10
9 9
AB A 1B A B AB
8 8 1 1 2 3
7 7 B3
Y6 Y6
Copyright © 2008. New Age International Ltd. All rights reserved.
3
B2
5 5
4 4
3 B 3 2 B
2 A 2 A
1
1 1 B
(1,1) 1
0 0A
1
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
X X
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 63
3.13 CLIPPING
Clipping is the process of determining the visible portions of a drawing lying within a
window. In clipping each graphic element of the display is examined to determine whether
or not it is completely inside the window, completely outside the window or crosses a
window boundary. Portions outside the boundary are not drawn. If the element of a drawing
Chapter 3
crosses the boundary the point of inter-section is determined and only portions which lie
inside are drawn. Readers are advised to refer to books on computer graphics for typical
clipping algorithms like Cohen-Sutherland clipping algorithm. Fig. 3.17 shows an example
of clipping.
D R A W IN G
W IN D O W
Sx 0 0 0
0 Sy 0 0
i. Scaling: The scaling matrix in 3-D is:
0 0 Sz 0
0 0 0 1
Copyright © 2008. New Age International Ltd. All rights reserved.
1 0 0 0
0 1 0 0
ii. Translation: The translation matrix is:
0 0 1 0
Tx Ty Tz 1
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
64 CAD/CAM/CIM
Cosθ Sinθ 0 0
−Sinθ Cosθ 0 0
Rotation about Z axis: Rz =
0 0 1 0
0 0 0 1
1 0 0 0
0 Cosφ −Sinφ 0
Similarly Rx =
0 Sinφ Cosφ 0
0 0 0 1
similarly
Cosϕ 0 Sinϕ 0
0 1 0 0
and Ry = −Sinϕ 0 Cosϕ 0
0 0 0 1
3.15 PROJECTIONS
In drawing practice, a 3-dimensional object is represented on a plane paper. Similarly in
computer graphics a 3-dimensional object is viewed on a 2-dimensional display. A
projection is a transformation that performs this conversion. Three types of projections are
commonly used in engineering practice: parallel, perspective and isometric.
B1
A
1
A C
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 65
Chapter 3
E
UR E
I CT AN IMAGE PLANE
P PL
Y P(X ,Y )
1 1 Y
P(X,Y)
C
P0 Z1
Z
Z0
X X
located on the Z-axis. This fact can also be expressed by saying that the optical axis is
aligned with the Z-axis of the co-ordinate system. The image plane is perpendicular to the
optical axis; i.e., in figure 3.19 it is parallel to the xy-plane of the co-ordinate system. This
fact accounts for the simplicity of a central projection.
Let the co-ordinates in the two-dimensional co-ordinate system of the image plane,
which we may call the image co-ordinate system, be denoted by X and Y. Let the distance
of the image plane to the origin of the spatial co-ordinate system be denoted by Z and the
distance of the viewpoint to the origin of the co-ordinate system by Z.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
66 CAD/CAM/CIM
Z0 − Z
Y = Y1
Z0 − Z1
A further simplification can be obtained by setting Z1 = 0. i.e., by moving into the XY
plane of the spatial co-ordinate system. Then we have
Z0 − Z
X = X1
Z0
Z0 − Z
Y = Y1
Z0
For even further simplification, we may move the viewpoint C toward infinity. With Z
0→ ∞, and we have the trivial solution
X = X1 and Y = Y1
This projection is called orthographic. The orthographic projection is a special form of
the parallel projection by which parallel lines of the three-dimensional object are
transformed into parallel lines of its image.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 67
Chapter 3
In this technique the picture is randomly represented in terms of visual attributes like
color, shade and intensity, and geometrical properties like X, Y co-ordinates, slopes and
text, which are ordered in Y. The scan conversion program scans through this information
and calculates the intensity of each pixel on the screen.
Consider Fig. 3.20. The figure consists of four lines (AB, BC, AD and CD). Three scan
lines 1, 2 and 3 are also shown in the figure. The active edge list for this figure is shown in
Table.3.4.
A
1
D
2
Scan line 1 2 3
AD AD AD
AB AB
DC
Copyright © 2008. New Age International Ltd. All rights reserved.
DC BC
Outside edge list DC BC
BC
Thus for scan line 3, all the edges above the scan line are also included in the active list.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
68 CAD/CAM/CIM
1 2 3 4
For the scan line of Fig 3.21, the encoding is shown in Fig. 3.22. For the first four pixels
in the scan line the line intensity is zero. Intensity is one for the next pixel, zero for next two
pixels, and one for the next pixel and so on.
Run length encoding has the advantage of large data compression. Its disadvantage is
that since the run lengths are stored sequentially, addition or deletion of lines is difficult.
0 4 1 1 0 2 1 1 0 1 1 2 0 1 0 1 1 2 0 1
Fig. 3.22 Run Length Encoding of Scan Line Shown in Fig. 3.21
contributes one pixel in a horizontal scan line. Fig. 3.23 shows a shift register
implementation of frame buffer. Shift register frame buffer memory has the
disadvantage of low levels of interactivity.
For better graphics performance the usual practice is to add a graphics processor with
a separate frame buffer memory. The system performance can be improved by this
architecture as it meets the update requirements of the frame buffer.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 69
1 1 1 1 1 1 1 1
1 1 1 0 1 1 1 1
1 1 0 0 0 0 1 1
1 1 0 0 0 0 1 1
1 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
Chapter 3
Fig. 3.23 Shift Register Implementation of Frame Buffer
3.17 RENDERING
Rendering is a general term describing the overall process of representation of a 3-D
object to a shaded 2-D projection on the screen of the computer. This involves a number
of processes:
i. Generation of a data structure for polygon models that will contain the
information required for the shading process.
ii. Applying transformations
iii. Scan converting polygons
iv. Hidden surface removal
v. Shading individual pixels.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
70 CAD/CAM/CIM
will be that of the background. For the scan line considered, from pixel 4 to 8, the color is
that of the polygon and beyond 8 the color is the background again. Several algorithms are
available to create ordered edge lists. These take into consideration the intersection of the
scan line with the vertices of the polygon also.
10
9
8
Y
7 P1
6
5 P2
4
3
2 P4
1 P3
0
0 1 2 3 4 5 6 7 8 9 10
X
5 5
Copyright © 2008. New Age International Ltd. All rights reserved.
1 1
8 8
4 6 4
2 2
7 7
3 3
(a) (b)
Fig. 3.25 Hidden Surface Removal
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 71
There are a number of algorithms available for removal of hidden lines and hidden
surfaces. Table 3.5 gives a list of algorithms for hidden line removal and hidden surface
removal.
Chapter 3
Hidden line removal Hidden surface removal
Floating horizon Blinn-Whitted
Image space Catmull subdivision
List priority Clark
Object space Lane Carpenter
Ray tracing Scan line
Roberts Warnock Image space
List priority
Newell -Newell-Sancha
Schumacher
Object space
Ray tracing
Roberts Algorithm
Scan line Z-buffer
Warnock
Watkins
Weiler Atherton
There are two popular approaches to hidden surface removal. These are scan line based
systems and Z-buffer based systems. Other important approaches are area subdivision
and depth list schemes.
has been applied. For every pixel, (X, Y) values are the pixel co-ordinates and Z value is
the viewing space depth. For each interior polygon point a search is carried out to
determine the minimum Z value. This search is conveniently implemented using a Z-
buffer that holds for a current point (X, Y) the smallest Z value so far encountered. The
Z-buffer algorithm has the advantage of simplicity. It handles scenes of any complexity.
There is also no computation required for depth sort. The storage space required, however
is large. This could be reduced by pre-processing, so that polygons nearest the viewpoint
are processed first.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
72 CAD/CAM/CIM
E
AN
PL
N
S CA
image will have jagged edges and incorrectly rendered fine detail or texture. Objects
smaller than the size of the pixel may be lost while displaying. Ant aliasing is the
technique adopted to solve these problems. One technique is to increase the
sampling rate by increasing the resolution of the raster. Another method is to
calculate the raster at higher resolution and display it at lower resolution by
averaging the pixel and attribute at the lower resolution. Three techniques are
described briefly below.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 73
Chapter 3
This method goes well with Z-buffer technique. However this may cause some blurring.
Another disadvantage of this technique is that it is not a suitable method for dealing with
small objects. Since the memory requirements when used with Z-buffer technique is large,
it is essentially a virtual memory technique.
3.21 REFLECTION
Shading is an important element in 3-D computer graphics, as it gives the necessary realism
Copyright © 2008. New Age International Ltd. All rights reserved.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
74 CAD/CAM/CIM
SCATTERING AND
EMISSION
LIGHT IN ABSORPTION
REFLECTION
(DIFFUSE)
TRANSMISSION
INTERNAL
REFLECTION REFLECTION
(SPECULAR)
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
Principles of Computer Graphics 75
Chapter 3
(a) Diffuse Reflection (b) Specular Reflection
Fig. 3.28 Reflection
3.22 SHADING
In simple polygonal mesh models, the surface is represented by constant shading. To
introduce more realistic shading, incremental shading is necessary. Two commonly used
incremental shading techniques are:
i. Gauraud Shading
ii. Phong Shading
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].
76 CAD/CAM/CIM
QUESTIONS
1. Using the DDA algorithm described in the text, sketch the pixels for the line
drawn from (4,4) to (12, 14).
2. Sketch the pixels for representing a circle with centre at 10, 10 and radius = 5 units.
3. Write a C program to implement Bresenham’s circle algorithm.
4. Differentiate between window and view port.
5. Discuss the window and view port features of the CAD software you use.
6. A rectangle has corner co-ordinates (10,20) (40,20), (40,40), (10,40). This rectangle
is rotated by 30° anticlockwise about (i) origin and (ii) about the point (40,20).
Compute the new co-ordinates in both cases.
7. What is homogeneous transformation?
8. What is concatenated matrix?
Copyright © 2008. New Age International Ltd. All rights reserved.
9. Briefly describe the different techniques used for scan conversion in Computer
Graphics.
10. What is rendering? What are the different stages of rendering an image?
11. Describe an algorithm for the removal of hidden lines.
12. Make a comparative study of hidden surface removal algorithms.
13. What is ant aliasing? Discuss the techniques used for ant aliasing.
14. Discuss the reflection models used in Computer Graphics.
15. Compare the techniques of Phong shading and Gauraud shading.
Radhakrishnan, P.. CAD/CAM/CIM, New Age International Ltd, 2008. ProQuest Ebook Central, [Link]
Created from inflibnet-ebooks on 2024-04-06 [Link].