How to get xy coordinates along a given path
- by netbrain
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?