0% found this document useful (0 votes)
52 views16 pages

Computer Graphics

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 16

Q.What is Computer Graphics ?

Ans- It is branch of computer science that deals with image ,figure,drawing and there analysis .

Computer Graphics means drawing the picture artificial by setting the pixel with different color.For doing
this we need lots of math calculation .it also deals - 1)makes a 3D picture and 2D in screen .
2)Gives the affect of light 3) What should be the technique so that the object since to be a soft or hard object.
4)Generating shadows

Q.Why Computer Graphics is used ?


Ans-Suppose a sell phone manufacturing company wants to show the sell of mobile for 5 years for this last
amount of information is to store an lot of time and memory will be needed and also difficult to understand
by a common man .
In this situation graphics is better alternative using graphics,graph,chart,different Graphics
analysis tool are used to data in pictorial form,that can be understood easily just with a simple loop.

Q.Different arise of computer Graphics : Computer Graphics

Generative Images Analysis Cognitive


Graphics (Used to generating picture image) (Used for photographic images)
(Used to create ,line,circle ,ellipse)

 Advantage of Computer Graphics : 1)Enhanced Visual Communication 2) Realistic virtual Experiences


3)Creative Design possibilities . 4)Time saving productivity 5)Improved data visualization 6) Iterative user
interface. 7)High quality Digital Art .

 Disadvantage of Computer Graphics :1)Eye strain and Fatigue 2)Limited Artistic Expression 3) High
resources requirement 4)Potential for addiction 5)Lack of tactile Experience 4)Impact on social
Interaction
 Application of Computer Graphics : 1)Computer Aided Design : for engineering and architectural system
2) Entertainment : Motion picture ,music,video ,computer games ,TV shows continuesly entertain us .
3) Education and training :Training with computer generate model for specified system.
4) Visualization :for analysis ,scientific,engineering ,medical and business data or behaviour computer
graphics produce different visual tool.
5) Presentation Graphics : To provide illustration and summarize various type of data .
6) Image processing : Computer Graphics helps in image processing and provide different technique to
modify or interpret existing picture .it is mainly used in medical application.
7) Computer Art : Using different printing packages with coddles,pressure sensitive stylus ,artist can be
produce electronic printing .
 Type of Computer Graphics : Basically computer graphics is of two type-1) 2)
1) Interactive Compute graphic : involve two way communication between computer and user here the
observe is given some control over the image by providing him with the input device that user can make any
changes in the produce image ,Example -Computer games Real life example-,pilot of a train

2) Non interactive Computer Graphic : it is known as passive computer graphic in which user does not have
any kind of control over the image.The image is totally under the control of programming instruction not
under the user .Example- screen sever ,Washing Machine.

 Advantage of Interactive Compute graphic : 1)High Quality 2) Produce more precise result or product
3)Better Productivity 4)Lower analysis and designing art

 Basic component of interactive Computer Graphics : 1) Input device 2)Processing Device


3) Display or output device

 Conceptual frame work for interactive computer graphics :

 Example of Computer Graphic Packages :Logo , Auto CAD,Corel Graphics ,meta file etc .
 Computer Graphics VS Image Processing ?
Ans- Computer Graphics differs from images processing in the sense image processing starts after the image
is in image space (frame buffer)where as computer graphics starts with drawing of the object .

Basically image processing means pixel ,based on operation on an already existing image and generates a
new image .
 Computer Graphics VS Animation ?
Ans- Computer graphics differs from animation because animation start with an motion of an image through
animation is closely related with computer graphics,still there are fer differences computer animation means
-generating graphical object in such a way that there is a motion in the picture sequence of picture generated
by computer graphics can generate a motion.

 Pixel : The smallest individual unit of a image is called Pixel.A Pixel is one of many tiny dots that makes
up representation of a picture in computer memory.

 Resolution : The quality of most graphics devices is determine by there resolution .That is how many
pixel pass to arranged they can represented and there color capability . It quantifies how closer line can
be visible to each other. Higher resolution means more clear and image and lower resolution
means hazy/haze and overlapping image.

Q. What is Aspect ratio ?


Ans-It is a ratio of width to its height of a computer screen .it measure the unit in length or number of pixel
Aspect ratio = width unit /height unit.

 Aspect Ratio:It is the ratio of number of pixel present horizontally and number of pixel present vertically.
 Resolution:-It is defined as the number of pixel present in the emit area.

Q.What is Persistence ?
Ans-Different kind of phosphore used in CRT an major different is there persistence that is how long they
continue to emit light after the CRT beam is removed.

Q.What is refresh Rate ?


Ans-An image appear on the screen when electron beam stricte on the surface of the screen in Zig-Zag
pattern .The Refresh Rate is the number of times a screen is redrawn in one second and it is measure in
haze .
Q.What is Bit Map ?
Ans- It is a Bit Array . A bit Map is a type of memory organization and image file format used to store digital
image .
Q.What is Frame Buffer ?
Ans- It is a large contiguous piece of memory ,at a minimum there is an memory bit for each pixel .
This amount of memory is called bit plate .The picture is build up in the frame buffer 1 bit at a time.

 Dot Per Inch (DPI ) :


Q.How many bits are required for 512 X 512 raster display with each pixel represented by 3 bit ?
Ans- 512 X 512 X 3 =786432 bit
Q.Find the DPI where resolution is 720 X 1024 and each inch contain 56 pixel and each pixel represented
in 4 bit ?
Ans- Resolution of the screen is =720 X 1024 =737280
DPI = Per inch contain 56 pixel and each pixel contain 4 bit
DPI=56 X 4 =224
Q.What is Morphing ?
Ans - Morphing is an animation function which is used to transform object shape from one from to another is
called Morphing .This function commonly used in movies ,cartoons ,advertisement ,and computer games etc .
Q.What is RLC (Run length coding )
Ans- RLC stand for Run length coding. It is a technique for used image data .
Q. What is Pix Map ?
Ans- Some system has multiple bit per pixel the frame buffer is offers refers to as pix map .
 Display Processor : It is a interpreter or piece of hardware that convert display processor code into
picture .It is one of the 4 main parts of display units . A display processor consist of -
1)Display file memory 2) Display Processor Unit. 3)Display Generator 4)Display Console

Fig :Block diagram of display system


 Cathode Ratio : The primary output device in graphical system is the video monitor .The main element
of a video monitor is cathode Ray Tube .Shown in the following picture -
The operation of CRT is very
simple i.e -
1) The electron gun emites a beam of
electrons (cathode rays )

2) The electron beam passes through


focusing an deflection system that
direct it toward specified position
phosphor coated screen .

3) When the beam heats the screen


the phosphor emits a small spot of
light of each position ,constructed by
the electron beam.

4) The light emited by phosphore


fades very rapidly ,so it needs to
redraw the picture repeatedly .
So it redraw the picture by directing
Fig : Cathode Ray Tube
the electron beam back over the
same screen point quickly.

 Different Scan technique :-There are 2 kind of redraw mechanism .Raster & Random scan display
1)Raster Scan Display:The architecture consist of display controller CPU,video controller,refresh buffer ,I/O
device.

I. The display image is store in the form of 0 and 1 in the refresh buffer .
II. The video controller read the refresh buffer and produces the actual image on the screen

III. Then a video controller is used here to scan each and every line of the refresh buffer (Top to
Bottom).This process is called refreshing .
IV. Each complete scanning of the screen called refreshing.
V. The line are scan from left to right and again the controller moves to the next line and scan the new line
from left to right and so on.
“When the beam is move left to right it is on .when it is moves back from right to left it is off”.

VI. When the beam reaches to the bottom of the screen it rapidly redirect back to the top left of the screen.
VII. Then a from buffer memory which hold the coordinate of the screen point is used to determine the actual
coordinate of the CRT.After that actual image is produce in CRT.
A display Process/Produce in this way is called Raster scan display .

2) Random Scan Display /Vector Display /Strop writing Display /Calligraphic Display :

o In this technique the electron beam is directed by only to the part of the screen where the picture is to
be drawn rather than scanning from left to right and top to bottom. As in raster display.
o The component line of picture can drawn and refresh by random scan system in specified Manner.
o Picture definition is now store as a set of line drawing command in refresh buffer or refresh display
file
o To display a specified picture the system cycle through set of command in the display file drawing
each component line in term after all line drawing command have been process the system cycle back
to the first line command in the least.

 Note Random Scan display is design to draw all the component lines of a picture 30 to 60 time in each
second .

Random Scan Display Raster Scan Display


1. It has high Resolution 1. Its resolution is low
2. It is more expensive 2. It is less expensive
3. Any modification if needed is easy 3.Modification is tough
4. Solid pattern is tough to fill 4.Solid pattern is easy to fill
5.Only screen with view on an area is displayed. 5. Whole screen is scanned.
6.It is restricted to line drawing applications 6.It is suitable for realistic display.

 Color CRT Monitor : A color CRT monitor display color picture by using a combination of
phosphor .That emit different color light by combining the emited light a range of color can be generated .
There are 3 method for color CRT 1) Beam Penetration Method 2) Shadow Mask Method

1) Beam Penetration Method:-In this method 2 layers of phosphor are coated inside the CRT screen .
I) One layer is for Red Phosphor . II)Another layer is for Green Phosphor.
When the electron beam falls on the phosphor the color of the pixel depends on the penetration power of the
electron beam.
o I f the power of the electron beam is slow or low then it penetrate only the red layer.(Outer)
o If the power of the electron beam is fast or high then it reaches to the inner most layer and excites
the green phosphor .
If the electron beam power is medium it shows the combination of red and green generally orange and
yellow.
If electron beam power is controlled by controlling the voltage of the electricity that generate different
intensities.

 Advantage : 1)les Expensive

 Disadvantage : 1)Display only 4 color 2)Quality of images are not so good .


2) Shadow Mask Method :
The shadow mask CRT has 3 phosphor color dot
at each pixel position this 3 phosphor emits 3
different lights i.e Red,Green and blue .This type
of CRT has 3 electron gun for 3 dots and one
greed with number of tiny holes is placed just
before the phosphor coating .This greed is called
shadow Mask.

When 3 electron gun emits 3 electron beam ,the


beams passes through a hole
with shadow mask greed and heats the phosphor
coat .This phosphore dots are arranged such a
way that the corresponding dots activates Its own dot .The variation of color can be obtained by the
combination of 3-basic color .Since 3 dots are placed very closely our eyes can’t separate the different color
in a single delta (Δ) instead it shows the combination color.using this technique following colors are found -
Red Green Blue Produced Color
OFF OFF OFF Black
OFF OFF ON Blue
OFF ON OFF Green
OFF ON ON Cyan
ON OFF OFF Red
ON OFF ON Maganda
ON ON OFF Yellow
ON ON ON White
Q.What is RGB true color System ?
Ans-Instead of ON and OFF RGB true color system - Is used different integrity of electron.Beam to produce
several color.
High quality raster graphic system uses 256 different voltage level including ON and OFF .
In this case total number of color can be produce after combining 3 dots are of different intensities is -
256 for Red X 256 Blue dots X 256 for Green dots
= 2 8 X 2 8 X 2 8 = 2 24 ≈ 17/16,777216 millions of color for each pixel . And

 Graphic Hardware : Graphics Hardware is of two type

Q.A raster scan has resolution(640 X 480) compute the size of the frame buffer (byte) t0 store 24 bit
/pixel.
Ans- For one pixel = 24 bit and Resolution of the screen =640 * 480
.: Total no of pixel on the screen=640 * 480 .: no of bits per pixel =24
So, size of the frame buffer =640 x 480 x 24 bit
= 640 x 480 x 24 / 8= 21600
8
Q.Consider a resolution size 12 x 12 inch with resolution 50 pixel/square inch .How many storage do we
need for frame buffer ,if we need for frame buffer we want to store 16 bits/ pixel.
Ans- .: Size of the screen = 12 x 12 = 144 inch
Resolution per square 50
.: Total no of pixel on the screen =12 x 12 x50
No of bit per pixel =16
.: Size of the frame buffer = 12 x 12 x 50 x 16 =12 x 12 x 50 x2 =14400
Q.A frame buffer has a size 1024 x 1024 with 10 bits/pixel compute the time required to load it ,if the
transfer rate is 10 bits /second .
Ans- .: Resolution of the screen =1024 x 1024
No of bit per pixel =10
Size of the fram buffer = 1024 x 1024 x 10 bits
No of bits loaded per second =10
Time required to load = 1024 x 1024 x10 = 1024 x1024 second
10
Q.A raster system resolution 1024 x 768 and refresh rate is 69 Hz .How many pixel could be access per
second .
Resolution of the screen =1024 x 768
Refresh rate =60 Hz (This implies each pixel on the screen freshed 60 times within a second )
.: Total no of pixel accessed in one second =1024 x 768 x 60
Q.Resolution =1024 x 1024 ,Refresh rate =60Hz ,Horizontal retrace time =400 μs (micro second)
Vertical retrace time = 4 μs Compute time spent to return the election beam per frame .
Total Retrace time= 400 + 4 =404 μs
.: Refresh rate =60Hz
.: Time required to retrace one frame buffer =404 = 6.74 μs
60
Q.Calculate the time spent in scanning each row of pixel in a raster system of resolution 680 x 420 and
refresh rate of 50 frame /second.
Ans- Resolution of raster system = 680 x 420
Refresh rate -50 frame /second
.: Refresh rate of 50 frame =1 second and Time required of 1 frame = 1/50
.: Time required to scan each row = 1/50 x 420 = 8.4 second

 Scan conversion : It is a process of representing graphics object to a collection of pixel .


The graphics objects are continuous but the pixel are discrete and each pixel can have either on or off state
In conversion the circuitry of the video display device is capable for converting binary values into a pixel on
and pixel off information using this ability computer graphics represent picture having discrete dot. For
generating graphical object (I.e point .line ,circle ellipse ) many algorithm have been developed

The application of scan conversion is video projectors ,cinema equipment,standard and HDTV
television,LCD monitors,radar display etc.

There are two method for scan conversion:-


1)Analog Methods:- In this method,the conversion is done using large numbers of delay cells and is
appropriate for analog video.
2)Digital Method: In this method,the picture is stored in frame buffer with x1 speed and is read with x2
speed
 Advantage of developing algorithm for scan conversion :_
1) Algorithm can generate graphics object as a faster rate .
2)Using algorithm memory can be used efficiently
3)Algorithm can develop a higher level of graphical object .

Example of object which can be scan converted -


1) Point 2 ) Line 3) Sector 4)Arc 5) Ellipse 6) Polygon 7)Rectangle 8)Character 9)Filled regions

 Scan converting a Point : Point platting is done by converting a single cor-ordinate position furnished
by an application program into appropriate operation which the output device is used scan converting a
point involves eliminating the pixel x that contains that point .
 Scan converting a straight line : A straight line may be define by two end points and an equation .In the
following figures two end points are described by (x2,y2).
The equation of the line is used to determine(x,y)coordinate of all the points that lies b/t these two end
points. y

ΔY
 Properties of good drawing algorithm:
1) Line should be appear straight .we must appropriate the line by choosing addressable points closed to it .If
we choose well the line will appear straight .If not we shall produced cross line.
2) Line should timing accurately.Unless lines are plotted accurately ,they may terminate at the wrong place
3) Line should have constant density .Line Density is proportional to the number displayed divided by the
length of line 4)Line density should be independent of line length and angle 5)Line should be drawn rapidly.

 Algorithm for line Drawing : 1)Direct use of line algorithm o Y=mx+c


2) Digital differential analyzer algorithm (DDA) o Y-Y1= Y2-Y1 (x-x1)
3)Bresenham’s line drawing algorithm. X2-x1
o X + Y =1
 Digital differential Analyzer (DDA) Algorithm : a b
1. What is Line ? 2) Line Equation 3)Slop of line : 3)Example of line drawing , DDA

1) What is Line ?
Ans- Line is define as a set of points or collection of points .
2) Line Segment: It is confined by two points
3) Line Equation : Commonly Known line equation is Y=mx+c - Interrupting point over Y axis
Slop(m) = Δy = difference of y
Δx difference of x
If ,we know the slop and Y intercept of the line then ,we can find any point of the line (if two end points are
given) As for example if x=10 the point can be derived as Y=mx+c=10m +c
 Y-Y1=Y2-Y1 (X-X1)
X2-X1
 X+ y =1 where a=x intercept and b=y -intercept
a b
 In computer graphic we used only the 1st one that is Y=mx+C
 Slop of Line :-

SO,the distance between X1 and X2 is defined as dx = Δx = (X2-X1)


Similarly =dy=Δy=(Y2-Y1)
It is seen that here a right angle triangle is formed and the opposite angle of the right angle is Θ ,SO the slop
is defined as,
Slop (m)= Δy This is opposite
Δx This is adjacent respect to angle Θ
So, that slop in nothing bu tan Θ = Opposite .: m = tan Θ
Adjacent .
 Drawing a Line :
1)Case -I :-

2)Case -II :

3)Case -III :

Q.Draw the line segment with given n point (x1 ,y1) = 2, 2 , (x2 , y2) = 9,2
Ans- For finding all the points o f the line ,we first find Δx and Δy
Different of x (Δx) =x2 -x1 =9-2 = 7
Different of y (Δy) =y2 -y1 =2-2 = 0
Here ,Δx >Δy .: Number of steps = 7
Slop (m)= Δy = 0 = 0 = tan 0
Δx 7
X increment =Different of x = 7 =1
Number of steps 7
Y increment = Different of y = 0 = 0
Number of steps 7
.: The co-ordinates of points are - X 2 3 4 5 6 7 8 9
When m=0 Y 2 2 2 2 2 2 2 2
X increment =Xk+1
And Y increment = Yk
Q.Draw the line segment with given n point (x1 ,y1) = 2, 5 , (x2 , y2) = 2,12
Ans- (Δx) =x2-x1 =2-2 = 0
(Δy) = y2-y1=12-5 = 7
Slop (m) = Δy = 7 = Θ > 1
Δx 0
No of step = Max (Δy, Δx )
= Δy =7
X increment = Δx = 0 =0
No of step 7
Y increment = Δy = 7 =1
No of step 7 x 2 2 2 2 2 2 2 2
.: The co-ordinates of points are y 5 6 7 8 9 10 11 12
When m > 1
X increment = xk and Y increment =Yk+1
Q.Draw the line segment with given n point (x1 ,y1) = 5, 4 , (x2 , y2) = 12,7
(Δx) =x2-x1 =12-5 = 7
(Δy) = y2-y1=7-4=3
Slop (m) = Δy = 3 = 0.43
Δx 7
No of step = Max (Δy, Δx )
= Δx =7
X increment = Δx = 7 =1
No of step 7
Y increment = Δy = 3 = 0.43
x 5 6 7 8 9 10 11 12
No of step 7
.: The co-ordinates of points are - y 4 4.43 4.86 5.28 5.72 6.58 7.01 7.44
When m < 1 R(y)=
X increment = xk+1 and Y increment =Yk+m
Q.Draw the line segment with given n point (x1 ,y1) = 5, 7 , (x2 , y2) = 10,15
Ans-
(Δx) =x2-x1 =10-5 = 5
(Δy) = y2-y1=15 - 7 = 8
Slop (m) = Δy = 8 = 1.6
Δx 5
No of step = Max (Δy, Δx )
= Δy =8
X increment = Δx = 5 = 0.63
No of step 8
Y increment = Δy = 8 =1
No of step 8 x 5 5.62 6.25 6.88 7.51 8.14 8.77 9.4 10.03
.: The co-ordinates of points are y 7 8 9 10 11 12 1 14 15
When m > 1 R(X)=
X increment = xk +1/m and Y increment =Yk+1
Q.Draw the line segment with given n point (x1 ,y1) = 12, 9 , (x2 , y2) = 17 ,14
(Δx) =x2-x1 =17-12 = 5
(Δy) = y2-y1=14-9 = 5
Slop (m) = Δy = 5 = 1
Δx 5
No of step = Max (Δy, Δx ) = 5
X increment = Δx = 5 =1
No of step 5
Y increment = Δy = 5 =1
No of step 5
x 12 13 14 15 16 17
.: The co-ordinates of points are
Y 9 10 11 12 13 14
When m = 1
X increment = xk +1 and Y increment =Yk+1
 Advantage of DDA:- 1)It is simplest algorithm and easy to implement. 2)DDA is faster method than
direct method of line drawing 3)DDA does not use multiplication theorem.
 Disadvantage of DDA:-1)Floating point arithmetic in DDA algorithm is still time consuming
 DDA Algorithm :
DDA _Algo (x1 ,y1,x2,y2)
{
Δx=x2-x1;
Δy=y2- y1 ;
/* No of steps calculation */
If (abs (dx) > abs (dy))
{
Steps =dx ;
}
else
{
Steps =dy ;
}
/* calculation of x-increment & y-increment */
Y-increment = dx = // float (steps);
Steps
X-increment = dy = // float (steps) ;
Steps
putpixel (Round (x1) ,Round (y1) );
for ( i = 1 ; i< steps ; i++)
{
x1= x + x- increment ;
Y1=y+y -increment ;
putpixel (Round (x1) ,Round (y1)) ;
}}
 Derivation of DDA Algorithm : The digital differential analyzer or DDA algorithm is very simple
algorithm for straight line drawing .This is the basic algorithm for drawing a line .

We know that the line equation for the straight line is y=mx+c where m is the slop or gradient of the line and
c is the interception point to y-axis . If (x1 ,y1) and (x2 , y2) be two end points of the line segment then :
Difference of x= Δx = x2 -x1 And difference of y = Δy = y2-y1
So, m can be written as ,
M= Y2 -Y1 = Δ y
X2- X1 Δx
So ,the slop can be lays between 0< m< 1.
 Case-1 : slope m< 1 , i.e m< tan 45 then
the coordinate x is calculate as X k+1 = X k+1 i.e x is incremented by 1
and y is calculated as Y k+1 = Yk +m
 Case-2 : slop m > 1 i .e m > tan 45 then
The coordinate are calculated as Yk+1 =Yk+1 and Xk+1 = Xk + 1
M
 Case -3 : slop m=1 i.e m=tan 45 i.e θ = 45 then the coordinates are calculated as Xk+1 = Xk+1 and
Y k+1 = Yk +1

 Bresenham's line drawing algorithm :


 Basic , Drawback of DDA ,Problem with floats ,Derivation of Bresenham’s , Algorithm ,Example-
The basic line drawing equation is Y=mx +c
In Bresenham's it can be written as -
Y =m (Xk +1) +c

From the above picture distance d1 from the


S pixel i.e d1= actual value of Y- Yk

Similarly distance d2 from the T pixel i.e d2 = Yk+1 -y

If (d1 -d2) <0 means closer to Yk point


If (d1 -d2) > 0 means closer to Yk+1 point
Difference between d1 and d2 is defined as decision parameter Pk
Therefore the coordinates are calculated as if Pk <0 then Pnext =Pk+ 2 Δy = Pk +1

Pk >0 then Pnext = Pk +2Δy - 2Δx


For initial value i.e Pk = P1 = 2Δy - Δx

 Bresenham's line drawing algorithm Pseudocode of Bresenham's line drawing algorithm


Step -1 : Assign x= x1
Y=y1
Step-2 : Find the decision parameter value
P initial = 2Δy- Δx
Where Δy =Y2 -Y1
Δx =x2 -x1
Step -3 : If Pk > =0
Pk+1 = Pk + 2Δy -2Δx ;
Xnext = X+1 ;
Ynext =Y+1 ;
Step -4 : if Pk <0
Pnext =Pk +2Δy ;
Xnext = x+1 ;
Ynext = Y; [No need to increment
the value of Y if remain same ]

Q. Draw a line segment with point P1( 1,1) and P1 (8, 5) using Bresenham’s line drawing Algo.
Here x= 1 x2= 8 Δx = x2 -x1 = 8-1 = 7
Y=1 y2=5 Δy=Y2-Y1 = 5-1 = 4
Decision parameter i.e Pinitial = 2Δy - Δx = 8- 7= 1
X Y P P= 2dy -dx
1 1 1>0
2 2 Pk=P+2Δy-2Δx = 1+8-14= - 5<0
3 2 Pk=P +2Δy=-5 +8 = 3>0 When , p < 0
4 3 Pk=P+2Δy -2Δx=3+8 -14 =-3 <0 P=P+ 2dy
5 3 Pk=P+ 2Δy= -3 +8= 5 <0 X++
else
6 4 Pk= p+2Δy-2Δx= 5+8 -14= -1<0
P=P+ 2dy -2dx
7 4 Pk=p+2Δy= -1 +8= 7>0
X++ , y++
8 5 Pk=p+2Δy-2Δx=7+8-14 =1>0
Q. Plot a line from (0,0) to (10 , 6) using Bresenham’s line drawing Algorithm .
Here x1= 0 x2= 10 Δx = x2-x1= 10 -0 =10
Y1=0 y2= 6 Δy= y2-y1 = 6-0 = 6
Decision parameter P initial = 2Δy -Δx = 12 -10 = 2
X Y P P= 2dy -dx
0 0 2> 0
1 1 Pk=P+2Δy-2Δx =2+12-20=-6 <0 When , p < 0
2 1 Pk=P+ 2Δy =-6 + 12=6>0 P= 2dy 2dy
P=P+ -dx
3 2 Pk=P+2Δy-2Δx =6 +12-20 =-2 <0 X++
4 2 Pk=P+ 2Δy = -2 + 12= 10>0 When
else , p < 0
5 3 Pk=P+2Δy-2Δx =10 +12-20 =2>0 P=P+
P=P+2dy2dy -2dx
6 4 Pk=P+2Δy-2Δx =2+12-20=-6 <0 X++
X++ , y++
7 4 Pk=P+ 2Δy =-6 +12=6 >0 else
8 5 Pk=P+2Δy-2Δx = 6+12-20 = -2 <0 P=P+ 2dy -2dx
X++ , y++
9 5 Pk=P+ 2Δy = -2 -12 =10 >0
10 6 Pk=P+ 2dy -2dx =10+12-20 = 2>0
Q. Draw a line segment with point ( X1,Y1)= (9, 18) and ending coordinate (X2 ,Y2) =(14, 22)
using Bresenham’s line drawing Algorithm .
Here x1=9 x2=14 Δx = x2-x1= 14- 9 =5
Y1=18 y2=22 Δy= y2-y1 = 22-18 =4
Decision parameter P initial = 2Δy -Δx = 8-5 = 3
X Y P
9 18 3>0
10 19 Pk=P+ 2dy -2dx = 3+8 -10 = 1 >0
11 20 Pk=P+ 2dy -2dx = 1 + 8 -10 =-1 <0
12 20 Pk=P+ 2dy =-1 + 8 =7>0
13 21 Pk=P+ 2dy -2dx = 7 +8 -10 =5 >0
14 22 Pk=P +2dy -2dx=5 +8 -10 =3>0
Q. Draw the line from (20, 10) to (30 , 18 ) using Bresenham’s line drawing Algorithm .
Here x1= 20 x2= 30 Δx = x2-x1= 30 - 20 = 10
Y1= 10 y2= 18 Δy= y2-y1 = 18 -10 = 8
Decision parameter P initial = 2Δy -Δx = 16-10 =6
X Y P
20 10 6 >0
21 11 Pk=P+ 2dy -2dx = 6 + 16 -20 =2 >0
P= 2dy -dx
22 12 Pk=P+ 2dy -2dx =2 +16 -20 = -2 < 0
23 12 Pk=P+ 2dy = -2 +16 = 14 >0
When , p < 0
24 13 Pk=P+ 2dy -2dx = 14 +16 -20 = 10 >0
P=P+ 2dy
25 14 Pk=P+ 2dy -2dx =10 +16-20 =6>0
X++
26 15 Pk=P+ 2dy -2dx = 6 +16 -20 =2 >0 else
27 16 Pk=P+ 2dy -2dx =2 +16 -20= -2 <0 P=P+ 2dy -2dx
28 16 Pk=P+ 2dy = -2 + 16 = 14 >0 X++ , y++
29 17 Pk=P+ 2dy -2dx = 14 + 16 -20 =10 >0
30 18 Pk=P+ 2dy -2dx 10 + 16 -20 = 6>0

Bresenham’s algorithm DDA Algorithm


1)Bresenham's line drawing algorithm uses fixed 1)DDA algorithm uses floating point that is real
point i.e integer arithmetic arithmetic .
2)Bresenham's line drawing algorithm uses 2) DDA algorithm uses multiplication division in its
subtraction and addition in its operation. operation .
3)Bresenham's line drawing algorithm is more 3)DDA algorithm is not accurate .
accurate than DDA.
4)Faster than DDA 4) Include floating point operation hence slow
5)It is raster line generation algorithm 4) It is scan conversion line algorithm .
 Circle Drawing algorithm :
 Define a Circle -Circle is a 8 base symmetric figure .the shape of the circle is same in all quadrants in
each quadrant there are two octant if we calculate all the points of one octant than other point of 7
octant can be calculated easily by the concept of
8 base symmetric .

Let the given point on the circle is P1 =(X,Y) assume


the center of the circle is in origin (0,0)
than other 8 symmetric points will be -

P1 =(y , x) p5=(-y ,-x)


P2=(x , y) P6=( -x, -y)
P3=(x ,-y) p7= (-x, y)
P4=(y ,-x) P8=(-y, x)

Q. (2,7) is a point on a circle then determine the other point of all octant of a circle
Ans- P1 =(2 , 7) p5=(-2 , -7)
P2=(7 , 2) P6=( -7, -2)
P3=(7 ,-2) p7= (-7, 2)
P4=(2 ,-7) P8=(-2, 7) The 7 point are calculated by using the property of reflections .The
reflection is accomplished in the following way .

P= 2dy -dx
 There are two standard method that mathematically defined a circle centre at origin -
1) Define a circle using polynomial method 2)Define a circle using polar co-ordinate .

1)Define a circle using polynomial method : These method define a circle with the second order
2
polynomial equation that is - Y = r 2 - x 2 Where x= point on x coordinate Y= point on y coordinate
R=radius of circle
2)Define a circle using polar co-ordinate : The second method of define of circle make using the polar
coordinate - i.e x= r cos θ where θ = current angle
Y= r sin θ r = circle radius Sin θ = Y
r
Cos θ = x
r

 Mathematical Definition of circle -Assume that the centre of the circle is an origin
2
The equation of the circle is Y + X 2= a2 -
where a = radius of the circle and (x,y) are
the different coordinate which are relevant
to draw a circle
Let as try to find out x and y coordinate in the
90 o to 45 0 or 45 0 to O0 sector .
 Midpoint circle drawing Algorithm : It is based on the relationship between arbitrary point (x,y) and
the radius - f (x ,y) = Y 2+ X 2 - a2
< 0 if (x,y) is inside the circle
= 0 if (x,y) is an the circle
> 0 if (x,y) is out side the circle
Hence we considered the distance between P and Q and the radius of the circle and take middle pixel of P
and Q .
Hence the mid point is ( Xi+1 ,Yi-1) using this concept we
have to calculate the other points and then replicate this
point to the other sector or octant .

For deriving the new points we have to calculate a initial


decision parameter and check if it is less than O (<0) or
not ,
we define the decision parameter As follows -
Pk =( 1- R) where R is the Radius
Case-2: Pk > 0
 Case-1 : Pk <0
Pk+1 = Pk +2x+1-2y
Pk+1 = Pk +2x+1
Xnext=X+1
Xnext=X+1
Ynext=Y-1
Ynext=Y
Q.Draw a circle using mid-point circle drawing algorithm where radius 10 and origin Xc ,Yc = (2 , 2 )
Ans- Given that R= 10 = Y
And origin [ Xc ,Yc = 2 , 2 ]
Now we have to find initial and decision parameter i .e Pk= 1-R = 1- 10 = -9
 Case-1 : Pk <0
Pk Xnext Ynext Xc=X+Xc Yc=Y+Yc
Pk+1 = Pk +2x+1
0 10 2 12
Xnext=X+1
-9 <0 1 10 3 12
Ynext=Y
Pk= - 9 +(2x1)+1 = -6 <0 2 10 4 12
Pk= -6 +(2x2)+1=-1 <0 3 10 5 12  Case-2: Pk > 0
Pk=-1+(2x3)+1=6>0 4 9 6 11 Pk+1 = Pk +2x+1-2y
Pk=6 +(2X4)+1-18=-3<0 5 9 7 11 Xnext=X+1
Pk=-3+(2x5)+1= 8>0 6 8 8 10 Ynext=Y-1
Pk=8+(2x6)+1-16=5>0 7 7 9 9
Q.Find the pixel location approximately on the second octant of the circle having centre (0,0) and
Radius 8 using mid point method .
Ans- Given that R= 8 = Y And origin(X0, Y0) = 0 ,0
Now we have to find initial and decision parameter i .e Pk= 1-R = 1- 8 = - 7
 Case-1 : Pk <0
Pk Xnext Ynext X+X0 Y+Yo Pk+1 = Pk +2x+1
0 8 2 10 Xnext=X+1
- 7 <0 1 8 3 10 Ynext=Y
Pk= - 7 +2 +1 = -4 <0 2 8 4 10
Pk= - 4 +4+ 1=1>0 3 7 5 9  Case-2: Pk > 0
Pk=1+6+1-14=-6<0 4 7 6 8 Pk+1 = Pk +2x+1-2y
Pk= -6 +8+1= 3>0 5 6 7 7 Xnext=X+1
Pk=3+10+1-12= 2>0 6 5 8 Ynext=Y-1
 Mid -point circle drawing Algorithm :
Step-1 : Input the circle radius R and the centre of the circle in (Xc , Yc)
Step-2 : Initialize the value x=0 and Y= radius (R)
Step-3 : Plot pixel (X+Xc , Y+Yc)  Advantage of Mid point circle Drawing Algorithm
Step-4: calculate the decision parameter Pk=1-R 1) It is a powerful and efficient algorithm
Step -5 : Start the loop while x > y 2) It is easy to implement from the programmer’s
If Pk <0 perspective
Pk+1 =Pk +2x +1 3) This algorithm is used to generate curves on raster
Xnext = X+1 display
Ynext = Y
Plot pixel ( X + Xc ,Y+Yc)  Disadvantage of Mid point circle Drawing
If Pk> 0 Algorithm -
Pk+1 =Pk +2x +1 -2y 1) Accuracy of the generating points is an issue in this
Xnext =X+1 algorithm
Ynext =Y-1 2) The circle generated by this algorithm is not smooth
Plot pixel (X+Xc ,Y +Yc) 3) This algorithm is time consuming .
Step -6 : stop (end of loop)
 Bresenham’s Circle Drawing Algorithm :- Mathematical Reduction /direction :
If we consider 8-base symmetric of a circle we have to calculate only one 8 sector of a circle and all other
point can found directly from the point .In this algorithm we will consider the point from 90 0 - 45 0 .
Or 45 0 to O o . The based of approximation is achieve to choosing the pixel which from the least distance from
the pre point derived from the circle .

From the above figure we can understand which pixel have to


be pic .Here the initial Decision parameter as calculated as -
Initial Decision parameter : 3 - 2r
Case-1 : if Pk<0 Case-2 : if Pk >0
Pk+1 =Pk +4x +6 Pk+1= Pk+4 (x-y) +10
Xnext =X+1 Xnext =X+1
Xnext =X+1 Ynext =Y-1
Ynext= y
 Bresenham’s Circle Drawing Algorithm :
Step -1 : Input the radius R and desired origin (Xc ,Yc)
Step -2 : Initialization the value x=0 and Y=R
Step -3 :Plot pixel [ (x+Xc) ,(y+Yc) ]
Step-4 : calculated the initial decision parameter Pk =3 -2r
Step -5 : Start the loop
While (x > y)
If Pk < 0
Pk+1 =Pk +4x +6
Xnext =X+1
Ynext =y
Plot pixel (x+xc , y+yc)
If Pk >o
Pk+1= Pk +4 (x-y) +10
Xnext =X+1
Ynext =Y-1
Plot pixel (x+xc, Y+Yc)
Q.Draw a circle using Bresenham's circle algorithm with radius 10 and Centre of the Circle Xc ,Yc=(2,2) .
Ans- R=10 , Xc ,Yc=(2,2) Pinitial = 3 - 2 * 10 = -17
Xk Yk Pk+1 Xc(X+Xc) Yc(Y+Yc)
0 10 3-2r=-17<0 2 12
1 10 -17 +(4 x 1)+6 =-7 <0 3 12
2 10 7+(4 x 2) + 6 =7 >0 4 12
3 9 7+4(3-9) +10 =-7<0 5 11
4 9 -7 +(4 x 4) +6 =15>0 6 11
5 8 15+4 (5-8) +10 =13>0 7 10
6 7 13+4(6-7) +10 =19>0 8 9
7 6

Q.Given the centre point coordinate (10 ,10) and radius as 1o generate all the points to form a circle .
Ans- R=10 , Xc ,Yc=(10 ,10)
Pinitial = 3 - 2 * 10 = -17

Xk Yk Pk+1 Xc=(X+Xc) Yc=(Y+Yc)


0 10 10 20
1 10 -17 11 20
2 10 -7 12 20
3 9 7 13 19
4 9 -7 14 19
5 8 15 15 18
6 7 13 16 17

 Bresenham's circle drawing vs Mid point circle Drawing Algorithm


Ans- Bresenham's circle drawing algorithm deals with integer so ,it is very less time and memory
consuming .The algorithm is accurate and efficient as it avoid using round function or floating point
calculation .
Where as Mid point algorithm avoid square root or triconmiti calculation by adapting integer
operation only . This algorithm checks the nearest integer by calculating mid points of the pixel nearer to the
given point on the circle .
 Concept of 4 - connected and 8- connected region :
There are two ways in which the pixel are considered to be connected to one another , 4 - connected and
8-connected .In 4 -connected method a pixel may have upto 4 neighbour .

Figure : 4 -Connected
These are up-down left and right if this current pixel is (x,y) the neighbour are - ( x , y+1) , ( x+1 ,y) ,( x-1,y)
and ( x,y-1).

Figure : 4 neighbourhood
In 8 connected method the pixel may have upto 8 neighbour

Figure : 8-Connected
There are up-down .left ,right and 4 corner points -
(X-1 , y+1) ( x , y+1) ( x+1 ,y+1)
( x-1,y) (x, y) ( x+1 ,y)
( x-1,y-1) ( x,y-1) ( x+1 ,y-1)

Fig : 8 -neighbourhood
 Concept of Polygon :
Q. What is Polygon : Polygon is a representation of a surface it is premitive which is closed in nature it is
form using a collection of line .It is also called as many sided figure .
The lines combined to form polygon are called sides or ages .The lines obtain by two vertices .Example -
Triangle , Rectangle , Pexagon , hexagon .

Types of polygon according there sides and edges :


1) Regular Polygon :All sides and interior angle of the polygon are equal . Example-

2)Irregular Polygon : If all the sides and interior angle of the polygon are different measure .
Example -

2) Convex Polygon : If the all interior angle of a polygon are strictly less than 180 Example -
Type of Convex - Regular Convex , Irregular Convex

4)Concave Polygon : If one or more interior angle of a polygon are more than 180 .Example-
.A

 Filling : To fill the pixel of specified region is called Filling .Filling is one of the fundamental concept of
computer graphics .There are several cases where filling place an important role .For example - To fill
the interior of an object like circle, rectangle and character .

Here we discuss different aspect of filling algorithm and some technique .

Q.What is region Filling ?


Ans- It is process of coloring a well defined .Image area or region by a given color .There are two type region
in terms of pixel - 1)Boundary defined Region 2) Interior or Flood filled .

1)Boundary defined Region : If a region is out-lined by the pixel i.e only the outline of the region is
define ,then it is called Boundary Defined Region .

Fig :Boundary Filled Region Fig :Interior or Flood Filled

3) Interior or Flood filled : A region whose total internal area is filled with pixel color is called Interior
defined region .

Note 1 - Depending upon the types of region there are 3 types of filling algorithm that is -
 Boundary Filled Algorithm : used is case of Boundary Field region
 Flood field Algorithm : Used in in case of interior filed region
 Scan field Algorithm : Used to draw a line inside a polygon

Note-2 : If the boundary is specified in a single color the filling process starts from in interior part and
proceed out word pixel all the boundary is an counter .

Note-3 :In case of area defined region by multi color boundary ,the approach will be different .In this case
we fill the area by replacing the specified interior color by the fill color instead of searching the specified
boundary color .This area is called interior specified region and the algorithm for filling this region is called
Flood field Algorithm .

You might also like