Mid-Point Circle Algorithm

Firstly, the resulting circle has large gaps where the slope approaches the vertical.

Secondly, the calculations are not very efficient

  • The square (multiply) operations
  • The square root operation – try really hard to avoid these

We need a more efficient, more accurate solution. The first thing we can notice to make our circle drawing algorithm more efficient is that circles centred at (0, 0) have eight-way symmetry.

Mid-Point Circle Algorithm

Similarly to the case with lines, there is an incremental algorithm for drawing circles – the mid-point circle algorithm.

In the mid-point circle algorithm we use eight-way symmetry so only ever calculate the points for the top right eighth of a circle, and then use symmetry to get the rest of the points.

Assume that we have

just plotted point (xk, yk)

The next point is a choice between (xk+1, yk) and (xk+1, yk-1)

We would like to choose the point that is nearest to the actual circle, So how do we make this choice?

Let’s re-jig the equation of the circle slightly to give us:

The equation evaluates as follows:

f(x, y) = x2 + y2 - r2

f(x, y) { < 0 if (x, y) is outside the circle boundary

f(x, y) { = 0 if (x, y) is on the circle boundary

f(x, y) { > 0 if (x, y) is inside the circle boundary

By evaluating this function at the midpoint between the candidate pixels we can make our decision.

Assuming we have just plotted the pixel at (xk, yk) so we need to choose between (xk+1, yk) and (xk+1, yk-1)

Our decision variable can be defined as:

pk = f(xk + 1, yk - 1/2 )

= (xk + 1)2 + (yk - 1/2 )2 - r2

If pk < 0 the midpoint is inside the circle and and the pixel at yk is closer to the circle Otherwise the midpoint is outside and yk-1 is closer.

To ensure things are as efficient as possible we can do all of our calculations incrementally First consider: