2 - Circle Drawing Algorithms
2 - Circle Drawing Algorithms
Cartesian equation:
This equation expresses the fact that every point (x, y) on the circle is at a constant distance
R from the center point ( ), thus:
( ) ( )
If the angle between the vector from the center point ( ) to the point (x, y) and the
positive x axis direction is then the coordinates of the point (x, y) are:
( )
( )
All circle points can be obtained by changing from 0 to . Note here we use the radian
system of measuring angles.
Consider the case when the center point ( ) is at the origin (i.e. ). If
some point (a, b) lies on the circle, it will satisfy the circle equation, i.e.:
It is easy to see that changing the signs and exchanging the variables a and b in the left hand
side of the above equation gives the same result. So, the following eight points are all on the
circle if one of them is on the circle:
{( )( )( )( )( )( )( )( )}
This fact can be exploited in circle drawing algorithms by computing the points of only one-
eighth of the circle and inferring all the other points by symmetry.
A circle with general center point ( ) other than the origin are simply computed by
shifting the points of the circle centered about the origin by ( ), so if we have some
point (a, b) on the circle centered about the origin, the corresponding eight similar points on
the general circle are:
{( )( )( )( )( )(
)( )( )}
The following utility function expresses this fact; it will be used in circle drawing algorithms.
Note that in all of the following algorithms, the computations of circle points (x, y) are for
points of circles centered about the origin and the utility ‘Draw8Points’ described above is
used to exploit the 8-symmetry and shifting properties for general circles.
Circle points are obtained by changing x and computing y. To know which octant (one-eighth
of the circle) to compute in this case, we must be sure that the slope of the circle at each
point of the octant is less than one in magnitude (absolute value). By taking the derivative of
both sides of the circle equation with respect to x, we obtain:
So:
For the absolute value of the slope to be less than or equal to one, we should have:
| | | |
One of the octants satisfying this condition is the one satisfying the condition: , so
the main loop of the algorithm starts at x=0 and ends when x=y.
So
The above algorithm computes the trigonometric functions sin and cos which take a very
long time because they are computed using infinite series expansions. [ ( )
, ( ) ]
Let (x, y) be a point on the circle centered about the origin. Let ( ) be its corresponding
polar coordinates. Mathematically:
Next point (x’, y’) to draw on the circle is obtained by incrementing by , thus it has polar
coordinates (R, ). Mathematically:
( )
( )
( ) ( ) ( )
( ) ( ) ( )
The idea is to start at some point (R, 0) and use the above formulae to compute next points
iteratively. The following functions implements the idea.
The following function can be used to test if some point is on the circle, inside or outside the
circle (centered at the origin)
( )
( )
( ) { ( )
( )
The idea is to start at the point (0, R). This point is considered the current point (x, y). The
circle testing function is then used to test whether the next midpoint (x+1, y-1/2) is inside or
outside the circle. If it is inside, next point to draw is (x+1, y), otherwise next point is (x+1, y-
1). In the shown Figure, drawn points are represented as blue stars while the midpoints are
represented as red stars.
An iterative approach is used to compute the testing function at the middle point as follows:
Define d(x, y) as the mid-point test function to be tested after drawing the point (x, y). d(x,
y) is thus given by:
( ) ( ) ( ) ( )
( )
So,
( ) ( )
( ) ( ) ( ) ( )
If d(x, y)<0 then (x, y) is inside the circle and next point to draw is (x+1, y) so the change in d
is given by:
( ) ( )
So:
( ) ( ) ( ( ) )
( ) ( ) ( ) ( )
If d(x, y)>0 then (x, y) is outside the circle and next point to draw is (x+1, y-1) and the change
in d is thus:
( ) ( )
So:
( ) ( ) ( ) ( ( ) )
( ) ( )
( ) ( ) ( ) ( )
The initial value of d contains the constant value which is a real number. Fortunately
and removing from this constant will not affect the algorithm since the sign of d
will not be affected by this removal. So we will use d=1-R as the initial value of d and the
algorithm will be purely integer. Bresenham algorithm for circle drawing is given below:
( )
( ) ( )
( ) ( )
( ) ( )
( ) ( ) ( ) ( ) ( )
( ) ( ) ( ) ( ) ( ( ) )
Else
( ) ( ) ( ) ( ) ( )
( ) ( ) ( ) ( ) ( ( ) )
End if