Quaternion slerp(Quaternion q, Quaternion r, double a)
Quaternion qmid(Quaternion q, Quaternion r)
Quaternion qsqrt(Quaternion q)
DESCRIPTION
The Quaternions are a non-commutative extension field of the Real numbers, designed
to do for rotations in 3-space what the complex numbers do for rotations in 2-space.
Quaternions have a real component
r
and an imaginary vector component v=(i,j,k).
Quaternions add componentwise and multiply according to the rule
(r,v)(s,w)=(rs-vv'-.3m'.v'.3m'w, rw+vs+v&215;w),
where v'-.3m'.v'.3m' and &215; are the ordinary vector dot and cross products.
The multiplicative inverse of a non-zero quaternion (r,v)
is (r,-v)/(r^u\\d-vv'-.3m'.v'.3m'v).
The following routines do arithmetic on quaternions, represented as
Return the multiplicative inverse of a quaternion.
qlen
Return
sqrt(q.r*q.r+q.i*q.i+q.j*q.j+q.k*q.k),
the length of a quaternion.
qunit
Return a unit quaternion
(length=1)
with components proportional to
q's.
A rotation by angle THETA about axis
A
(where
A
is a unit vector) can be represented by
the unit quaternion q=(cos THETA/2, Asin THETA/2).
The same rotation is represented by -q; a rotation by -THETA about -A is the same as a rotation by THETA about A.
The quaternion q transforms points by
(0,x',y',z') = %qu\\d(0,x,y,z)q.
Quaternion multiplication composes rotations.
The orientation of an object in 3-space can be represented by a quaternion
giving its rotation relative to some `standard' orientation.
The following routines operate on rotations or orientations represented as unit quaternions:
mtoq
Convert a rotation matrix (see
tstack(9.2))
to a unit quaternion.
qtom
Convert a unit quaternion to a rotation matrix.
slerp
Spherical lerp. Interpolate between two orientations.
The rotation that carries
q
to
r
is %qu\\dr, so
slerp(q, r, t)
is q(qu\\dr)u\t\d.
qmid
slerp(q, r, .5)
qsqrt
The square root of
q.
This is just a rotation about the same axis by half the angle.