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

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
boo1234
Messages
1
Reaction score
0
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.
 
Physics news on Phys.org
Well you can just take [itex]x_2-x_1[/itex] that gives you the distance [itex]x_2[/itex] to [itex]x_1[/itex] let's 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 [itex]x_1[/itex] and [itex]y_1[/itex] respectively until a=[itex]x_2-x_1[/itex] or until b=[itex]y_2-y_1[/itex]. If a and b respectively are equal to [itex]x_2-x_1[/itex] and [itex]y_2-y_1[/itex] 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: