views:

2135

answers:

4

What's a good algorithm for drawing anti-aliased circles? (Filled and not filled.)

+1  A: 

If you want an easy one, make a soft blur from pixel matrix A to pixel matrix B.

This is one i've used (here in pseudo-code)

anti_alised_matrix[x][y] = point[x][y] / 2 + point[x+1][y]/8 + point[x-1][y]/8 + point[x][y-1]/8 + point[x][y+1]/8;

Ofcourse this is applied to grayscale, but you can do easily the same in RGB.

This is really a very simple one, you can also add the diagonals i.e. [x+1][y+1] and split it by 16 or 32.

We used this one to make a rather easy anti aliasing for Computer graphics course. (It was an optional feature)

fmsf
A: 

Depending on your platform you are using, it may be built in - Java certainly has AA built into it's graphics rendering (and has had for a long time). I would be surprised if DotNet did not also have AA built in. Plus, the platform likely has subpixel AA, which you get for free, and which is substantially better than standard AA.

Software Monkey
A: 

Create a Graphics object g. Do

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

Draw your anti aliased circle with g.FillEllipse or g.DrawEllipse

Spikolynn
Did he ever say he was on .NET?
Tomalak
Nope. But did he ever say he was not :?)
Spikolynn
He asked for an algorithm, not a platform-specific sample of how to use something that does it for you.
OJ
"how to use something that does it for you" sounds like an algorithm to me. Maybe a better answer would involve a stick in a sand, rope and a nail :?)
Spikolynn
"how to use something that does it for you" sounds like the exact opposite of an "algorithm" to me. Algorithms usually involve math and work everywhere, you just set a property to a predefined value. ;-)
Tomalak
Spikolynn, what you gave is a ritual; what he asked for is reason.
Svante
hehe, these are funny comments. :) (I would take the easy option if i could but...)
I actually found this comment useful as I DID need to know how to do this in .NET
Guy
+6  A: 

Bresenham (of the line algorithm fame) also had a circle algorithm.

Xiaolin Wu adapted the line algorithm for anti-aliasing, and likewise did the same to the circle algorithm.

http://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm

You can find the circle algorithm with this search:

http://www.google.com/search?q=Xiaolin%20Wu%20circle

Adam Davis
Actually, what is popularly known as "Bresenham's circle algorithm" wasn't Bresenham's own work.http://en.wikipedia.org/wiki/Midpoint_circle_algorithmBut still....
Stewart