Circle Drawing Algorithm
Circle Drawing Algorithm
Regulation 2008
LECTURER III
CIRCLE-GENERATING ALGORITHMS
General function is available in a graphics library for displaying various kinds of curves,
including circles and ellipses.
Properties of a circle
A circle is defined as a set of points that are all the given distance (xc,yc).
Fig1.29: Circle
y = yc + rsin
When a display is generated with these equations using a fixed angular step size, a circle
is plotted with equally spaced points along the circumference. To reduce calculations use a large
Regulation 2008
angular separation between points along the circumference and connect the points with straight
line segments to approximate the circular path.
Set the angular step size at 1/r. This plots pixel positions that are approximately one unit
apart. The shape of the circle is similar in each quadrant. To determine the curve positions in the
first quadrant, to generate he circle section in the second quadrant of the xy plane by nothing that
the two circle sections are symmetric with respect to the y axis and circle section in the third and
fourth quadrants can be obtained from sections in the first and second quadrants by considering
symmetry between octants.
Circle sections in adjacent octants within one quadrant are symmetric with respect to the
450 line dividing the two octants. Where a point at position (x, y) on a one-eight circle sector is
mapped into the seven circle points in the other octants of the xy plane.
To generate all pixel positions around a circle by calculating only the points within the
sector from x=0 to y=0. the slope of the curve in this octant has an magnitude less than of equal
to 1.0. at x=0, the circle slope is 0 a nd at x=y, the slope is -1.0
Bresenhams line algorithm for raster displays is adapted to circle generation by setting
up decision parameters for finding the closest pixel to the circumference at each sampling step.
Square root evaluations would be required to computer pixel siatances from a circular path.
Bresenhams circle algorithm avoids these square root calculations by comparing the
squares of the pixel separation distances. It is possible to perform a direct distance comparison
without a squaring operation.
Regulation 2008
In this approach is to test the halfway position between two pixels to determine if this
midpoint is inside or outside the circle boundary. This method is more easily applied to other
conics and for an integer circle radius the midpoint approach generates the same pixel positions
as the Bresenham circle algorithm.
For a straight line segment the midpoint method is equivalent to the bresenham line
algorithm. The error involved in locating pixel positions along any conic section using the
midpoint test is limited to one half the pixel separations.
Midpoint circle Algorithm:
In the raster line algorithm at unit intervals and determine the closest pixel position to the
specified circle path at each step for a given radius r and screen center position (x c,yc) set up our
algorithm to calculate pixel positions around a circle path centered at the coordinate position by
adding xc to x and yc to y.
To apply the midpoint method we define a circle function as
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
fcircle (x,y)
<0, if (x,y) is inside the circle boundary
=0, if (x,y) is on the circle boundary
>0, if (x,y) is outside the circle boundary
The tests in the above eqn are performed for the midposition sbteween pixels near the circle path
at each sampling step. The circle function is the decision parameter in the midpoint algorithm.
Midpoint between candidate pixels at sampling position xk+1 along a circular path. Fig -1
shows the midpoint between the two candidate pixels at sampling position x k+1. To plot the pixel
at (xk,yk) next need to determine whether the pixel at position (x k+1,yk) or the one at position
(xk+1,yk-1) is circular to the circle.
Our decision parameter is the circle function evaluated at the midpoint between these two
pixels
Regulation 2008
= fcircle (xk+1+1,yk+1-1/2)
=[(xk+1)+1]2+(yk+1-1/2)2-r2
Or
Pk+1
=Pk+2(xk+1)+(y2k+1-y2 k )-(yk+1-yk)+1
Where yk+1 is either yk or yk-1 depending on the sign of Pk .
Increments for obtaining Pk+1 are either 2xk+1+1 (if Pk is negative) or 2xk+1+1-2 yk+1.
Evaluation of the terms 2xk+1 and 2 yk+1 can also be done incrementally as
2xk+1=2xk+2
2yk+1=2 yk-2
At the Start position (0,r) these two terms have the values 0 and 2r respectively. Each
successive value for the 2xk+1 term is obtained by adding 2 to the previous value and each
successive value for the 2yk+1 term is obtained by subtracting 2 from the previous value.
The initial decision parameter is obtained by evaluating the circle function at the start
position (x0,y0)=(0,r)
P0
= fcircle (1,r-1/2)
=1+(r-1/2)2-r2
Or
P0
=(5/4)-r
Regulation 2008
y=y+yc
k
0
1
2
3
4
5
6
pk
-9
-6
-1
6
-3
8
5
(xk+1, yk-1)
(1,10)
(2,10)
(3,10)
(4,9)
(5,9)
(6,8)
(7,7)
2xk+1
2
4
6
8
10
12
14
2yk+1
20
20
20
18
18
16
14
Regulation 2008
RESULT:
Regulation 2008