Re: quaternions revisited

New Message Reply Date view Thread view Subject view Author view

Jim Helman (jimh++at++surreal)
Wed, 27 Sep 95 13:58:53 -0700


2.0 includes the quaternion support listed below.

Also, pfMatrix::makeQuat(pfQuat &quat);

-jim

pfQuat(3pf) IRIS Performer 2.0 libpr C++ Reference Pages pfQuat(3pf)

NAME
     pfQuat - Set and operate on quaternions

FUNCTION SPECIFICATION
     #include <Performer/pr/pfLinMath.h>

     void pfQuat::makeRot(float angle, float x, float y, float z);

     void pfQuat::getRot(float *angle, float *x, float *y, float *z);

     float pfQuat::length(void);

     void pfQuat::conj(const pfQuat& q);

     void pfQuat::exp(const pfQuat& q);

     void pfQuat::log(const pfQuat& q);

     void pfQuat::mult(const pfQuat& q1, const pfQuat& q2);

     void pfQuat::div(const pfQuat& q1, const pfQuat& q2);

     void pfQuat::invert(const pfQuat& q);

     int pfQuat::equal(const pfQuat& q1, const pfQuat& q2);

     int pfQuat::almostEqual(const pfQuat& q1, const pfQuat& q2,
                     float tol);

     void pfQuat::slerp(float t, const pfQuat& q1, const pfQuat q2);

     void pfQuat::squad(float t, const pfQuat& q1, const pfQuat q2,
                     const pfQuat& a, const pfQuat& b);

     extern void pfQuat::meanTangent(const pfQuat& q1, const pfQuat& q2,
                     const pfQuat& q3);

          struct pfQuat : public pfVec4

PARENT CLASS FUNCTIONS
     The IRIS Performer class pfQuat is derived from the parent class pfVec4,
     so each of these member functions of class pfVec4 are also directly
     usable with objects of class pfQuat. Casting an object of class pfQuat
     to an object of class pfVec4 is taken care of automatically. This is
     also true for casts to objects of ancestor classes of class pfVec4.

     void pfVec4::addScaled(pfVec3& dst, const pfVec3& v1, float s,
               const pfVec3& v2);

                                                                        Page 1

pfQuat(3pf) IRIS Performer 2.0 libpr C++ Reference Pages pfQuat(3pf)

     void pfVec4::add(const pfVec4& v1, const pfVec4& v2);
     int pfVec4::almostEqual(const pfVec4& v2, float tol);
     void pfVec4::combine(float s1, const pfVec4& v1, float s2,
               const pfVec4& v2);
     void pfVec4::copy(const pfVec4& v);
     float pfVec4::distance(const pfVec4& pt2);
     float pfVec4::dot(const pfVec4& v2);
     int pfVec4::equal(const pfVec4 v2);
     float pfVec4::length(void);
     void pfVec4::negate(const pfVec4& v);
     float pfVec4::normalize(void);
     void pfVec4::scale(float s, const pfVec4& v);
     void pfVec4::set(float x, float y, float z, float w);
     float pfVec4::sqrDistance(const pfVec4& pt2);
     void pfVec4::sub(const pfVec4& v1, const pfVec4& v2);
     void pfVec4::xform(const pfVec4 v, const pfMatrix m);

DESCRIPTION
     pfQuat represents a quaternion as the four floating point values (x, y,
     z, w) of a pfVec4.

     pfQuat::makeRot converts an axis and angle rotation representation to a
     quaternion. pfQuat::getRot is the inverse operation. It produces the
     axis (as a unit length direction vector) and angle equivalent to the
     given quaternion. Also see pfMatrix::makeQuat and
     pfMatrix::getOrthoQuat.

     Several monadic quaternion operators are provided. pfQuat::conj produces
     the complex conjugate dst of q by negating only the complex components
     (x, y, and z) which results in an inverse rotation. pfQuat::exp and
     pfQuat::log perform complex exponentiation and logarithm functions
     respectively. The length of a quaternion is computed by pfQuat::length
     and is defined as the norm of all four quaternion components. Macro
     equivalents are PFCONJ_QUAT and PFLENGTH_QUAT. For negation, use the
     pfVec4 routine, pfVec4::negate.

     pfQuat::mult and pfQuat::div are dyadic quaternion operations which
     provide the product, and quotient of two quaternions. When quaternions
     are used to represent rotations, multiplication of two quaternions is
     equivalent, but more efficient, than the multiplication of the two
     correspondinging rotation matrices.

     pfQuat::invert computes the multiplicative inverse of a quaternion.
     These operations are the basis from which the other quaternion
     capabilities have been derived. Macro equivalents are PFMULT_QUAT,
     PFDIV_QUAT, and PFINVERT_QUAT. For addition and scalar multiplciation,
     use the pfVec4 routines pfVec4::add, pfVec4::sub, and pfVec4::scale.
     Comparisons can be made with the pfVec4 member functions pfVec4::equal
     and pfVec4::almostEqual, since pfQuat is derived from pfVec4.

     Interpolation of quaternions (as presented by Ken Shoemake) is an
     effective technique for rotation interpolation. Spherical linear

                                                                        Page 2

pfQuat(3pf) IRIS Performer 2.0 libpr C++ Reference Pages pfQuat(3pf)

     interpolation is performed with pfQuat::slerp, which produces a pfQuat
     that is t of the way between q1 and q2.

     Spherical quadratic interpolation is provided by pfQuat::squad and its
     helper function, pfQuat::meanTangent.

NOTES
     These functions use a pfVec4 to represent quaternions and store the
     imaginary part first, thus the array contents q = {x,y,z,w} are a
     representation of the quaternion w + xi + yj+ zk.

     Because both q and -q represent the same rotation (quaternions have a
     rotation range of [-360,360] degrees) conversions such as
     pfMatrix::getOrthoQuat make an arbitrary choice of the sign of the
     returned quaternion. To prevent the arbitrary sign from introducing
     large, unintended rotations, pfQuat::slerp checks the angle theta between
     q1 and q2. If theta exceeds 180 degrees, q2 is negated changing the
     interpolations range from [0,theta] to [0, theta-360 degrees].

     For more information on quaternions, see the article by by Sir William
     Rowan Hamilton "On quaternions; or on a new system of imaginaries in
     algebra," in the Philosophical Magazine, xxv pp. 10-13 (July 1844).
     More recent references include "Animating Rotation with Quaternion
     Curves," SIGGRAPH Proceedings Vol 19, Number 3, 1985, and "Quaternion
     Calculus For Animation," in "Math for SIGGRAPH", Course Notes, #23,
     SIGGRAPH 1989, both by Ken Shoemake. Note that for consistency with
     Performer's transformation order, pfQuats are the conjugates of the
     quaternions described in these references.

SEE ALSO
     pfVec4, pfMatrix

                                                                        Page 3


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:54 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.