Posts

How to Draw Anti-Aliased Circles (Xiaolin Wu’s Method)

In this post, we will briefly explore how Xiaolin Wu’s algorithm for drawing anti-aliased circles works. We’ll explain the underlying concept and show you how to implement it with simple code. Introduction Xiaolin Wu's algorithm was published in 1991, and it’s one of those clever tricks to get anti-aliased lines and circles. Compared to Bresenham, which is all integer math and sharp edges, Wu's approach uses floating point and controls pixel brightness to get smoother results. Here we’ll focus on the circle version, quick overview of the idea, and then straight to the code. Eight-way symmetry Thanks to the circle’s eight-way symmetry, we can reduce the amount of work by computing only one eighth of the arc. Once we have the points for that section, we just reflect and rotate them to get the full shape across all octants. This not only simplifies the code, but also helps keep the intensity distribution consistent all around. Working around spatial sampling To work around th...