0

Let's say I know two points that make up a line. I want to know the points in which this line goes through a matrix or a drawable of an image (both of which I have access to, so whichever one would be easier to use is welcome). Any ideas on how I can do this?

ElectronAnt
  • 2,115
  • 7
  • 22
  • 39
  • Are the points in 3D and the matrix in some defined position in 3D? – Ted Hopp Jun 25 '12 at 17:27
  • Ah. When you refer to "the points in which this line goes through a matrix", do you mean the pixels that it intersects? Points have zero dimension and pixels have a defined size. – Ted Hopp Jun 25 '12 at 17:29
  • good point. the line is actually a vertical line and i know its x coordinate (ie where on the screen the line is positioned) – ElectronAnt Jun 25 '12 at 17:32

1 Answers1

0

The starting point for you would be a line drawing algorithm. There are many line drawing algorithms. Check the wiki page.

dx = x2 - x1
dy = y2 - y1
for x from x1 to x2 {
        y = y1 + (dy) * (x - x1)/(dx)
        plot(x, y)
}

Given 2 pointsas input to this algorithm, it will plot all the points in-between them. The points can be then mapped to the image in question.

Ron
  • 24,175
  • 8
  • 56
  • 97