math - Determine the distance of a Vector 3 along another Vector 3 -
i have 2 3d vectors. (objects x, y , z float values)
in diagram below, determine length of green line. distance along vector 1 vector 2 is. or, distance origin end of line on vector 1 @ 90' vector 1 , passes thorough point @ end of vector 2.
i doing in unity3d have access quite few helper methods enable me length of vector3 , on easily.
the length obviously
norm(v2)*cos(angle(v1,v2))
and since
cos(angle(v1,v2))=abs(dot(v1,v2))/norm(v1)/norm(v2)
the final formula is
abs(dot(v1,v2))/norm(v1)
one
e1 = v1/norm(v1)
is unit vector in direction of v1
, , green vector is
dot(e1,v2)*e1
resulting in same length formula.
Comments
Post a Comment