• Advertisement
Sign in to follow this  

certain distance along a line

This topic is 4937 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Currently, I use this to move along lines:
private Vector3 PointOnLine(Vector3 startPT, Vector3 directionPT, float parNum)
{
	Vector3 newVector = new Vector3();
	newVector.X = (startPT.X + (parNum * directionPT.X));
	newVector.Y = (startPT.Y + (parNum * directionPT.Y));
	newVector.Z = (startPT.Z + (parNum * directionPT.Z));
	return newVector;
}
how do i do the same thing using "parNum" to obtain a "newVector" that is a certain distance from "startPT" along the line created by "startPT" and "directionPT" effectively, "parNum" should be the distance; i need to modify this function so that it returns a Vector3 that is "parNum" units away from "startPT" along the line created by "startPT" and "directionPT"

Share this post


Link to post
Share on other sites
Advertisement

v = directionPT - startPT; // Get vector between points
v.Normalize(); // normalize to unit vector
v *= parNum; // multiply unit vector by number of units along line
v += startPT; // make it start from teh start

Share this post


Link to post
Share on other sites

private Vector3 PointOnLine(Vector3 startPT, Vector3 directionPT, float parNum)
{
Vector3 newVector = new Vector3();
float Length = directionPT.Length();
parNum /= Length;
newVector.X = (startPT.X + (parNum * directionPT.X));
newVector.Y = (startPT.Y + (parNum * directionPT.Y));
newVector.Z = (startPT.Z + (parNum * directionPT.Z));
return newVector;
}

with that function, if you pass in a distance for parNum, it will do the same as if you pass in 0-1 now. IFooBar misunderstood, he thought directionPT was the end point, which is why what he said doesn't work. It should work if you change it to this:

v = directionPT; // Get vector between points, directionPT is already the vector between the points
v.Normalize(); // normalize to unit vector
v *= parNum; // multiply unit vector by number of units along line
v += startPT; // make it start from teh start

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement