Let’s say I have two points on a Cartesian coordinate plane, A and B, whose x and y coordinates are double-precision floats. How do I find the location of a point C that is an arbitrary percent of the distance between them?
In other words, what goes in the following method instead of “//Do magic to C“? Remember that A and B each consist of two doubles, which represent their respective x and y coordinates.
public static findProgressPoint(DoublePoint A, DoublePoint B, double position)
{
if (position > 1 || position < 0) //Ensure that position is between 0 and 1, inclusive
position = position - (int)position;
DoublePoint C = new DoublePoint(0.0, 0.0);
//Do magic to C
return C;
}
This should work:
pxis thexcoordinate betweenx1andx2at the distance fromx1proportional to the value ofposition;pyis the correspondingycoordinate.