Math-Set vector length keeping the angle

From Vectorlab
Jump to: navigation, search


Given two vectors representing start and end point of a line and a distance, returns the vector with the coordinates of the new end pt of the line built by the vectors while keeping their angle. By Orso B. Schmid


{ Orso ***************************** }
{ given two vectors representing start and end pt of a line and a distance, }
{ returns the vector with the coordinates of the new end pt of the line, }
{ like reshaping the line to the new length = distance, keeping the angle }
FUNCTION M_Set2Distance(startV, endV : VECTOR; dist: REAL): VECTOR;
	BEGIN
		{ M_Set2Distance := startV + Ang2Vec(Vec2Ang(endV - startV), 1) * dist; }
		M_Set2Distance := startV + (UnitVec(endV - startV) * dist); { is the same as the previous }
	END;