added two methods to btQuaternion, and add a note that the 'angle' method returns the half angle.
angleShortestPath and getAngleShortestPath Thanks to Tully Foote. This fixes issue 379.
This commit is contained in:
@@ -390,7 +390,7 @@ public:
|
|||||||
{
|
{
|
||||||
return *this / length();
|
return *this / length();
|
||||||
}
|
}
|
||||||
/**@brief Return the angle between this quaternion and the other
|
/**@brief Return the ***half*** angle between this quaternion and the other
|
||||||
* @param q The other quaternion */
|
* @param q The other quaternion */
|
||||||
btScalar angle(const btQuaternion& q) const
|
btScalar angle(const btQuaternion& q) const
|
||||||
{
|
{
|
||||||
@@ -398,6 +398,19 @@ public:
|
|||||||
btAssert(s != btScalar(0.0));
|
btAssert(s != btScalar(0.0));
|
||||||
return btAcos(dot(q) / s);
|
return btAcos(dot(q) / s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**@brief Return the angle between this quaternion and the other along the shortest path
|
||||||
|
* @param q The other quaternion */
|
||||||
|
btScalar angleShortestPath(const btQuaternion& q) const
|
||||||
|
{
|
||||||
|
btScalar s = btSqrt(length2() * q.length2());
|
||||||
|
btAssert(s != btScalar(0.0));
|
||||||
|
if (dot(q) < 0) // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp
|
||||||
|
return btAcos(dot(-q) / s) * btScalar(2.0);
|
||||||
|
else
|
||||||
|
return btAcos(dot(q) / s) * btScalar(2.0);
|
||||||
|
}
|
||||||
|
|
||||||
/**@brief Return the angle of rotation represented by this quaternion */
|
/**@brief Return the angle of rotation represented by this quaternion */
|
||||||
btScalar getAngle() const
|
btScalar getAngle() const
|
||||||
{
|
{
|
||||||
@@ -405,6 +418,19 @@ public:
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**@brief Return the angle of rotation represented by this quaternion along the shortest path*/
|
||||||
|
btScalar getAngleShortestPath() const
|
||||||
|
{
|
||||||
|
btScalar s;
|
||||||
|
if (dot(*this) < 0)
|
||||||
|
s = btScalar(2.) * btAcos(m_floats[3]);
|
||||||
|
else
|
||||||
|
s = btScalar(2.) * btAcos(-m_floats[3]);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**@brief Return the axis of the rotation represented by this quaternion */
|
/**@brief Return the axis of the rotation represented by this quaternion */
|
||||||
btVector3 getAxis() const
|
btVector3 getAxis() const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user