Wu's anti-aliasing algorithm, vertical lines

635 views Asked by At

I've been implementing Wu's algorithm mostly per Xiaolin Wu's algorithm, but have run into a bit of a snag. Specifically, this bit of the algorithm, which is included by a note at the bottom of the wiki entry:

If at the beginning of the routine abs(dx) < abs(dy) is true, 
then all plotting should be done with x and y reversed.

I thought that this meant just reverse all the calls to plot(x, y) with plot(y, x), but doing so resulted in some very special looking lines (I can't seem to get a screenshot because every time I try, my OpenGL window pastes blank into Paint).

Can anyone who has implemented this before give me a bit of guidance? My lines look a bit silly right now with only half of each quadrant filled.

1

There are 1 answers

0
Howard On

You should not only swap plot(x,y) with plot(y,x) but also exchange the input parameters x1<->y1 and x2<->y2. If you do both it´ll work correctly. The latter part is done in the code in the article but not the switch of the plot coordinates.

Reason behind is that you step pixel by pixel in x range. If your horizontal extent is less than vertical it might yield gaps (think e.g. a perfectly vertical line which would result it a single x-value only).

Therefore you switch input parameters x and y but at the same time the output coordinate system (by exchanging x and y in the plot function).