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:

  1. O2 updates Pre teaser page
  2. Verizon opens network; puts Treo 755p teaser page online
  3. A little bug in FontBucket.c, routine FmValidFont
  4. The Sound of…sorting algorithms
  5. Mastering algorithms in C review

4 Responses to “A cool page explaining circle drawing algorithms”

  1. 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.

  2. 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.

  3. 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

  4. @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

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

© 2013 TamsPalm - the Palm OS / web OS Blog Suffusion theme by Sayontan Sinha