BCA Computer Graphics
BCA Computer Graphics
SEMESTER - VI
II ALGORITHMS 33
III TRANSFOSSRMATIONS 51
IV CLIPPING ALGORITHMS 76
Page 2 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
UNIT - I
INPUT AND OUTPUT DEVICES
Page 3 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Education:
Computer generated models are extremely useful for teaching huge
number of concepts and fundamentals in an easy to understand and learn
manner. Using computer graphics many educational models can be created
through which more interest can be generated among the students regarding the
subject.
Training:
Specialized system for training like simulators can be used for training
the candidates in a way that can be grasped in a short span of time with better
understanding. Creation of training modules using computer graphics is simple
and very useful.
Graphic operations:
A general purpose graphics package provides user with Varity of
function for creating and manipulating pictures.
The basic building blocks for pictures are referred to as output
primitives. They includes character, string, and geometry entities such as
point, straight lines, curved lines, filled areas and shapes defined with
arrays of color points.
Input functions are used for control & process the various input device
such as mouse, tablet, etc.
Control operations are used to controlling and housekeeping tasks such
as clearingdisplay screen etc.
All such inbuilt function which we can use for our purpose are known
asgraphics function
Software Standard
Primary goal of standardize graphics software is portability so that it can
be used in anyhardware systems & avoid rewriting of software program
for different system
Some of these standards are discussed below
Page 4 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 5 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Fig. 2.1: − Stair step effect produced when line is generated as a series of
pixel positions.
The stair step shape is noticeable in low resolution system, and we can
improve their appearance somewhat by displaying them on high
resolution system.
More effective techniques for smoothing raster lines are based on
adjusting pixel intensities along the line paths.
For raster graphics device−level algorithms discuss here, object positions
are specified directly in integer device coordinates.
Pixel position will referenced according to scan−line number and
column number which is illustrated by following figure. Pixel positions
referenced by scan−line number andcolumn number.
To load the specified color into the frame buffer at a particular position,
we will assume
We have available low−level procedure of the form set pixel (x,y).
Similarly for retrieve the current frame buffer intensity we assume to
have procedure
Page 6 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
0 6
4
2
1 2 3 4 5
Graphics Packages:
There are mainly two types of graphics packages:
General programming package
Special−purpose application package
General programming package
A general programming package provides an extensive set of graphics
function that can be used in high level programming language such as C
or FORTRAN.
It includes basic drawing element shape like line, curves, polygon, color
of elementtransformation etc.
Example: − GL (Graphics Library).
Page 7 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 8 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Pointing device: It allows you move the pointer and select objects on
the screen, e.g. mouse or trackball.
Icons: It refers to small images on the display screen that represent
commands, files, windows etc. Using pointer and pointing device, you
can execute these commands.
Desktop: It is the display screen that contains the icons.
GUI KEY Benefits
It allows you to place more information within a program.
The graphics allow users to use complex programs with greater ease.
It saves time as you do not need to edit configurations manually.
You can easily memorize the tasks (point-and-click).
Helps create user-friendly software with a point-and-click interface.
Input Devices:
The Input Devices are the hardware that is used to transfer transfers
input to thecomputer. The data can be in the form of text, graphics, sound, and
text. Output device display data from the memory of the computer. Output can
be text, numeric data, line,polygon, and other objects.
These Devices include:
1. Keyboard
2. Mouse
3. Trackball
4. Space ball
5. Joystick
6. Light Pen
7. Digitizer
8. Touch Panels
9. Voice Recognition
10. Image Scanner
Page 9 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
1. Keyboard
The most commonly used input device is a keyboard. The data is entered by
pressing the set of keys. All keys are labelled. A keyboard with 101 keys is
called a QWERTY keyboard. The keyboard has alphabetic as well as numeric
keys. Some special keys are also available.
1. Numeric Keys: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Page 10 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
2. Mouse:
A Mouse is a pointing device and used to position the pointer on the
screen. It is a small palm size box. There are two or three depression switches
on the top. The movement of the mouse along the x-axis helps in the
horizontal movement of the cursor and the movement along the y-axis helps
in the vertical movement of the cursor on the screen. The mouse cannotbe used
to enter text. Therefore, they are used in conjunction with a keyboard.
3. Trackball
It is a pointing device. It is similar to a mouse. This is mainly used in
notebook or laptop computer, instead of a mouse. This is a ball which is half
inserted, and by changing fingers on the ball, the pointer can be moved.
4. Space ball:
It is similar to trackball, but it can move in six directions where trackball
can move intwo directions only. The movement is recorded by the strain gauge.
Strain gauge is applied with pressure. It can be pushed and pulled in various
directions. The ball has a diameter around 7.5 cm. The ball is mounted in the
base using rollers. One-third of the ball is an inside box, the rest is outside.
Applications:
Page 11 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
6. Light Pen:
Light Pen (similar to the pen) is a pointing device which is used to select
displayed menu item or draw pictures on the monitor screen. It consists of a
photocell and an optical system placed in a small tube. When its tip is moved
over the monitor screen, and pen button ispressed, its photocell sensing element
detects the screen location and sends the corresponding signals to the CPU.
Uses:
Page 12 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
existing lines. The electronic tracking device contains a switch for the user to
record the desire x & y coordinate positions. The coordinates can be entered
into the computer memory or stored or an off-line storage medium such as
magnetic tape.
8. Touch Panels:
Touch Panels is a type of display screen that has a touch-sensitive
transparent panel covering the screen. A touch screen registers input
when a finger or other object comes in contact with the screen.
When the wave signals are interrupted by some contact with the screen,
that located is recorded.
Page 13 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Non-impact Printers
Impact Printers
In impact printers, there is a physical contact established between the print
head,ribbon, ink-cartridge, and paper.
The printers hit print head on an ink-filled ribbon than the letter prints on the
paper.
Impact printers are works like a typewriter.
These printers have three types:
Page 14 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Types of Printers:
Page 15 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Advantages:
More reliable
Noisy in operation
Drum Printers:
It has a shape like a drum, so it is called “Drum Printer.” This type of printer
contains many characters that are printed on the drum. The surface of the drum
is break down into the number of tracks. Total tracks are equal to character132.
A drum will have 132 tracks. The number of tracks is divided according to the
width of the paper. It can print approx. 150-2500 lines per minute.
Drum Printer
Advantages:
High Speed
Low Cost
Page 16 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Disadvantages:
Noisy in Operation
Dot Matrix Printer:
It is also known as the “Impact Matrix Printer.” Dot Matrix Printer can
print only one character at a time. The dot matrix printer uses print heads
consisting of 9to 24 pins. These pinsare used to produce a pattern of dots on the
paper to create a separate character. Dot-matrix printer can print any shapes of
character, special character, graphs, and charts.
Long Life
Disadvantages:
Slow speed
Low Resolution
Page 17 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Non-impact Printers
In Non-impact printers, there is no physical contact between the print
head or paper head. A non-impact printer prints a complete page at a time. The
Non-impact printers spray ink on the paper through nozzles to form the letters
and patterns. The printers that print the letters without the ribbon and on papers
are called Non-impact printer. Non-impact printers are also known as “Page
Printer.”
These printers have two types:
Inkjet Printer
Laser Printer
Inkjet Printer:
It is also called “Deskjet Printer.” It is a Non-impact printer in which the
letters and graphics are printed by spraying a drop of ink on the paper with
nozzle head.
A Color inkjet printer has four ink nozzles, sapphire, red, yellow, and
black, so it is also called CMYK printer. We can produce any color by using
these four colors. The prints and graphics of this printer are very clear. These
printers are generally used for home purposes.
Inkjet Printer
Advantages:
High-Quality Printout
Low noise
Page 18 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
High Resolution
Disadvantages:
Laser printer
Advantages:
High Resolution
High printing Speed
Page 19 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Plotters:
A plotter is a special type of output device. It is used to print large graphs,
large designs on a large paper. For Example: Construction maps, engineering
drawings, architectural plans, and business charts, etc.It was invented by
“Remington rand” in 1953.It is similar to a printer, but it is used to print vector
graphics.
Types of Plotter:
Flatbed Plotter:
In a flatbed plotter, the paper is kept in a stationary position on a table or
a tray. A flatbed plotter has more than one pen and a holder. The pen rotates on
the paper upside-down and right-left by the using of a motor. Every pen has a
different color ink, which is used to draw the multicolor design. We can quickly
draw the following designs by using a flatbed printer.
For Example: Cars, Ships, Airplanes, Dress design, road and highway blue
prints, etc.
Page 20 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
A Flatbed Plotter
Advantages of Flatbed Plotter
A Drum Plotter
Advantages of Drum Plotter:
Page 21 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Construction of a CRT:
The primary components are the heated metal cathode and a control
grid.
The heat is supplied to the cathode (by passing current through the
filament).This way the electrons get heated up and start getting
ejected out of the cathodefilament.
Page 22 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
2. Magnetic Deflection:
Here, two pairs of coils are used. One pair is mounted on the top and
bottom of the CRT tube, and the other pair on the two opposite sides. The
magnetic field produced by both these pairs is such that a force is generated on
the electron beam in a direction which is perpendicular to both the direction of
magnetic field, and to the direction of flow of the beam. One pair is mounted
horizontally and the other vertically.
Page 23 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
This frame buffer stores the intensity values for all the screen points.
Each screen point is called a pixel (picture element or pel).
On black and white systems, the frame buffer storing the values of the
pixels is called a bitmap. Each entry in the bitmap is a 1-bit datawhich
determine the on (1) and off (0) of the intensity of the pixel.
On color systems, the frame buffer storing the values of the pixels is called
a pixmap(Though nowadays many graphics libraries name it as bitmap too).
Each entry in the pix map occupies a number of bits to represent the color of the
pixel. For a true color display, the number of bits for each entry is 24 (8 bits
per red/green/blue channel, each channel 28 =256 levels of intensity value, ie.
256 voltage settings for each of the red/green/blue electron guns).
Random-Scan (Vector Display) or stroke-writing or calligraphic displays:
The CRT's electron beam is directed only to the parts of the screen where
a picture is to be drawn. The picture definition is stored as a set of line-drawing
commands in a refresh display file or a refresh buffer in memory.
Page 24 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Random-scan generally have higher resolution than raster systems and can
produce smooth line drawings, however it cannot display realistic shaded
scenes.
Color CRT Monitors:
The CRT Monitor display by using a combination of phosphors. The phosphors
are different colors. There are two popular approaches for producing color
displays with a CRT are:
Page 25 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Inexpensive
Disadvantages:
Page 26 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Working:
The phosphor dots in the triangles are organized so that each electron
beam can activate only its corresponding color dot when it passes
through the shadow mask.
Advantage:
Realistic image
Million different colors to be generated
Page 27 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
No refreshing is needed.
High Resolution
Page 28 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
High Resolution
Large screen size is also possible.
Less Volume
Less weight
Flicker Free Display
Disadvantage:
Poor Resolution
Wiring requirement anode and the cathode is complex.
Page 29 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Small Size
Low Cost
Disadvantage:
LCDs do not emit light; as a result, the image has very little contrast.
Page 30 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Graphics Accelerator
A graphics accelerator is a piece of dedicated hardware designed and
used to rapidly process visual data. It is a full computer in its own right, as it has
its own processor, RAM, buses and even I/O mechanisms which it uses to
Page 31 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
connect to the computer system; in modern computers this is the PCI-E port.
Graphics accelerator is an older term for what is now commonly called a
graphics processing unit (GPU).
Graphics accelerators are widely used in industries such as:
Computer-aided design (CAD)
Page 32 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
UNIT - II
ALGORITHMS
Definition
It is a process of representing graphics objects a collection of pixels. The
graphics objects are continuous. The pixels used are discrete. Each pixel can
have either on or off state.
The circuitry of the video display device of the computer is capable of
converting binary values (0, 1) into a pixel on and pixel off information. 0 is
represented by pixel off. 1 is represented using pixel on. Using this ability
graphics computer represent picture having discrete dots
Any model of graphics can be reproduced with a dense matrix of dots or
points. Most human beings think graphics objects as points, lines, circles,
ellipses. For generating graphical object, many algorithms have been developed.
Advantage of developing algorithms for scan conversion:
1. Algorithms can generate graphics objects at a faster rate.
2. Using algorithms memory can be used efficiently.
3. Algorithms can develop a higher level of graphical objects.
Examples of objects which can be scan converted
1. Point
2. Line
3. Sector
4. Arc
5. Ellipse
6. Rectangle
7. Polygon
8. Characters
9. Filled Regions
Page 33 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
m=
yi+1-yi=∆y.......................... equation 3
yi+1-xi=∆x.......................... equation 4
yi+1=yi+∆y
∆y=m∆x
yi+1=yi+m∆x
∆x=∆y/m xi+1=xi+∆x xi+1=xi+∆y/m
Case1: When |m|<1 then (assume that x1<x2)
x= x1,y=y1 set ∆x=1 yi+1=y1+m, x=x+1 Until x = x2
Case2: When |m|>1 then (assume that y1<y2) x= x1,y=y1 set ∆y=1
xi+1= , y=y+1
Until y → y2
Page 34 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Advantage:
1. It is a faster method than method of using direct use of line equation.
2. This method does not use multiplication theorem.
3. It allows us to detect the change in the value of x and y ,so plotting of
same point twiceis not possible.
4. This method gives overflow indication when a point is repositioned.
5. It is an easy method because each step involves just two additions.
Disadvantage:
1. It involves floating point additions rounding off is done.
Accumulations of round offerror cause accumulation of error.
2. Rounding off operations and floating point operations consumes a lot
of time.
3. It is more suitable for generating line using the software. But it is
less suited forhardware implementation.
DDA Algorithm:
Step1: Start Algorithm
Step2: Declare x1,y1,x2,y2,dx,dy,x,y as integer variables.
Step3: Enter value of x1,y1,x2,y2. Step4: Calculate dx = x2-x1 Step5:
Calculate dy = y2-y1
Step6: If ABS (dx) > ABS (dy)
Then step = abs (dx) Else
Step7:xinc=dx/step
yinc=dy/stepassign x = x1 assign y = y1
Step8: Set pixel (x, y)
Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y)) Step10: Repeat step 9 until x = x2 Step11:
End Algorithm
Page 35 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Example: If a line is drawn from (2, 3) to (6, 15) with use of DDA. How many
points will needed togenerate such line?
Solution: P1 (2,3) P11 (6,15)x1=2
y1=3 x2= 6 y2=15
dx = 6 - 2 = 4
dy = 15 - 3 = 12
m=
Page 36 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 37 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Now consider the difference between these 2 distance valuess - t
When (s-t) <0 ⟹ s < t The closest pixel is S When (s-t) ≥0 ⟹ s < t The closest
pixel is T This difference is
s-t = (y-yi)-[(yi+1)-y]
= 2y - 2yi -1
Bresenham's Line Algorithm:
Step1: Start Algorithm
Step2: Declare variable x1,x2,y1,y2,d,i1,i2,dx,dy
Step3: Enter value of x1,y1,x2,y2
Where x1,y1are coordinates of starting point And x2,y2 are coordinates of
Ending point
Step4: Calculate dx = x2-x1
Calculate dy = y2-y1 Calculate i1=2*dy
Calculate i2=2*(dy-dx)Calculate d=i1-dx
Step5: Consider (x, y) as starting point and xendas maximum possible value of
x.
If dx < 0
Then x = x2 y = y2 xend=x1
If dx > 0 Then x = x1
y = y1
xend=x2
Step6: Generate point at (x,y)coordinates.
Step7: Check if whole line is generated.
If x > = xend Stop.
Step8: Calculate co-ordinates of the next pixel If d < 0
Page 38 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Thend = d + i1
If d ≥ 0
Then d = d + i2 Increment y = y + 1
Step9: Increment x = x + 1
Step10: Draw a point of latest (x, y) coordinates
Step11: Go to step 7
Step12: End of Algorithm
Example: Starting and Ending position of the line are (1, 1) and (8, 5). Find
intermediate points.
Solution: x1=1
y1=1x2=8y2=5
dx= x2-x1=8-1=7dy=y2-y1=5-1=4
I1=2* ∆y=2*4=8 I2=2*(∆y-∆x)=2*(4-7)=-6d = I1-∆x=8-7=1
Page 39 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
x y d=d+I1 or I2
1 1
d+I2=1+(-6)=-5
2 2
d+I1=-5+8=3
3 2 d+I2=3+(-6)=-3
4 3 d+I1=-3+8=5
5 3 d+I2=5+(-6)=-1
6 4 d+I1=-1+8=7
7 4 d+I2=7+(-6)=1
8 5
Advantage:
1. It involves only integer arithmetic, so it is simple.
2. It avoids the generation of duplicate points.
3. It can be implemented using hardware because it does not use
multiplication anddivision.
4. It is faster as compared to DDA (Digital Differential Analyzer)
Page 40 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 41 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Polynomial Method:
The first method defines a circle with the second-order polynomial equation as
shown in fig:
y2=r2-x2
Where x = the x coordinatey = the y coordinate
r = the circle radius
With the method, each x coordinate in the sector, from 90° to 45°, is found by stepping x from 0
Algorithm:
Step1: Set the initial variablesr = circle radius
(h, k) = coordinates of circle centerx=o
I = step size X end
Step2: Test to determine whether the entire circle has been scan-converted. If x
>xend then stop.
Page 42 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Step3: Compute y =
Step4: Plot the eight points found by symmetry concerning the center (h, k) at the current (x, y)
coordinates.
Plot (x + h, y +k) Plot (-x + h, -y + k)
Plot (y + h, x + k) Plot (-y + h, -x + k)
Plot (-y + h, x + k) Plot (y + h, -x + k)
Plot (-x + h, y + k) Plot (x + h, -y + k)
Step5: Increment x = x + i
Bresenham’s Algorithm
We cannot display a continuous arc on the raster display. Instead, we have to
choosethe nearest pixel position to complete the arc.
From the following illustration, you can see that we have put the pixel at X,
Page 43 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
YX,Y location
and now need to decide where to put the next pixel − at N X+1,YX+1,Y or at S
X+1,Y−1X+1,Y−1.
Algorithm:
Step 1 - Get the coordinates of the center of the circle and radius, and
store them in x,yand R respectively. Set P=0 and Q=R.
Step 2 − Set decision parameter D = 3 – 2R. Step 3 − Repeat through step-
8 while P ≤ Q.Step 4 − Call Draw Circle X, Y, P, QX, Y, P,
Q. Step 5 − Increment the value of P.
Step 6 − If D < 0 then D = D + 4P + 6.
Step 7 − Else Set R = R - 1, D = D + 4P−QP−Q + 10.
Step 8 − Call Draw Circle X, Y, P, QX, Y, P, Q.
Draw Circle Method(X, Y, P, Q).
Call Putpixel (X + P, Y + Q). Call Putpixel (X - P, Y + Q). Call Putpixel (X + P,
Y - Q). Call Putpixel (X - P, Y - Q). Call Putpixel (X + Q, Y + P). Call Putpixel
Page 44 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 45 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Connected Polygon
In this technique 4-connected pixels are used as shown in the figure. We
are putting the pixels above, below, to the right, and to the left side of the
current pixels and this process will continue until we find a boundary with
different color.
Algorithm
Step 1 − Initialize the value of seed point seedx,seedyseedx,seedy, fcolor
anddcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color, then repeat the
steps 4 and 5 till the boundary pixels reached. If get pixel (x,y) =
dcol then repeat step 4 and 5
Step 4 −Change the default color with the fill color at the seed
point.SetPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighbourhood points.
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol) FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
Step 6 − Exit
There is a problem with this technique. Consider the case as shown below
where we tried to fill the entire region. Here, the image is filled only partially.
In such cases, 4-connected pixels technique cannot be used.
Page 46 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Connected Polygon
In this technique 8-connected pixels are used as shown in the figure. We
are putting pixels above, below, right and left side of the current pixels as we
were doing in 4-connected technique.
In addition to this, we are also putting pixels in diagonals so that entire
area of the current pixel is covered. This process will continue until we find a
boundary with different color.
Algorithm
Step 1 − Initialize the value of seed point seedx, seedyseedx,seedy,
fcolorand dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color then repeat the steps
4 and 5 till theboundary pixels reachedIf getpixel(x,y) = dcol then repeat step 4
and 5
Step 4 − Change the default color with the fill color at the seed point.
SetPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighbourhood points
Page 47 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
FloodFill (seedx – 1, seedy, fcol, dcol) FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol) FloodFill (seedx, seedy + 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol) FloodFill (seedx + 1, seedy + 1, fcol,
dcol) FloodFill (seedx + 1, seedy - 1, fcol, dcol) FloodFill (seedx – 1, seedy - 1,
fcol, dcol)
Step 6 − Exit
The 4-connected pixel technique failed to fill the area as marked in the
following figure which won’t happen with the 8-connected technique.
Inside-outside Test
This method is also known as counting number method. While filling
an object, we often need to identify whether particular point is inside the object
or outside it. There are two methods by which we can identify whether
particular point is inside an object or outside.
Odd-Even Rule
Nonzero winding number rule
Odd-Even Rule
In this technique, we count the edge crossing along the line from any
point x,yx,y to infinity. If the number of interactions is odd then the point x,yx,y
is an interior point. If the number of interactions is even then point x,yx,y is an
exterior point. Here is the example to give you the clear idea −
Page 48 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
From the above figure, we can see that from the point x,yx,y, the number
of interactionspoint on the left side is 5 and on the right side is 3. So the total
number of interaction point is 8, which is odd. Hence, the point is considered
within the object.
Winding Number Rule
This method is also used with the simple polygons to test the given point
is interior or not. It can be simply understood with the help of a pin and a rubber
band. Fix up the pin on one of the edge of the polygon and tie-up the rubber
banding it and then stretch the rubber band along the edges of the polygon.
When all the edges of the polygon are covered by the rubber band, check
out the pin which has been fixed up at the point to be test. If we find at
least one wind at the pointconsider it within the polygon, else we can say that
the point is not inside the polygon.
Page 49 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Give the value 1 to all the edges which are going to upward direction
and all other -1 as direction values.
Check the edge direction values from which the scan line is passing
and sum up them.
If the total sum of this direction value is non-zero, then this point
to be tested is an interior point, otherwise it is an exterior point.
In the above figure, we sum up the direction values from which the
scan lineis passing then the total is 1 – 1 + 1 = 1; which is non-zero.
So the point is said to be an interior point.
Page 50 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
UNIT – III
TRANSFORMATIONS
Translation
A translation is applied to an object by representing it along a straight
line path from one coordinate location to another adding translation
distances, tx, ty to original coordinate position (x,y) to move the point to a
new position (x’,y’) tox’ = x + tx, y’ = y + ty
The translation distance point (tx,ty) is called translation vector or
shift vector. Translation equation can be expressed as single matrix equation
by using column vectors to represent the coordinate position and the
translation vector as
Page 51 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Moving a polygon from one position to another position with the translation
vector (-5.5, 3.75)
Rotations:
A two-dimensional rotation is applied to an object by repositioning it
along a circular path on xy plane. To generate a rotation, specify a rotation
angle θ and the position (xr, yr) of the rotation point (pivot point) about
which the object is to be rotated.
Positive values for the rotation angle define counter clock wise
rotation about pivot point. Negative value of angle rotates objects in clock
wise direction. The transformation can also be described as a rotation about
a rotation axis perpendicular to xy plane and passes through pivot point.
Page 52 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Rotation of a point from position (x, y) to position (x’, y’) through angle θ
relative to coordinate origin
The transformation equations for rotation of a point position P when
the pivot point is at coordinate origin. In figure r is constant distance of the
point positions Ф is the original angular of the point from horizontal and θ is
the rotation angle. The transformed coordinates in terms of angle θ and Ф
x’ = rcos(θ+Ф) = rcosθosФ – rsinθsinФ y’ = rsin(θ+Ф) = rsinθcosФ +
rcosθsinФ
R=𝑐𝑜𝑠∅
P’ = R
Rotation Matrix
−𝑠𝑖𝑛∅
𝑠𝑖𝑛∅
𝑐𝑜𝑠∅
Page 53 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
x’=x.Sx y’ =y.Sy
𝑥′ 𝑥 0 𝑥
𝑦′= 0 𝑆 . (or)
P’ = S. P
Where S is 2 by 2 scaling matrix
Turning a square (a) Into a rectangle (b) with scaling factors sx = 2 and sy =
1.Any positive numeric values are valid for scaling factors sx and sy. Values
less than 1 reduce the size of the objects and values greater than 1 produce
an enlarged object.
There are two types of Scaling. They are
Uniform scaling
Non Uniform Scaling
Page 54 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
To get uniform scaling it is necessary to assign same value for sx and sy.
Unequal values for sx and sy result in a non-uniform scaling.
Matrix Representation and Homogeneous Coordinates
Many graphics applications involve sequences of geometric
transformations. An animation, for example, might require an object to be
translated and rotated at each increment of the motion. In order to combine
sequence of transformations we have to
eliminatethematrixaddition.Toachievethiswehaverepresentmatrixas3X3inste
adof2X2introd using an additional dummy co-ordinate. Here points are
specified by three numbers instead of two. This coordinate system is called
as Homogeneous coordinate system and it allows expressing transformation
equation as matrix multiplication. Cartesian coordinate position (x, y) is
represented as homogeneous coordinate triple(x, y, h)
Represent coordinates as (x, y,h)
Actual coordinates drawn will be (x/h,y/h)
For Translation
Page 55 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
For Scaling
For Rotation
Composite Transformations
A composite transformation is a sequence of transformations; one
followed by the other. We can set up a matrix for any sequence of
transformations as a composite transformation matrix by calculating the
matrix product of the individual transformations
Translation
If two successive translation vectors (tx1,ty1) and (tx2,ty2) are applied to a
coordinate position P, the final transformed location P’ is calculated as
P’ = T(tx2, ty2). {T(tx1, ty1).P}
= {T(tx2, ty2).T(tx1,ty1)}.P
Page 56 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
P’ = R(θ2).{R(θ1).P} = {R(θ2).R(θ1)}.P
By multiplying the two rotation matrices, we can verify that two
successive rotation areadditive
R(θ2).R(θ1) = R(θ1 + θ2)
So that the final rotated coordinates can be calculated with the composite
rotation matrix as P’ = R(θ1 + θ2).P
Scaling
Concatenating transformation matrices for two successive scaling
operations produces thefollowing composite scaling matrix
Translate the object so that the pivot point is returned to its original position
The composite transformation matrix for this sequence is obtain with
Page 57 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Use the inverse translation of step 1 to return the object to its original
position
Page 58 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Concatenating the matrices for these three operations produces the required
scaling matrix Can also be expressed as T(xf, yf).S(sx, sy).T(-xf, -yf) = S(xf,
yf, sx, sy)
Note: Transformations can be combined by matrix multiplication
Other Transformations
Reflection
Shear
Reflection:
A reflection is a transformation that produces a mirror image of an object.
The mirror image for a two-dimensional reflection is generated relative to
an axis of reflection by We can choose an axis of reflection in the xy plane
or perpendicular to the x y plane or coordinate origin.
Page 59 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 60 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 61 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Reflection axis as the diagonal line y = -x
Page 62 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
X - Shear
The x shear preserves the y coordinates, but changes the x values which
causevertical lines to tilt right or left as shown in figure
The Transformations matrix for x-shear is
y’ = y + y shx .x
XY - Shear
The transformation matrix for x y-shear
Page 63 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 64 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Example x’ = x
Y’ = shy (x – x ref) + yShy = ½ and x ref = -1
3D Transformation:
In Computer graphics, Transformation is a process of modifying and re-
positioning theexisting graphics.
3D Transformations take place in a three dimensional plane.
3D Transformations are important and a bit more complex than 2D
Transformations.
Transformations are helpful in changing the position, size, orientation,
Page 65 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Transformation Techniques:
In Computer Graphics, Various techniques are
Translation
Rotation
Scaling
Reflection
Shear
In this article, we will discuss about 3D Translation in Computer Graphics.
3D Translation in Computer Graphics:
In Computer graphics, 3D Translation is a process of moving an object from
oneposition to another in a three dimensional plane.
Consider a point object O has to be moved from one position to another in a 3D
plane.Let
Initial coordinates of the object O = (Xold, Yold, Zold)
New coordinates of the object O after translation = (Xnew, Ynew,
Zold)
Translation vector or Shift vector = (Tx, Ty, Tz)
Page 66 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Tx defines the distance the Xold coordinate has to be moved.
Ty defines the distance the Yold coordinate has to be moved.
Tz defines the distance the Zold coordinate has to be moved
.
Page 67 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 68 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
In Matrix form, the above rotation equations may be represented as,
For Y-Axis Rotation:
This rotation is achieved by using the following rotation equations-
Xnew = Zold x sinθ + Xold x cosθ
Ynew = Yold
Znew = Yold x cosθ – Xold x sinθ
In Matrix form, the above rotation equations may be represented as-
Page 69 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Znew = Zold
In Matrix form, the above rotation equations may be represented as-
3D Scaling in Computer Graphics:
In computer graphics, scaling is a process of modifying or altering the size of
objects.
Scaling may be used to increase or reduce the size of object.
Scaling subjects the coordinate points of the original object to change.
Scaling factor determines whether the object size is to be increased or
reduced.
If scaling factor > 1, then the object size is increased.
If scaling factor < 1, then the object size is reduced.
Page 70 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 71 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
In Matrix form, the above reflection equations may be represented as-
Page 72 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Ynew = -Yold
Znew = Zold
In Computer graphics,
3D Shearing is an ideal technique to change the shape of an existing object in a three
dimensional plane
In a three dimensional plane, the object size can be changed along X direction, Y
direction as well as Z direction.So, there are three versions of shearing:
1. Shearing in X direction
2. Shearing in Y direction
3. Shearing in Z direction
Page 73 of 101
Shearing in X Axis-
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Shearing in Y Axis-
Shearing in Y axis is achieved by using the following shearing equations:
Xnew = Xold + Shx x Yold
Ynew = Yold
Znew = Zold + Shz x Yold
Page 74 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
In Matrix form, the above shearing equations may be represented as-
Shearing in Z Axis-
Shearing in Z axis is achieved by using the following shearing equations-
Xnew = Xold + Shx x Zold
Ynew = Yold + Shy x Zold
Znew = Zold
In Matrix form, the above shearing equations may be represented as-
Page 75 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
UNIT – IV
CLIPPING ALGORITHMS
Page 76 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
In order to maintain the same relative placement of the point in the viewport as
in the window,we require:
Solving these impressions for the viewport position (xv, yv), we have
xv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy .... equation 2
Where scaling factors are
Equation (1) and Equation (2) can also be derived with a set of
transformation that converts the window or world coordinate area into the
viewport or screen coordinate area. This conversation is performed with the
following sequence of transformations:
Perform a scaling transformation using a fixed point position (xw
min, yw min) that scales the window area to the size of the viewport.
Page 77 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 78 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 79 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
1. Visible:
If a line lies within the window, i.e., both endpoints of the line lies within
the window. Aline is visible and will be displayed as it is.
2. Not Visible:
If a line lies outside the window it will be invisible and rejected. Such
lines will not display. If any one of the following inequalities is satisfied, then
the line is considered invisible. Let A (x1,y2) and B (x2,y2) are endpoints of
line. xmin,xmax are coordinates of the window. ymin,ymax are also coordinates
of the window.x1>xmax x2>xmax y1>ymax y2>ymax x1<xmin x2<xmin
y1<ymin y2<ymin
3. Clipping Case:
If the line is neither visible case nor invisible case. It is considered to be
clipped case. First of all, the category of a line is found based on nine regions
given below. All nine regions are assigned codes. Each code is of 4 bits. If both
endpoints of the line have end bits zero, then the line is considered to be visible.
The centre area is having the code, 0000, i.e., region 5 is considered a rectangle
window.
Page 80 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 81 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
If And ≠ 0000
Then the line is invisibleElse
And=0000
Line is considered the clipped case.
Step4: If a line is clipped case, find an intersection with boundaries of the
windowm=(y2-y1 )(x2-x1)
a) If bit 1 is "1" line intersects with left boundary of rectangle window
y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window
Page 82 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 83 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Ym=(y1+y2)/2
Xmis midpoint of X coordinate. Ymis midpoint of Y coordinate.
Step5: Check each midpoint, whether it nearest to the boundary of a
window or not.
Step6: If the line is totally visible or totally rejected not found then repeat
step 1 to 5.
Step7: Stop algorithm.
Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-
ordinates of A (-4, 2) and B (-1, 7). Does this line visible. Find the visible
portion of the line using midpoint subdivision?
Solution:
Step1: Fix point A (-4, 2)
Page 84 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
So B""to B length of line will be clipped from upper side Now considered left-
hand side portion
A and B""are now endpoints
Find mid of A and B""
Page 85 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
A (-4, 2) B ""(-1, 6)
Page 86 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 87 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
If the first vertex of the edge is outside the window boundary and the second
vertex of the edge is inside then the intersection point of the polygon edge with
the window boundary and the second vertex are added to the output vertex list
(See Fig. m (a)).
If both vertices of the edge are inside the window boundary, only the
second vertex is added to the output vertex list. (See Fig. m (b)).
If the first vertex of the edge is inside the window boundary and the
second vertex of the edge is outside, only the edge intersection with
the window boundary is added to the output vertex list. (See Fig. m
(c)).
If both vertices of the edge are outside the window boundary, nothing
is added to the output list. (See Fig. m (d)).
Once all vertices are processed for one clip window boundary, the output
list of vertices is clipped against the next window boundary. Going through
above four cases we can realize that there are two key processes in this
algorithm.
Page 88 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 89 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 90 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Solution:
Original polygon vertices are V1, V2, V3, V4, and V5. After clipping each
boundary thenew vertices are as shown in figure above.
Page 91 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
UNIT V
HIDDEN SURFACE ALGORITHMS
Hidden Surface Elimination
1. One of the most challenging problems in computer graphics is the
removal of hiddenparts from images of solid objects.
2. In real life, the opaque material of these objects obstructs the light rays
from hiddenparts and prevents us from seeing them.
3. In the computer generation, no such automatic elimination takes place
when objectsare projected onto the screen coordinate system.
4. Instead, all parts of every object, including many parts that should be
invisible aredisplayed.
5. To remove these parts to create a more realistic image, we must apply a
hidden line orhidden surface algorithm to set of objects.
6. The algorithm operates on different kinds of scene models, generate
various forms ofoutput or cater to images of different complexities.
7. All use some form of geometric sorting to distinguish visible parts of
objects from thosethat are hidden.
8. Just as alphabetical sorting is used to differentiate words near the
beginning of thealphabet from those near the ends.
9. Geometric sorting locates objects that lie near the observer and are
therefore visible.
10. Hidden line and Hidden surface algorithms capitalize on various forms of
coherence toreduce the computing required to generate an image.
11. Different types of coherence are related to different forms of order or
regularity in theimage.
12. Scan line coherence arises because the display of a scan line in a raster
image is usuallyvery similar to the display of the preceding scan line.
13. Frame coherence in a sequence of images designed to show motion
recognizes thatsuccessive frames are very similar.
Page 92 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 93 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 94 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
1. Sorting:
All surfaces are sorted in two classes, i.e., visible and invisible. Pixels are
coloredaccordingly.
Several sorting algorithms are available i.e.
Bubble sort
Page 95 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Shell sort
Quick sort
Tree sort
Radix sort
Different sorting algorithms are applied to different hidden surface
algorithms. Sorting of objects is done using x and y, z co-ordinates. Mostly z
coordinate is used for sorting. The efficiency of sorting algorithm affects the
hidden surface removal algorithm. For sorting complex scenes or hundreds of
polygons complex sorts are used, i.e., quick sort, tree sort, radix sort.
For simple objects selection, insertion, bubble sort is used.
Coherence
It is used to take advantage of the constant value of the surface of the
scene. It is based on how much regularity exists in the scene. When we moved
from one polygon of one object to another polygon of same object color and
shearing will remain unchanged.
Types of Coherence
Edge coherence
Object coherence
Face coherence
Area coherence
Depth coherence
Scan line coherence
Frame coherence
Implied edge coherence
a) Edge coherence:
The visibility of edge changes when it crosses another edge or it also
penetrates a visible edge.
Page 96 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
b) Object coherence:
Each object is considered separate from others. In object, coherence
comparison is done using an object instead of edge or vertex. If A object is
farther from object B, then there is no need to compare edges and faces.
c) Face coherence:
In this faces or polygons which are generally small compared with the size
of the image.
d) Area coherence:
It is used to group of pixels cover by same visible face.
e) Depth coherence:
Location of various polygons has separated a basis of depth. Depth of
surface at one point is calculated, the depth of points on rest of the surface
can often be determined by a simple difference equation.
f) Scan line coherence:
The object is scanned using one scan line then using the second scan line.
The interceptof the first line.
g) Frame coherence:
It is used for animated objects. It is used when there is little change in
image from oneframe to another.
h) Implied edge coherence:
If a face penetrates in another, line of intersection can be determined from
two pointsof intersection.
Algorithms used for hidden line surface detection
Back Face Removal Algorithm
Z-Buffer Algorithm
i. Back Face Removal Algorithm
It is used to plot only surfaces which will face the camera. The objects on
the back side are not visible. This method will remove 50% of polygons from
the scene if the parallel projection is used. If the perspective projection is used
Page 97 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
then more than 50% of the invisible areawill be removed. The object is nearer to
the center of projection, number of polygons from the back will be removed.
It applies to individual objects. It does not consider the interaction
between various objects. Many polygons are obscured by front faces, although
they are closer to the viewer, so for removing such faces back face removal
algorithm is used.
When the projection is taken, any projector ray from the center of
projection through viewing screen to object pieces object at two points, one is
visible front surfaces, and another isnot visible back surface.
This algorithm acts a preprocessing step for another algorithm. The back
face algorithm can be represented geometrically. Each polygon has several
vertices. All vertices are numbered in clockwise. The normal M1 is generated a
cross product of any two successive edge vectors. M1represent vector
perpendicular to face and point outward from polyhedron surface
N1=(v2-v1 )(v3-v2)
If N1.P≥0 visible
N1.P<0 invisible
Advantage
It is a simple and straight forward method.
It reduces the size of databases, because no need of store all surfaces
in the database,only the visible surface is stored.
Repeat for all polygons in the scene.
Do numbering of all polygons in clockwise direction i.e.v1 v2 v3 vz
Calculate normal vector i.e. N1 N1=(v2-v1 )*(v3-v2)
Consider projector P, it is projection from any vertex Calculate dot
product Dot=N.P
Test and plot whether the surface is visible or not.
If Dot ≥ 0 then surface is visibleelse
Not visible
Page 98 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023
Page 99 of 101
STUDY MATERIAL FOR B.C.A
COMPUTER GRAPHICS
SEMESTER – VI, ACADEMIC YEAR 2022-2023