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.
You should not only swap
plot(x,y)withplot(y,x)but also exchange the input parametersx1<->y1andx2<->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
xrange. 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
xandybut at the same time the output coordinate system (by exchangingxandyin the plot function).