UNIT – 2
LINE, CIRCLE AND POLYGON
INTRODUCTION
 The screen of computer is divided into
number of row and columns.
 The intersection of row and column is called
as pixel. Pixel is a smallest addressable point
that can be displayed on screen.
 To draw a line on screen firstly we have to
determine which pixels are to be switched
ON.
 Thus, the process of determining appropriate
pixel for representing picture is called as
Rasterization.
GENERAL CRITERIAS
 Lines should appear straight.
 Lines should start and end accurately.
 Lines should have constant density along
their length.
 Lines density should be independent of line
length and angle.
 Lines should be drawn rapidly.
LINE DRAWING ALGORITHM
 Straight line drawing algorithms are based on
incremental methods.
 In incremental method line starts with a
starting point, then some fix incremental
value is added to current point to get next
point on line and same is continued till end
of line.
 Following are the two main algorithm’s used
to draw a straight line.
1. DDA algorithm.
2. Bresenham’s algorithm
DDA ALGORITHM
 Read end point of line i.e.(x1, y1) and (x2, y2).
 ∆x=abs(x2-x1) and ∆y=abs(y2-y1)
 If dx>=dy then len=dx
else
len=dy
end if
 dx=(x2-x1)/len
dy=(y2-y1)/len
 X=x1+0.5*sign(dx)
y=y1+0.5*sign(dy)
 i=1
while(i<=len)
{
x=x+dx
y=y+dy
i=i+1
}
 stop
 Merits:-
 It is simple algorithm.
 It is faster method.

 Demerits:-
 Floating point arithmetic in DDA algorithm is
time consuming.
 Accumulation of round-off error in successive
additions of floating point increment can cause
the calculated pixel positions to draft away
from the true line path for long line segments.
EXAMPLE:
1. Consider a line from (0,0) to (5,6). Use
simple DDA algorithm to rasterize this line.
2. Consider a line from (0,0) to (-5,-5). Use
simple DDA algorithm to rasterize this line.
BRESENHAM’S ALGORITHM
 Read end point of line i.e.(x1, y1) and (x2, y2).
 ∆x=abs(x2-x1) and ∆y=abs(y2-y1)
 Initialize starting point of linei.e. x=x1
y=y1
 Plot (x, y) i.e plot first point.
 Obtain initial value of decision parameter PK as
PK =2∆y-∆x
 If PK <0
{ x=x+1
y=y
PK = PK +2∆y }
If PK >=0
{ x=x+1
y=y+1
PK = PK +2∆y-2∆x }
plot(x,y)
 Repeat step (6) ∆x times.
 stop
EXAMPLE
 Consider a line from (6,6) to (12,9). Use
simple Bresenham’s algorithm to rasterize
this line.
CIRCLE GENERATING
ALGORITHM
y axis y=x
x axis
y=-x
 Following are the main algorithm’s used to
draw a circle.
1. DDA algorithm.
2. Bresenham’s algorithm.
3. Mid-point algorithm.
DDA CIRCLE GENERATING ALGORITHM.
 Algorithm:-
1. Read radius of circle(r) and calculate value
of e(epsilon).
2. x=0 y=r
3. x1=x y1=y
4. While((y1-y)<e||(x-x1)>e)
{
x1=x1+e.y1
y1=y1-e.x1
}
5. stop
BRESENHAM’S CIRCLE
GENERATING ALGORITHM.
 Algorithm:-
1. Read radius of circle(r)
2. Calculate initial decision variable Pi.
3. x=0 and y=r
4. if(pi<0) { x=x+1 pi=pi+4x+6 }
elseif(pi>=0) { x=x+1 y=y-1
pi=pi+4(x-y)+610 }
5. Plot pixels in all octants
6. stop
MID-POINT CIRCLE GENERATING
ALGORITHM.
 Algorithm:-
1. Read radius of circle(r).
2. Obtain 1st
point on circle boundary as (x0,y0) = (0,r)
3. Calculate initial decision variable P0=1-r.
4. if(pi<0) { xi=xi+1
yi=yi pi+1=pi+2(xi+1)+1 }
elseif(pi>=0) { xi=xi+1
yi=yi-1 pi+1=pi+2(xi+1)+1-2yi+1
}
5. Plot pixels in all octants
Plot(x,y)
Plot(y,x)
Plot(-y,x)
Plot(-x,y)
Plot(-x,-y)
Plot(-y,-x)
Plot(y,-x)
Plot(x,-y)
6. stop
THANK YOU

CGA is a creation and manipulation of image or picture with the help of computer.

  • 1.
    UNIT – 2 LINE,CIRCLE AND POLYGON
  • 2.
    INTRODUCTION  The screenof computer is divided into number of row and columns.  The intersection of row and column is called as pixel. Pixel is a smallest addressable point that can be displayed on screen.  To draw a line on screen firstly we have to determine which pixels are to be switched ON.  Thus, the process of determining appropriate pixel for representing picture is called as Rasterization.
  • 3.
    GENERAL CRITERIAS  Linesshould appear straight.  Lines should start and end accurately.  Lines should have constant density along their length.  Lines density should be independent of line length and angle.  Lines should be drawn rapidly.
  • 4.
    LINE DRAWING ALGORITHM Straight line drawing algorithms are based on incremental methods.  In incremental method line starts with a starting point, then some fix incremental value is added to current point to get next point on line and same is continued till end of line.  Following are the two main algorithm’s used to draw a straight line. 1. DDA algorithm. 2. Bresenham’s algorithm
  • 5.
    DDA ALGORITHM  Readend point of line i.e.(x1, y1) and (x2, y2).  ∆x=abs(x2-x1) and ∆y=abs(y2-y1)  If dx>=dy then len=dx else len=dy end if  dx=(x2-x1)/len dy=(y2-y1)/len  X=x1+0.5*sign(dx) y=y1+0.5*sign(dy)  i=1 while(i<=len) { x=x+dx y=y+dy i=i+1 }  stop
  • 6.
     Merits:-  Itis simple algorithm.  It is faster method.   Demerits:-  Floating point arithmetic in DDA algorithm is time consuming.  Accumulation of round-off error in successive additions of floating point increment can cause the calculated pixel positions to draft away from the true line path for long line segments.
  • 7.
    EXAMPLE: 1. Consider aline from (0,0) to (5,6). Use simple DDA algorithm to rasterize this line. 2. Consider a line from (0,0) to (-5,-5). Use simple DDA algorithm to rasterize this line.
  • 8.
    BRESENHAM’S ALGORITHM  Readend point of line i.e.(x1, y1) and (x2, y2).  ∆x=abs(x2-x1) and ∆y=abs(y2-y1)  Initialize starting point of linei.e. x=x1 y=y1  Plot (x, y) i.e plot first point.  Obtain initial value of decision parameter PK as PK =2∆y-∆x  If PK <0 { x=x+1 y=y PK = PK +2∆y } If PK >=0 { x=x+1 y=y+1 PK = PK +2∆y-2∆x } plot(x,y)  Repeat step (6) ∆x times.  stop
  • 9.
    EXAMPLE  Consider aline from (6,6) to (12,9). Use simple Bresenham’s algorithm to rasterize this line.
  • 10.
  • 11.
     Following arethe main algorithm’s used to draw a circle. 1. DDA algorithm. 2. Bresenham’s algorithm. 3. Mid-point algorithm.
  • 12.
    DDA CIRCLE GENERATINGALGORITHM.  Algorithm:- 1. Read radius of circle(r) and calculate value of e(epsilon). 2. x=0 y=r 3. x1=x y1=y 4. While((y1-y)<e||(x-x1)>e) { x1=x1+e.y1 y1=y1-e.x1 } 5. stop
  • 13.
    BRESENHAM’S CIRCLE GENERATING ALGORITHM. Algorithm:- 1. Read radius of circle(r) 2. Calculate initial decision variable Pi. 3. x=0 and y=r 4. if(pi<0) { x=x+1 pi=pi+4x+6 } elseif(pi>=0) { x=x+1 y=y-1 pi=pi+4(x-y)+610 } 5. Plot pixels in all octants 6. stop
  • 14.
    MID-POINT CIRCLE GENERATING ALGORITHM. Algorithm:- 1. Read radius of circle(r). 2. Obtain 1st point on circle boundary as (x0,y0) = (0,r) 3. Calculate initial decision variable P0=1-r. 4. if(pi<0) { xi=xi+1 yi=yi pi+1=pi+2(xi+1)+1 } elseif(pi>=0) { xi=xi+1 yi=yi-1 pi+1=pi+2(xi+1)+1-2yi+1 }
  • 15.
    5. Plot pixelsin all octants Plot(x,y) Plot(y,x) Plot(-y,x) Plot(-x,y) Plot(-x,-y) Plot(-y,-x) Plot(y,-x) Plot(x,-y) 6. stop
  • 16.