/** Gets the oriented angle between 2 vectors.
@remarks
Vectors do not have to be unit-length but must represent directions.
The angle is comprised between 0 and 2 PI.
*/
inline Ogre::Radian angleTo(const Ogre::Vector2& other) const
{
Ogre::Radian angle = angleBetween(other);
if (crossProduct(other)<0)
angle = (Ogre::Radian)Ogre::Math::TWO_PI - angle;
return angle;
}
Can someone explain to me what does this code and why it is necessary?
the Function angleBetween() returns a value between 0 and pi (exakt opposit) because it is not directed.
so on a clock if a points to 12, b points to 3 and c points to 9 then a.angleBetween(b) would be the same as a.angleBetween(c): pi/2.
angleTo() returns a value between 0 and 2pi (complete circle) because the angle is directed (right-handed). so in the above example a.angleTo(b) would still be pi/2 but a.angleTo(c) would be 3/2 pi. The check crossProduct()<0 checks if the angle is suppost to be larger than pi (this is due to the definition of the cross product)