How to get xy coordinates along a given path

Posted by netbrain on Game Development See other posts from Game Development or by netbrain
Published on 2012-07-09T19:29:58Z Indexed on 2012/07/09 21:23 UTC
Read the original article Hit count: 218

Say i have two points (x,y), (0,0) and (10,10). Now i wan´t to get coordinates along the line by stepping through values of x and y. I thought i solved it with the following functions:

 fy = startY + (x - startX) * ((destY-startY)/(destX-startX));
 fx = (y + startY) / ((destY-startY)/(destX-startX)) + startX;

taken from http://en.wikipedia.org/wiki/Linear_interpolation

However, it seems that im getting a problem when destX and startX is the same value, so you get division by zero.

Is there a better way of getting coordinates along a line when knowing the start and endpoint of the line?

© Game Development or respective owner

Related posts about game-mechanics

Related posts about coordinates