vect-floating-0.1.0.4: A low-dimensional linear algebra library, operating on the Floating typeclass

Data.Vect.Floating.Util.Quaternion

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

newtype Quaternion a Source

The type for quaternions.

Constructors

 Q (Vec4 a)

Instances

 Floating a => DotProd a Quaternion Floating a => Vector a Quaternion Floating a => UnitVector a Quaternion UnitQuaternion Floating a => Interpolate a (Quaternion a) Read a => Read (Quaternion a) Show a => Show (Quaternion a) (Floating a, Storable a) => Storable (Quaternion a) (Floating a, Random a) => Random (Quaternion a) Num a => MultSemiGroup (Quaternion a) Floating a => AbelianGroup (Quaternion a) Typeable (* -> *) Quaternion

newtype UnitQuaternion a Source

The type for unit quaternions.

Constructors

 U (Vec4 a)

Instances

 Floating a => DotProd a UnitQuaternion Floating a => UnitVector a Quaternion UnitQuaternion Read a => Read (UnitQuaternion a) Show a => Show (UnitQuaternion a) (Floating a, Storable a) => Storable (UnitQuaternion a) (Floating a, Ord a, Random a) => Random (UnitQuaternion a) Floating a => MultSemiGroup (UnitQuaternion a) Num a => LeftModule (UnitQuaternion a) (Vec3 a) Typeable (* -> *) UnitQuaternion

type Q = Quaternion Source

An abbreviated type synonym for quaternions

An abbreviated type synonym for unit quaternions

# general quaternions

unitQ :: Num a => Q a Source

zeroQ :: Num a => Q a Source

multQ :: Num a => Q a -> Q a -> Q a Source

negQ :: Floating a => Q a -> Q a Source

normalizeQ :: Floating a => Q a -> Q a Source

invQ :: Floating a => Q a -> Q a Source

The inverse quaternion

fromQ :: Q a -> Vec4 a Source

toQ :: Vec4 a -> Q a Source

# unit quaternions

unitU :: Num a => U a Source

multU :: Num a => U a -> U a -> U a Source

negU :: Floating a => U a -> U a Source

The opposite quaternion (which encodes the same rotation)

normalizeU :: Floating a => U a -> U a Source

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 :: Num a => U a -> U a Source

The inverse of a unit quaternion

fromU :: Num a => U a -> Vec4 a Source

fromU' :: Floating a => U a -> Normal4 a Source

mkU :: Floating a => Vec4 a -> U a Source

toU :: Floating a => Normal4 a -> U a Source

unsafeToU :: Num a => Vec4 a -> U a Source

# unit quaternions as rotations

actU :: Num a => U a -> Vec3 a -> Vec3 a Source

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

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

actU' :: Floating a => U a -> Normal3 a -> Normal3 a Source

rotU :: Floating a => Vec3 a -> a -> U a Source

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 `

rotU' :: Floating a => Normal3 a -> a -> U a Source

longSlerpU :: Floating a => a -> U a -> U a -> U a Source

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 :: (Floating a, Ord a) => a -> U a -> U a -> U a Source

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 :: Floating a => U a -> Ortho3 a Source

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 :: Floating a => U a -> Ortho3 a Source

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`