I have a generic not normalized Vector3 v1
and I want to calculate its component along another Vector3 v2
. I used to normalize the vector I want to be the direction and then multiplying the other vector's magnitude for it. I can't really understand if it would also work to multiply the other vector (not just its magnitude), but I want to know if there is a lighter way to do it, since compute the magnitude of a vector implies evaluating a square root.
In code I would say
Vector3 v1;
Vector3 v2; v2.Normalize();
Vector3 resulting_v = v1.Length() * v2;
the other case (I am not sure if can work) would be
Vector3 v1;
Vector3 v2; v2.Normalize();
Vector3 resulting_v = v1 * v2;
or, if there is a better solution, I'm listening