[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pixel coordinates of a line

    A blast from the past.  I'm old enough to have had to
write my own graphical user interface from scratch.  I did
so on a curious HP Pascal Workstation, which had a graphics
library based on HPGL, but the plotting was *one* *hundred*
times slower than if you just stuffed pixels into the
display memory yourself.

    Anyway, my algorithm for drawing a line was this:

    First clip the line (if necessary) using
geometry-derived algebra like Tom's, this gives you (x1,y1)
and (x2,y2), the screen coordinates of the line that will
actually be drawn.

    Then find out which of (x2-x1) and (y2-y1) had the
largest magnitude, this gives you the number of pixels,
since there will be one pixel for each integer value of this

    Finally, loop through the coordinates for whichever axis
had the longest span, adding the index times the line's
slope to the other coordinate.  Using integer maths made the
rounding off automatic and fast.  In IDL you could do this
step as a matrix operation with an index matrix.