Data.Quaternion.Rotation
- Package
- purescript-quaternions
- Repository
- hdgarrood/purescript-quaternions
This module provides rotations in 3D space based on quaternions. It is intended to be imported qualified, for example like this:
import Data.Quaternion.Rotation (Rotation)
import Data.Quaternion.Rotation as Rotation
#Rotation Source
newtype Rotation aA rotation in three-dimensional space, represented by a unit quaternion (also known as a versor).
The constructor is not exported to ensure that only valid rotations can be constructed.
The semigroup instance provides composition of rotations; p <> q gives
a rotation representating the rotation q followed by the rotation p.
Note that in general, this is not the same as p followed by q!
Instances
#fromQuaternion Source
fromQuaternion :: Quaternion Number -> Rotation NumberConstruct a Rotation from any Quaternion, by normalizing to a versor.
#toQuaternion Source
toQuaternion :: forall a. Rotation a -> Quaternion aGet the underlying versor.
#showAngleAxis Source
showAngleAxis :: Rotation Number -> StringAn alternative string representation, which can be useful for debugging.
#inverse Source
inverse :: forall a. DivisionRing a => Rotation a -> Rotation aThe inverse of a rotation. The following should hold for any rotation p:
inverse p <> p == memptyp <> inverse p == mempty
#act Source
act :: forall a. DivisionRing a => Rotation a -> Vec3 a -> Vec3 aThe action of a rotation on a vector in 3D space. This is a group action, which means that the following hold:
- Identity:
act mempty == id - Compatibility:
act p (act q v) = act (p <> q) v
#normalize Source
normalize :: Rotation Number -> Rotation NumberThough all functions in this library which create a Rotation ensure that
the underlying Quaternion has magnitude 1, after a sufficient number of
arithmetic operations the magnitude may drift away from 1. In this case
normalize can be used; normalize takes a possibly-drifted Rotation
and rescales if it necessary, so that its magnitude returns to 1.