While coding on a Palm OS game yesterday, I created a simple circle drawing algorithm based on sine and cosine of an angle. The circles it drew were of very low quality – and I set out to find a better circle drawing algorithm.

After a few hours of searching, I finally found this page:

http://www.cs.unc.edu/~mcmillan/comp136/Lecture7/circle.html

It explains a rather simple algorithm that works very well – should you ever need a custom circle drawing routine(no, the Palm OS’s doesn’t do it here), you will be very happy to have this page at hand!

Related posts:

The demo code only seems to support diameters in odd number of pixels.

I haven’t taken the time to analyze the approach for validity with even count diameters.

Obviously it could be adapted, if this is indeed a shortcoming.

Actually, if you only need a circle, you can use WinDrawRectangle, like so

RectangleType r = { 10, 10, 100, 100 };

WinDrawRectangle(&r, 50);

The second parameter is the radius of the circle placed at each corner. This would draw a circle that’s centered at 60,60 of radius 50.

This isn’t useful for ellipses, but for circles it works nicely.

Hi Ben,

I did that – but it isn’t enough for me any more=).

You will see why I need the new algorithm very soon – in fact, send me an email and I will show you now!

Best regards

Tam Hanna

@ReadOnly

The odd sized diameter is more a result of the definition of the circle (center with a radius that are both integers) than the algorithm itself. But the main point is that these algorithms were made back when computation resources were at a premium and being able to draw a good looking circle with just integer operations was a necessity.

Also, the link from the article appears to be dead, so here’s a related article on wikipedia:

http://en.wikipedia.org/wiki/Midpoint_circle_algorithm