finding point on the vector

i have two vectors that i use to render line. i am trying to get two points on the line that is 10% of the length distant from the end and beginning so actually i would render two lines that are part of the big line, check out the attachment

Uploaded with ImageShack.us

any help appreciated!

Early morning maths…

  1. Get the length of the line
  2. Get percentage of that length i.e. ( length / 100 ) * x
  3. Get the directional vector of the line, times by step 2 result
  4. P1 plus step 3 result

Im sure theres a quicker way of doing this but its 9am.

Something like this I guess:

function SplitLine(p1 : Vector3, p2: Vector3, startDistance : float, endDistance : float) : Vector3[]
{
	var directionUnitVector : Vector3 = (p2 - p1).normalized;
	
	var p1EndPoint : Vector3 = p1 + (directionUnitVector * startDistance);
	var p2EndPoint : Vector3 = p2 + (-directionUnitVector * endDistance);
	
	return [p1EndPoint, p2EndPoint];
}

Lerp will come in handy here.

tenPercent = Vector3.Lerp(p1, p2, 0.10);
ninetyPercent = Vector3.Lerp(p1, p2, 0.90);

now you have your 4 points.

Lerp performs a linear interpolation between 2 values based on a percentage. (read up on the various permutations of Lerp/Slerp in the docs for specifics and differences of datatypes such as Lerp’ing a color variable)

I had a feeling there was something built-in that would do exactly this, thanks Mitch.

thank you all!