pixel coordinates of a line [message #25547] |
Wed, 27 June 2001 23:29  |
marc schellens[1]
Messages: 183 Registered: January 2000
|
Senior Member |
|
|
Hello everybody,
I want to extract pixels along a line.
I know start and endpoint (ie. I draw the line in top of the
image).
How to get the pixel values? Do I have to do it 'by hand'?
thanks,
marc
|
|
|
Re: pixel coordinates of a line [message #25606 is a reply to message #25547] |
Mon, 02 July 2001 03:47  |
Struan Gray
Messages: 178 Registered: December 1995
|
Senior Member |
|
|
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
coordinate.
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.
Struan
|
|
|