You are on page 1of 5

2) DDA method-This digital differential analyzer can be used to draw the circle,if we

can define the circle by ordinary differential equation.Let r be the radius of the circle,with
origin as the centre of the circle.we know the equation of the circle is given by y2=r2-x2
Now r being the constant,we can obtain the differential equation as follows:
2xdx=-2ydy , dy/dx= -x/y
We can construct the circle by using incremental step of -εx , εy (ε=2-n)
xn+1=xn+ εy , y n+1=yn-εx
But we don’t get a circle from these quations, it will be a spiral.Each point is slightly
farther from the centre of the circle and from the earlier point, as we have each step
direction perpendicular to radius of circle.We shall use x n+1 to compute y n+1
So the equations now become xn+1=xn+ εy , y n+1=yn-ε xn+1

representing it in the form of a matrix we have

1 -ε
[xn+1, yn+1]=[ xn, yn ],[ ε 1]

Now the value of 1 -ε is 1+ ε2


[ε 1]

Hence if we wish that the curve should be closed,this determinant value should
become unity.
Therefore we can write final equation as

1 -ε
[xn+1, yn+1]=[ xn, yn ],[ ε 1- ε2 ]

3) Bresenham’s circle algorithm-According to bresenham’s,”the best approximation


of true circle will be described by those pixels in the raster that fall at the least
distance from the true circle.”
P1(xi,yi) P3(xi+1,yi)

yi

yi-1

P2(xi+1,yi-1)

xi xi+1

At each step, when we obtain a new pixel/point,there are going to be three possibilities
1) point is on the circle
2) point is inside the circle
3) point is outside the circle
let P1be the point which may be already plotted correctly.the next point are P2 or P3
dP2 =(Distance from origin to pixel P2 ) 2-(Radius of circle)2

dP3 =(Distance from origin to pixel P3 ) 2-(Radius of circle)2

dP2 will always be negative as it lies inside the circle


dP3 will always be positive as it lies outside the circle

d=dP3 –dP2

now the condition are

if the value of d
1) <0 , dP3 <dP2 ,select pixel P3
2) >0 , dP3 >dP2 ,select pixel P2
3) =0, dP3 =dP2 ,select either dP3 or P2
By the equation of circle x2 +y2-r2
P3 has coordinates (xi+1 , yi ), P2 has coordinates (xi+1 , yi-1 ) but xi+1= xi +1, yi-1 = yi -1
dP3 =(xi +1)2 +yi2 -r2
dP2 =(xi +1)2 +(yi-1)2 -r2

d=dP3 –dP2 but dP2 will always be negative as it lies inside the circle
so d=dP3 –(-dP2 )=dP3 +dP2
=2(xi +1)2 +yi2 +(yi-1)2-2r2
Now starting pixel coordinates (P0 ) is (0,r)
So d=2(0 +1)2 +r2 +(r-1)2-2r2 = 3-2r

This is the initial value of d


Decision variable for the next step is di+1=2(xi+1 +1)2 +yi+12 +(yi+1-1)2-2r2

di+1 - di =2(xi+1 +1)2 +yi+12 +(yi+1-1)2-2r2 –(2(xi +1)2 +yi2 +(yi-1)2-2r2 )

di+1 = di +4xi +2(yi+12 -yi2 ) -2(yi+1-yi) +6


so
di+1 = di +4xi +6 if di <0 as then yi+1=yi
di+1 = di +4(xi-yi) +10 if di >=0 as then yi+1=yi-1

The algorithm as follows


1) read (h,k) as the centre of circle and r as its radius
2) initialize x=0,y=r,d=3-2*r
3) while(x<=y)
plot(x+h,y+k),
plot(-x+h,y+k),
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),

if (d<0) then
d=d+4*x+6
else d=d+4*(x-y)+10 , y=y-1

end if x=x+1
end while
4) stop

4)Midpoint circle algorithm-


P1(xi,yi) P3(xi+1,yi)
yi
yi-1

P2(xi+1,yi-1)

xi xi+1

For a given radius rand screen position (x0,y0),we can first set up our algorithm to
calculate pixel positions around a circle path centered at the coordinate origin(0,0).then
each calculated position(x, y) is moved to its proper screen position by adding xc to x and
yc to y along the circle section from x=0 to x=y in the first quadrant ,the slope of the
curve varies from 0 to -1.therefore we can take unit steps in the position x direction over
this octant and use a decision parameter to determine which of the two possible y
positions is closer to the circle path at each step. Positions in the other seven octants are
obtained by symmetry. to apply the midpoint method ,we defined the circle function

fcircle(x,y)= x2 +y2-r2 .
Any point (x,y) on the boundary of the circle with radius r satisfies the equation
fcircle(x,y)=0.If the point is in the interior of the circle ,the circle function is negative.And
if the point is outside the circle,the circle function is positive.
The midpoint between the two candidate pixels at sampling position xi+1 .Assuming we
have just plotted the pixel at (xi,yi),we next need to determine whether the pixel at
position (xi+1,yi) or the one at position (xi+1,yi-1) is closer to the circle.our decision
parameter is the circle function at the midpoint between these two pixels.

di= fcircle (xi +1,yi -1/2)= (xi +1)2+(yi -1/2) 2-r2


if di <0,this midpoint is inside the circle and the pixel on the scan line yi,is closer to the
circle boundary.Other wise the midpoint is outside or on the circle boundary,and we
select the pixels on the scan line yi-1 .Successive decision parameters are obtained using
incremental calculations.We obtain a recursive expression for the next decision parameter
by evaluating the circle function at sampling position
xi+1 +1= xi +2
di+1= fcircle (xi+1 +1,yi+1 -1/2)= [(xi +1)+1]2+(yi+1 -1/2) 2-r2
di+1= di+2 (xi +1)+( yi+12 - yi 2)- ( yi+1 - yi )+1

where yi+1 is either yi or yi-1 depending on the sign of di


increments for obtaining di+1 are either 2xi+1 +1 or 2xi+1 +1-2yi+1
evaluation of the terms 2xi+1 and 2yi+1 can also be done incrementally as
2xi+1 =2xi +2 , 2yi+1 =2yi -2

The initial decision parameter is obtained by evaluating the circle function at the start
position (x0,y0)=(0,r):

d0 = fcircle (1,r-1/2)=5/4 - r

if the radius r is specified as an integer we can simply round d0 =1-r

Algorithm:
1) Input radius r and circle center(xc, yc ) and obtain the first point on the
circumference of a circle centered on the origin as (xc, yc )=(0,r)
2) Calculate the initial value of the decision parameter as d0 =5/4 - r
3) At each xi position ,starting at i=0,perform the following test: if di <0,th e next
point along the circle centered on (0,0) is (xi+1,yi)
di+1= di+2 (xi+1)+1
otherwise the next point along the circle is (xi+1,yi-1) and
di+1= di+2xi+1+1-2yi+1
where 2xi+1 =2xi +2 , 2yi+1 =2yi -2

4) Determine symmetry points in the other seven octants


5) Move each calculated pixel position (x,y) onto the circular path centered on
(x0 ,y0 ) and plot the coordinate value x=x+xc , y=y+yc

6) Repeat step 3 through 5 until x>=y

You might also like