I implemented/copied the wu line algorithm from pseudo-code on wiki-pedia and other places.

When drawing a sine wave it breaks down at the point where the line changes from y dominant to x dominant (or vice versa). (I did not copy the endpoint code because it looks terrible and I do not need them for my purposes. )

Does anyone know a solution for this issue? If not I will modify the algorithm myself to get it to work. I am just curious if someone else has run into this and knows exactly how to fix it. Is it possible to implement without the lines being globally aware of each other? Or is this why drawing API's implement moveto and lineto functions?

The pseudo code


Are your pixel pairs really covering the line points? You appear to have an off-by-one error in your algorithm implementation.

I suggest plotting the aliased version of your curve and superposing the two images, maybe using two separate colour channels. You will probably see where the error lies. Or you could post some code for double checking.

| improve this answer | |
  • \$\begingroup\$ Yea the issue is fractional points....and perhaps lines that are less than one pixel long. There is a rounding error so when the next line is drawn in certain cases it draws it one off from the the last endpoint. I am working on it. \$\endgroup\$ – eat_a_lemon Apr 24 '11 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.