What coordinates does a line between two coordinates intersect?

44 Views Asked by At

I have a simple coordinate system like the following:

enter image description here

In this example, I have a line between two coordinates $(2,7)$ and $(8,5)$. The line is drawn from and to the exact center of each coordinate.

I'd like to calculate what coordinates are intersected by this line. Formulated differently: I need to know which coordinates the line touches.

Using the above coordinate system, a correct result would be:

$(2,7)\rightarrow(3,7)\rightarrow(4,6)\rightarrow(5,6)\rightarrow(6,6)\rightarrow(7,5) \rightarrow(8,5)$

The selected coordinates are just random, I'd like to be able to do the calculation no matter what two coordinates are selected.

Thanks in advance!