vect-0.4.7: A low-dimensional linear algebra library, tailored to computer graphics.

Data.Vect.Double.Util.Quaternion

Contents

Description

The unit sphere in the space of quaternions has the group structure SU(2) coming from the quaternion multiplication, which is the double cover of the group SO(3) of rotations in R^3. Thus, unit quaternions can be used to encode rotations in 3D, which is a more compact encoding (4 floats) than a 3x3 matrix; however, there are two quaternions corresponding to each rotation.

See http://en.wikipedia.org/wiki/Quaternion and http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation for more information.

Synopsis

types

type Q = QuaternionSource

An abbreviated type synonym for quaternions

type U = UnitQuaternionSource

An abbreviated type synonym for unit quaternions

general quaternions

multQ :: Q -> Q -> QSource

negQ :: Q -> QSource

invQ :: Q -> QSource

The inverse quaternion

unit quaternions

multU :: U -> U -> USource

negU :: U -> USource

The opposite quaternion (which encodes the same rotation)

normalizeU :: U -> USource

This is no-op, up to numerical imprecision. However, if you multiply together a large number of unit quaternions, it may be a good idea to normalize the end result.

invU :: U -> USource

The inverse of a unit quaternion

unit quaternions as rotations

actU :: U -> Vec3 -> Vec3Source

The left action of unit quaternions on 3D vectors. That is,

 actU q1 $ actU q2 v  ==  actU (q1 `multU` q2) v 

rotU :: Vec3 -> Double -> USource

The quaternion to encode rotation around an axis. Please note that quaternions act on the left, that is

 rotU axis1 angl1 *. rotU axis2 angl2 *. v  ==  (rotU axis1 angl1 .*. rotU axis2 angl2) *. v 

longSlerpU :: Double -> U -> U -> USource

Interpolation of unit quaternions. Note that when applied to rotations, this may be not what you want, since it is possible that the shortest path in the space of unit quaternions is not the shortest path in the space of rotations; see slerpU!

slerpU :: Double -> U -> U -> USource

This is shortest path interpolation in the space of rotations; however this is achieved by possibly flipping the first endpoint in the space of quaternions. Thus slerpU 0.001 q1 q2 may be very far from q1 (and very close to negU q1) in the space of quaternions (but they are very close in the space of rotations).

rightOrthoU :: U -> Ortho3Source

Makes a rotation matrix (to be multiplied with on the right) out of a unit quaternion:

 v .* rightOrthoU (rotU axis angl)  ==  v .* rotMatrix3 axis angl

Please note that while these matrices act on the right, quaternions act on the left; thus

 rightOrthoU q1 .*. rightOrthoU q2  ==  rightOrthoU (q2 .*. q1)

leftOrthoU :: U -> Ortho3Source

Makes a rotation matrix (to be multiplied with on the left) out of a unit quaternion.

 leftOrthoU (rotU axis angl) *. v  ==  v .* rotMatrix3 axis angl