To get right to it: Say I’ve got two specific pixels a & b, as well as a list of random others. I now want to check all pixels in that list if they are on the line which passes through a & b (but which is NOT restricted to have a & b as endpoints!)
I looked at Bresenham’s line algorithm, but that seems to only find the points between a & b?
I’ve also had a look at linear equations in general but I’m kind of stuck on how to properly discretize the continuous line into pixels…
(I’m trying to implement a random sampling algorithm in java, which tries to find the line with the most pixels on it, if that matters).
Thanks a lot for any help with this 🙂
I strongly suggest that you compute the distance between the point and the line.
If you use one pixel as unit of measurement (which you will if you work in a pixel coordinate system), you can simply check if the distance from the point to the line is < 1.
Here’s how to compute the distance between a point and a line: