# Returning each co-ord between two points of a linear line

1. Jan 25, 2009

### boo1234

Hi,

I need to come up with an equation/solution/way to return each of the co-ordinates between two points in a line.

This is for a game, I want to return the co-ords between two player locations.

Let's say for example player one is at 20,5 and player two is at 41,5

I need to return:

21,5
22,5
23,5
24,5
25,5

and so on up to 41,5

The points are dynamic

Help appreciated.

To clarify I need to return each TILE that the 'line' passes through between two players.

2. Jan 25, 2009

### The Dagda

Well you can just take $x_2-x_1$ that gives you the distance $x_2$ to $x_1$ lets call it a, then do the same for y and call it b, now simply add one to each co-ordinate or take one if a or b are negative to $x_1$ and $y_1$ respectively until a=$x_2-x_1$ or until b=$y_2-y_1$. If a and b respectively are equal to $x_2-x_1$ and $y_2-y_1$ then stop. Should provide you with each co-ordinate between the two points. Being a computer I'm sure it can update that in real time with no problems.

Last edited: Jan 25, 2009