calculate angles between two vectors
Posted: Tue Jan 26, 2010 4:16 pm
Hello guys,
Is a quite simple, but a useful tool. I think there is nothing like this in class vector3d. So, I built this inside vector3d.h and worked fine.
That's it.
Is a quite simple, but a useful tool. I think there is nothing like this in class vector3d. So, I built this inside vector3d.h and worked fine.
Code: Select all
//! Get angle between vectors
T getAngleBetween (const vector3d<T>& vec2)
{
f32 angle;
angle = acos((X * vec2.X + Y * vec2.Y + Z * vec2.Z)/(
sqrt(X*X + Y*Y + Z*Z) * sqrt(pow(vec2.X,2) + pow(vec2.Y,2) + pow(vec2.Z,2))
));
return angle;
}