Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for drawing thick antialiased lines

Are there any "standard" algorithms for drawing thick antialiased lines? I have found Xiaolin Wu's algorithm for drawing 1px width lines, but have yet to find any extension for thicker lines.

like image 360
rcv Avatar asked Mar 19 '11 18:03

rcv


People also ask

Which algorithm is best for line drawing?

Line drawing algorithms such as Bresenham's or Wu's are preferred instead.

What is thick primitives in computer graphics?

Thick primitives are defined by OpenGL and other graphics interface specifications as primitives that are greater than 1 pixel in thickness. A thick line, accordingly, is a represented as a composite of two or more parallel and adjacent single pixel lines.


2 Answers

An inneficient, crude, quick way would be to draw the lines larger (say, 4x) and then scaling them down using weight averaging. Details here:

Algorithms for downscaling bitmapped fonts

Look at the accepted answer.

like image 130
F. P. Avatar answered Sep 29 '22 06:09

F. P.


If your lines will always be straight and you aren't looking to anti-alias curves, you can do a three-pass approach.

I'm not sure how efficient this would be in your environment, but you can draw the aliased version of the line with thickness - 2 and then use Xiaolin Wu's approach twice to anti-alias the edges. @Francisco P.'s approach would work, too, and might actually be preferable.

One way or another, the aliasing needs to be smoothed out along the outer edges. If you're dealing with lines of thickness greater than one, you can achieve this by just drawing the two edges anti-aliased and then filling in the middle.

like image 43
Xenethyl Avatar answered Sep 29 '22 06:09

Xenethyl