1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jan 25, 2009 #1

    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:


    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. jcsd
  3. Jan 25, 2009 #2
    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] 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 [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: Jan 25, 2009
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook