Computer Graphics
Computer Graphics
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
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
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.
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.
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 .
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.
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
The application of scan conversion is video projectors ,cinema equipment,standard and HDTV
television,LCD monitors,radar display etc.
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.
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 :-
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
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
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 .
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
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 .
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 .
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 .
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 .