5

I am interested in finding an antialiasing algorithm which can be used on a line of any shape (not just straight lines).

I notice that Mathematica seems to have a very good algorithm and can draw fine lines 1 or 2 pixels wide. My current best effort algorithm generally requires more like 3 pixels so my lines are somewhat thicker than Mathematica's.

Does anybody know what algorithm Mathematica uses for antialiasing, or can recommend a high-quality algorithm that can be used to generate sub-2-pixel antialiased lines and curves?

keelar
  • 5,814
  • 7
  • 40
  • 79
Tyler Durden
  • 11,156
  • 9
  • 64
  • 126
  • Can't you draw 3 separate lines three times? – ElKamina Jul 17 '13 at 22:37
  • The cleanest and simplest, but somewhat slow, antialiasing method is just oversampling. That is, draw the line at higher resolution than your actual display, and scale it down. – Lee Daniel Crocker Jul 18 '13 at 09:36
  • I am familiar with this method, and it is possible that Mathematica uses it, however examples I have seen don't seem to have very good quality all the time compared to Mathematica. Maybe I am just seeing things, but my suspicion is that they are using a more sophisticated approach. – Tyler Durden Jul 18 '13 at 15:18
  • I don't have much experience with manual oversampling but be aware that there are [**many**](http://www.general-cathexis.com/interpolation/index.html) different ways to rescale images; quite possibly the quality you seek can be had with a different resampling algorithm or [**filter**](http://www.imagemagick.org/Usage/filter/). – Mr.Wizard Jul 26 '13 at 22:31

1 Answers1

3

One of the most used algorithm for drawing unaliased lines is Wu's line algorithm.

On this basis, you can draw polygons easily; this site explains how to derive this algorithm to draw ellipses.

Bentoy13
  • 4,886
  • 1
  • 20
  • 33
  • I want to be able to draw arbitrary shapes, including for example, sin and cos (trigonometric functions), as well as higher order polynomials. Wu's algorithm is primarily for straight lines. – Tyler Durden Jul 18 '13 at 15:16
  • I think that the same approach can be applied for everything. See this post which mentions how to draw antialiased splines: http://stackoverflow.com/questions/4541442/drawing-aliased-pixel-perfect-1px-splines-catmull-rom-specifically. You may use the same trick to draw everything else; another way is approximating your curve with subpixellic precision with splines, and draw the spline. – Bentoy13 Jul 19 '13 at 10:04