Professional Documents
Culture Documents
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
1 -ε
[xn+1, yn+1]=[ xn, yn ],[ ε 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 ]
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
d=dP3 –dP2
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
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
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.
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
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