0% found this document useful (0 votes)
21 views36 pages

CAD CAM CIM - (Chapter 3. Principles of Computer Graphics)

This chapter discusses the principles of computer graphics as applied in CAD, highlighting the advantages of using computer graphics over traditional 2D drawing methods. It covers essential techniques such as raster technology, line and circle drawing algorithms, and the components of modern graphic displays. The chapter emphasizes the importance of geometric modeling, accuracy, and the ease of modification and storage in computer-aided design.

Uploaded by

POKEMON episode
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views36 pages

CAD CAM CIM - (Chapter 3. Principles of Computer Graphics)

This chapter discusses the principles of computer graphics as applied in CAD, highlighting the advantages of using computer graphics over traditional 2D drawing methods. It covers essential techniques such as raster technology, line and circle drawing algorithms, and the components of modern graphic displays. The chapter emphasizes the importance of geometric modeling, accuracy, and the ease of modification and storage in computer-aided design.

Uploaded by

POKEMON episode
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER

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.

• Sections can be automatically created.


• The associativity ensures that any change made in one of the related views will
automatically reflect in other views.
• Revision and revision control are easy.
• Drawings (geometric models) can be modified easily.
• More important than all, drawings can be reused conveniently.
• Storage and retrieval of drawings are easy.

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.

3.2 GRAPHIC PRIMITIVES


A drawing is created by an assembly of points, lines, arcs, circles. For example, drawing
shown in Fig 3.1 consists of several entities. In computer graphics also drawings are created
in a similar manner. Each of these is called an entity. The drawing entities that a user may
find in a typical CAD package include :
point
line
Copyright © 2008. New Age International Ltd. All rights reserved.

construction line, multi-line, polyline


circle
spline
arc
ellipse
polygon
rectangle

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

Fig. 3.1 A Simple Drawing


The fundamental principles of generation of some of these entities are discussed below :

3.3 POINT PLOTTING


The frame buffer display is an example of a point plotting device. The smallest unit accepted
by such displays is a single pixel. To construct a useful picture on a point plotting device,
a picture must be built out of several hundreds of pixels.

3.4 DRAWING OF LINES


Straight line segments are used a great deal in computer generated pictures. The following
criteria have been stipulated for line drawing displays :
i. Lines should appear straight
ii. Lines should terminate accurately
iii. Lines should have constant density
iv. Line density should be independent of length and angle
v. Line should be drawn rapidly
The process of turning on the pixels for a line segment is called vector generation. If the
Copyright © 2008. New Age International Ltd. All rights reserved.

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

3.4.1 DDA ALGORITHM


The digital differential analyzer generates lines from their differential equations. The DDA
works on the principle that X and Y are simultaneously incremented by small steps
proportional to the first derivatives of X and Y. In the case of a straight line the first
derivatives are constant and are proportional to DX and DY, where D is a small quantity.

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.

Table 3.1 Pixel Values

X Y trunc (X) trunc (Y)


2.5 7.50 2 7
3.5 7.73 3 7
4.5 7.96 4 7
5.5 8.19 5 8
6.5 8.42 6 8
7.5 8.65 7 8
8.5 8.88 8 8
9.5 9.11 9 9
10.5 9.34 10 9
11.5 9.57 11 9
12.5 9.80 12 9
13.5 10.23 13 10
14.5 10.46 14 10
15.5 10.69 15 10

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

Fig. 3.2 Plotting a Line

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.

3.4.3 DRAWING OF CIRCLES


Circle is another important entity like line. Several circle drawing algorithms have been
described in literature. A simple procedure for drawing a circle is described in this section.
This procedure calculates points on the circle centred about the origin and then adds
co-ordinates of the centre (X ,Y ) to the X and Y values respectively.
program mcircle;
var xc, yc, radius : integer;
($I GRAPH.P)
Procedure dcircle
(xc, yc,
radius: integer) ;
var
dtheta,
cdtheta, sdtheta,
x, y,
xtemp: real ;
z: integer ;
begin
dtheta : = 1/radius ;
cdtheta: = cos(dtheta) ;
sdtheta: = sin(dtheta) ;
x: = radius;
y: = 0;
for z: 0 to 45 do
begin
plot (round (xc + x), round (yc + y), 1);
plot (round (xc – x), round (yc + y), 1);
Copyright © 2008. New Age International Ltd. All rights reserved.

plot (round (xc + x), round (yc – y), 1);


plot (round (xc – x), round (yc – y), 1);
plot (round (xc + y), round (yc + x), 1);
plot (round (xc – y), round (yc + x), 1);
plot (round (xc + y), round (yc – x), 1);
plot (round (xc – y), round (yc – x), 1);
xtemp: = 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 47

x : = (x* cdtheta – y*sdtheta) ;


y : = (y*cdtheta + x*sdtheta) ;
end ;

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.

3.5 BRESENHAM’S CIRCLE ALGORITHM


Bresenham’s algorithm enables the selection of optimum raster locations to represent a
straight line. In this algorithm either pixels along X or Y directions are incremented by one
unit depending upon the slope of the line. The increment in the other direction is determined
by examining the error or distance between actual line location and the nearest grid
locations.
The principle of Bresenham’s algorithm can be explained with the aid of Fig 3.3 a. If the
slope of the line (in the first octant) is more than 1/2, the pixel point in the Y direction is
shifted by one. Thus lines L1 and L2 passes through pixel (0,0). For line L2 slope is greater
than 1/2 ; hence the pixel point is (1,1) whereas for L1 the slope is less than 1/2 and hence
(1,0) is the pixel point.
Bresenham’s algorithm selects optimum raster locations with minimum computation.
To accomplish this, the algorithm always increments by one unit in either X or Y depending
upon the slope of the line. The increment in the other variable either zero or one is
Copyright © 2008. New Age International Ltd. All rights reserved.

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.

and eliminating division to determine slope.


The pseudo code and a C-program for implementing Bresenham’s algorithm are given
below:

Pseudo code for Bresenham’s line-drawing algorithm


Given a line from x1, y1 to x2, y2 ...
dx is the difference between the x components of end points
dy is the difference between the y components of end points

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

ix is the absolute value of dx


iy is the absolute value of dy
inc is the larger of dx, dy
plotx is x1
ploty is y1 (the beginning of line)

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.

Program in Turbo-C to draw a line


# include <stdio. h>
# include <graphics. h>
# include <stdlb. h>
void draw line (int x1, int y1, int x2, int y2),
void main (void)
Copyright © 2008. New Age International Ltd. All rights reserved.

{
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

putpixel (plotx, ploty, 1)


else
}
getch ( ) ;
closegraph ( ) ;

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

Xi, Yi-1 Xi+1, Yi-1


Copyright © 2008. New Age International Ltd. All rights reserved.

Fig. 3.4 First Quadrant Pixel Position

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

Void draw circle (int xc, int yc, int y) ;


Void symmetry (int x, int y, int xc, int yc) ;
double ratio ;
Void main (void)
{
draw circle (300, 150, 50) ;
}
int d, x ;
int gd, gm ;
gd = DETECT ;
initgraph (&gd, &gm, “ “) ;
d=3-2*y;
ratio = 1.5
x=0;
while (x < y)
{
symmetry (x, y, xc, yc) ;
if (d < 0)
d+=4*x+6;
else
{
d + = 4 * (X – Y) + 10 ;
y-:
}
x++ ;
if (x = = y)
symmetry (x, y, xc, yc) ;
}
getch ( ) ;
closegraph ( ) ;
}
Copyright © 2008. New Age International Ltd. All rights reserved.

void symmetry (int x, int y, int xc, int yc)


{
int x start, x end, x out ;
int y start, y end, y out ;
x start = x * ratio
x end = (x + 1) * ratio ;
y start = y * ratio ;

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

Fig. 3.5 Flow Chart to Determine Pixel Values

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

3.5.2 EXAMPLE OF BRESENHAM’S ALGORITHM


Consider a circle with centre at the origin and radius equal to 10 units. Because of symmetry
only the first octant is considered here.
X=0
Y = 10
i = 2 (1–10) = –18
LIMIT = 0
PLOT (0, 10)
Y1 > LIMIT CONTINUE
i < 0 GOTO 2
2 = 2 (–18) + 2 (10) –1 = –17 < 0 GOTO 10
10 X = 0 + 1 = 1
i = –17 + 2 + 1 = –14
GOTO 1
1 PLOT (1, 10)
Yi > LIMIT CONTINUE
i<0
= 2 (–14) + 2 (10) –1
= –9 < 0 GOTO 10
X=1+1
i = –14 + 2 (2) + 1
= –9
GOTO 1
PLOT (2, 10)
The procedure is to be continued till the required point is reached. The results are
given in Table 3.3 and are plotted in Fig. 3.6.

Table 3.3 Pixel Values for Circle


Copyright © 2008. New Age International Ltd. All rights reserved.

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

Fig. 3.6 Plot of First Octant of a Circle

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.

3.7 TRANSFORMATION IN GRAPHICS


Geometric transformations provide a means by which an image can be enlarged in size, or
reduced, rotated, or moved. These changes are brought about by changing the co-ordinates
of the picture to a new set of values depending upon the requirements.

3.8 CO-ORDINATE SYSTEMS USED IN GRAPHICS AND WINDOWING


Transformations can be carried out either in 2-dimensions or in 3-dimensions. The theory
of two-dimensional transformations is discussed first in this chapter. This is then extended
to three dimensions.
When a design package is initiated, the display will have a set of co-ordinate values. These
Copyright © 2008. New Age International Ltd. All rights reserved.

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

Fig. 3.7 Use of Window to Enlarge a Portion of the Drawing

3.9 VIEW PORT


It may be sometimes desirable to display different portions or views of the drawing in
different regions of the screen. A portion of the screen where the contents of the window
are displayed is called a view port. Let the screen size be X = 0 to 200 and Y = 0 to 130. A
view port can be defined by the co-ordinates say X1 = 65, X2 = 130, Y1 = 50 and Y2 = 100.
If we use the same window as in Fig. 3.7, the definition of this view port will display the
image in the right hand top quarter of the screen (Fig. 3.8) choosing different view ports
multiple views can be placed on the screen. Fig. 3.9 shows four views of a component
displayed using view port commands.

1 3 0 ,1 0 0 View Port 2
View Port 1

View Port 4 View Port 3


6 5 ,5 0
Copyright © 2008. New Age International Ltd. All rights reserved.

Fig. 3.8 View Port Fig. 3.9 Use of Multiple View Ports

3.10 2-D TRANSFORMATIONS


In computer graphics, drawings are created by a series of primitives which are represented
by the co-ordinates of their end points. Certain changes in these drawings can be made by
performing some mathematical operations on these co-ordinates. The basic transformations
are scaling, translation and rotation.

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

Fig. 3.10 Scaling a Point

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

Fig. 3.11 (a) Fig. 3.11 (b)

Fig. 3.11 Scaling a Triangle

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

 Cos 45° Sin 45° 


20]  –Sin 45° Cos 45° 

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

Fig. 3.13 Rotation

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

Fig. 3.14 Shearing

An X-shear transforms the point (X, Y) to (X1, Y1), where


X1 = X + Sh2.Y
Y1 = Y Sh2 is the shear factor.
Fig. 3.15 shows the effect of X-shear.

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

Fig. 3.15 X-Shear


Copyright © 2008. New Age International Ltd. All rights reserved.

3.11 HOMOGENEOUS TRANSFORMATIONS


Each of the above transformations with the exception of translation can be represented
as a row vector X, Y and a 2 X 2 matrix. However, all the four transformations discussed
above can be represented as a product of a 1 X 3 row vector and an appropriate 3 X 3
matrix. The conversion of a two-dimensional co-ordinate pair (X, Y) into a 3-dimensional
vector can be achieved by representing the point as [X Y 1]. After multiplying this vector

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.

3.12 COMBINATION TRANSFORMATIONS


Sequences of transformations can be combined into a single transformation using the
concatenation process. For example, consider the rotation of a line about an arbitrary point.
Line AB is to be rotated through 45° in anticlockwise direction about point A (Fig 3.16(a)).
Fig. 3.16(b) shows an inverse translation of AB to A1B1. A1B1 is then rotated through 45° to
A2B2. The line A2B2 is then translated to A3B3.

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

The respective transformation matrices are:


 1 0 0
 
 0 1 0
 −Tx −Ty 1 

 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

Fig. 3.16 (a) Fig. 3.16 (b)


Fig. 3.16 Rotation about an Arbitrary Point

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

Fig. 3.17 Example of Clipping

3.14 3-DIMENSIONAL TRANSFORMATIONS


It is often necessary to display objects in 3-D on the graphics screen. The transformation
matrices developed for 2-dimensions can be extended to 3-D.

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

iii. Rotation: Rotation in 3-D can be about X - , Y - or Z axis.

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.

3.15.1 PARALLEL (ORTHOGONAL) PROJECTION


This is the simplest of the projection methods. Fig. 3.18 shows the projection of a cube on
to a projection plane. The projectors, which are lines passing through the corners of the
object are all parallel to each other. It is only necessary to project the end points of a line in
3-D and then join these projected points. This speeds up the transformation process.
However a major disadvantage of parallel projection is lack of depth information.
Y
C
D1 1
Copyright © 2008. New Age International Ltd. All rights reserved.

B1
A
1

A C

Fig. 3.18 Parallel Projection of Cube

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

3.15.2 PERSPECTIVE PROJECTION


The perspective projection enhances the realism of displayed image by providing the viewer
with a sense of depth. Portions of the object farther away from the viewer are drawn smaller
then those in the foreground. This is more realistic as it is the way we see an object. In
perspective projection the projections connect the eye with every point of the object and
therefore all projections converge to the eye.

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

Fig. 3.19 Central Projection

As the display screen is a two-dimensional space, we cannot display three-dimensional


objects but only their projections. Computationally, projection transformations are in general
quite expensive. Since the generation of a perspective view of a given object may require
the projection transformation of a considerable number of points, the projection applied is
usually restricted to the central projection and sometimes to even simpler parallel or
orthographic projection in order to keep the execution time for the generation of a
perspective view within reasonable limits.
Figure 3.19 explains the central projection as it is usually applied in computer graphics.
The problem is to determine the projection of an object point, located somewhere in a
three-dimensional space, onto a plane in that space, called the image plane. This projection
is called the image point of the corresponding object point. In a central projection, The
center of projection, also called the viewpoint, is located on one of the axes of the three-
dimensional orthogonal co-ordinate system. In Figure 3.19 the viewpoint is arbitrarily
Copyright © 2008. New Age International Ltd. All rights reserved.

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

Then it follows from an elementary theorem of geometry that


Z0 − Z
X = X1
Z0 − Z1

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.

3.15.3 ISOMETRIC PROJECTION


In isometric projection the three orthogonal edges of an object are inclined equally to the
projection plane. Because of the relative ease of projection and the ability to give 3-D
perception, isometric projection is widely used in computer aided design.
In computer aided design the co-ordinates of the drawing are available in their natural
co-ordinate system. These are transformed suitably to enable the viewer different views or
rotate the object in such away that all the faces of the object are made visible continuously.
There are several uses for this technique in product design. Hence good design packages
incorporate several viewing transformation techniques. The viewing parameters depend
upon the system graphics standard followed in developing the graphics package. The
algorithms for these viewing transformations are available in literature.
Copyright © 2008. New Age International Ltd. All rights reserved.

3.16 SCAN CONVERSION


In order to display rasterized image using video technology it is necessary to organize
the picture into the precise pattern required by the video display. This is called scan
conversion. The display information must be organized and presented in the scan line
order i.e., from top to bottom and from left to right. There are several techniques of scan
conversion.

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

i. Real time scan conversion


ii. Run-length encoding
iii. Cell organization
iv. Frame buffer memory

3.16.1 REAL TIME SCAN CONVERSION

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

Fig. 3.20 Active Edge List

Table 3.4 Active Edge List for Fig. 3.20

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

3.16.2 RUN LENGTH ENCODING


In run length encoding scheme the number of pixels of same intensity and color in a
given scan line is specified. In the simplest case the encoded data will show the intensity
and run length. For example, suppose we have a pixel arrangement in a scan line as
shown in Fig. 3.21.

1 2 3 4

Fig. 3.21 Pixels in the Scan Line

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

3.16.3 CELL ENCODING


Run length encoding stores a picture sequentially line by line. In contrast cell encoding
considers representation of picture information by dividing the display area into cells of
suitable sizes. For example, a display area of 512 × 512 can be divided into 4096 cells of 64
pixels. In the case of drawings, combinations of these adjacent cells can be used to construct
complete lines.

3.16.4 FRAME BUFFERS


A common implementation of frame buffer is a random access semiconductor memory.
Frame buffers can also be implemented using shift registers. Each shift register
Copyright © 2008. New Age International Ltd. All rights reserved.

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.

3.18 RASTERIZING POLYGONS


Rasterizing a line was discussed earlier in this chapter. Filling a polygon means finding
pixel co-ordinates of interior points and assigning to these a value calculated using one of
the incremental shading schemes. This requires the construction of an edge list for each
polygon. There are two approaches to solid area scan conversion of polygons. They are
Copyright © 2008. New Age International Ltd. All rights reserved.

scan conversion and seed filling.

3.18.1 SCAN CONVERTING POLYGONS


A scan line intersects a polygon at one or more points. The intersection divides the scan
line into a number of regions. Referring to Fig. 3.24, P1-P2-P3-P4 is a polygon. It has a
vertex list of P1P2P3P4 and an edge list of P1P2, P2P3, P3P4 and P4P1. The intersections
are at pixels 4 and 8 along the scan line n. In determining the intensity of shade or color, the
intersections are considered in pairs. For intervals between pairs of intersections, the color

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

Fig. 3.24 Scan Converting Polygons

3.18.2. SEED FILL ALGORITHM


The scan line algorithm fills the polygon in the scan line order. The seed fill algorithm is
designed on the assumption that at least one pixel interior to a polygon is known. Interior
- or boundary - defined regions can be classified into 4 - connected or 8 - connected.
Algorithms can be designed to fill both the regions. An 8-connected algorithm, apart from
left, right, up and down direction, gives four more additional diagonal directions.
More efficient algorithms use a combination of scan line and seed fill approaches.

3.19 HIDDEN SURFACE REMOVAL


One of the difficult problems in computer graphics is the removal of hidden surfaces from
the images of solid objects. In Fig. 3.25 (a) an opaque cube is shown in wire frame
representation. Edges 15, 48, 37, 14, 12,23,58 and 87 are visible whereas edges 56, 67 and 26
are not visible. Correspondingly, surfaces 1265, 2673 and 5678 are not visible since the object
is opaque. The actual representation of the cube must be as shown in Fig. 3.25 (b).

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.

Table 3.5 Algorithms for Hidden Line and Hidden Surface

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.

3.19.1 Z-BUFFER ALGORITHM


This scheme was developed by Catmull using Sutherland’s classification scheme. In this
technique, pixels interior to a polygon are shaded and their depth is evaluated by
interpolation from Z-values of the polygon vertices after the viewing transformation
Copyright © 2008. New Age International Ltd. All rights reserved.

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

3.19.2 SCAN LINE Z-BUFFER ALGORITHM


This is a special case of Z-buffer algorithm. In this algorithm for each scan line the
frame buffer is initialized to the back ground and Z buffer to the minimum Z. The
intersection of the scan line with the two dimensional projection of each polygon is
found. The depth of each pixel on the scan line between each pair of the intersection is
determined. If the pixel depth is greater than that in the Z-buffer then this line segment
is currently visible.
A spanning scan line algorithm, instead of solving the hidden surface removal on a
pixel-by-pixel basis using incremental Z calculation, uses spans along the scan line
over which there is no depth conflict. Consider the three dimensional screen space
shown in Fig. 3.26. A scan line algorithm moves a scan line plane down the Y-axis. This
plane, parallel to the XOZ plane, intersects the objects in the scene and reduces the
hidden surface problem to a 2-D space. The line segments obtained through the
intersection are then analyzed to detect hidden surfaces. This is done by considering
the spans which form part of a line segment that is contained between edge intersections
of all active polygons.
Y

E
AN
PL
N
S CA

Fig. 3.26 Spanning Scan line algorithm

3.20 ANTI ALIASING


Aliasing in computer graphics manifests in several ways. The computer generated
Copyright © 2008. New Age International Ltd. All rights reserved.

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

3.20.1 SUPER SAMPLING OR POST FILTERING


This method is a three-stage process. The stages are :
i. The image is sampled at n times the display resolution.
ii. The sample image is then low pass filtered
iii. The filtered image is resampled at the device resolution.

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.20.2 PRE-FILTERING OR AREA SAMPLING


This technique involves performing sub-pixel geometry in the continuous image generation
domain and returns for each pixel an intensity which is computed by using the area of
visible sub-pixel fragments as weights in an intensity run. Thus this is an area sampling
method. Since this method involves considerable amount of computation, several
modifications to this algorithm have been developed.

3.20.3 STOCHASTIC SAMPLING


This method is a two stage process.
i. Sample the image using a sampling grid where the position of each sampling
point has been subjected to random perturbation.
ii. Use these sample values with a reconstruction filter to determine the pixel
intensities to which the unperturbed sample positions correspond.
The problem with this method is that it is only easily incorporated where the image
synthesis uses an incoherent sampling method. Since the method splits the objects into
micro polygons, it is suitable of objects consisting of parametric bi-cubic patches.

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.

to the representation of the object.


Fig. 3.27 shows what happens when light is incident on a surface. Light gets partly
reflected, partly scattered, partly absorbed and partly transmitted. The relative magnitudes
of these are influenced by many factors like the opaqueness of the solid, surface texture
etc. The intensity and wave length of light reflected from a surface depends on the incident
angle, the surface roughness, incident wave length and the electrical properties of the
surface. In computer graphics designer can model reflected light and transmitted light.

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)

Fig. 3.27 Light Incident on a Surface

Reflected light could be categorized into two types:


i. Diffuse reflection: Diffuse light is scattered in all directions and is responsible for
the color of the object. The light is reflected from a surface due to molecular
interaction between incident light and the surface material. A yellow object for
example, absorbs white light and reflects yellow component of the light. This
property is attributed to diffuse reflection. When light from a point source is
incident on a solid object, the diffuse reflection depends upon the angle of
inclination of the surface with that of the incident beam. More important source
of illumination of the objects is ambient light, which is the result of multiple
reflections from the walls and other objects in the vicinity and is incident on a
surface in all directions.
ii. Specular reflection: A perfectly matt surface scatters light in all directions. Most
of the surfaces that we deal with, however, have different levels of glossiness.
The specular deflection deals with the reflection of the surface due to glossiness.
Consider Fig. 3.28 which shows the reflection of light on a surface. If the surface
is perfectly glossy the reflected light is in the direction of R. If the surface becomes
more and more matt, the reflection intensity varies as in a profile shown as the
shaded area of the figure.
A technique to model reflection from an object based on specular reflection has been
Copyright © 2008. New Age International Ltd. All rights reserved.

proposed by Phong. This model assumes that:


• Light sources are point sources.
• All geometry except the surface normal is ignored.
• Diffuse and specular components are modeled as local components
• The model to simulate the specular term is empirical.
• The color of specular reflection is that of the light source
• The ambient lighting is constant.

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

3.22.1 GAURAUD SHADING


Gauraud Shading involves bilinear intensity interpolation over a polygon mesh. It is
restricted to diffuse component of the reflection model. The technique first calculates
the intensity at each vertex, assuming that the light source is at infinity. The intensity of
the light reflected over the polygonal surface can then be obtained by integrating the
interpolation process with the scan conversion process. The intensities at the edge of
each scan line are calculated from the vertex intensities and intensities along the scan
line from these.

3.22.2 PHONG TECHNIQUE


Phong model overcomes some of the deficiencies of Gauraud technique and incorporates
Copyright © 2008. New Age International Ltd. All rights reserved.

specular reflection. The important feature of the Phong model are :


i. Vertex normals instead of vertex intensities are calculated by averaging normal
vectors of the surface that share the vertex.
ii. Bilinear interpolation is used for incremental interpolation of points interior to
polygons.
iii. A separate intensity is evaluated for each pixel from the interpolated normals.

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

3.23 GENERATION OF CHARACTERS


Along with the primitives discussed above, strings of characters are to be displayed on
drawings to give instruction and information to the user of the drawing. A font can be made
of rectangular patterns of dots called raster cells. Fig. 3.29 shows a typical 7×9 raster cell,
which may vary from graphic system to graphic system. Each character is then represented
by 63 bits. The character generation can be done either through hardware (ROM) or software.
Graphics software usually provides means for users to design new fonts.

Fig. 3.29 Representation of Text

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

You might also like