spatial-math-0.2.1.1: 3d math including quaternions/euler angles/dcms and utility functions

Safe HaskellNone
LanguageHaskell2010

SpatialMath

Contents

Synopsis

Documentation

data Euler a Source

3-2-1 Euler angle rotation sequence

Constructors

Euler 

Fields

eYaw :: a
 
ePitch :: a
 
eRoll :: a
 

Instances

Functor Euler 
Foldable Euler 
Traversable Euler 
Generic1 Euler 
Eq a => Eq (Euler a) 
Data a => Data (Euler a) 
Ord a => Ord (Euler a) 
Show a => Show (Euler a) 
Generic (Euler a) 
Serialize a => Serialize (Euler a) 
Typeable (* -> *) Euler 
type Rep1 Euler 
type Rep (Euler a) 

rotateXyzAboutX :: Floating a => V3 a -> a -> V3 a Source

Rotate a vector about the X axis

>>> trunc $ rotateXyzAboutX (V3 0 1 0) (pi/2)
V3 0.0 0.0 1.0
>>> trunc $ rotateXyzAboutX (V3 0 0 1) (pi/2)
V3 0.0 (-1.0) 0.0

rotateXyzAboutY :: Floating a => V3 a -> a -> V3 a Source

Rotate a vector about the Y axis

>>> trunc $ rotateXyzAboutY (V3 0 0 1) (pi/2)
V3 1.0 0.0 0.0
>>> trunc $ rotateXyzAboutY (V3 1 0 0) (pi/2)
V3 0.0 0.0 (-1.0)

rotateXyzAboutZ :: Floating a => V3 a -> a -> V3 a Source

Rotate a vector about the Z axis

>>> trunc $ rotateXyzAboutZ (V3 1 0 0) (pi/2)
V3 0.0 1.0 0.0
>>> trunc $ rotateXyzAboutZ (V3 0 1 0) (pi/2)
V3 (-1.0) 0.0 0.0

euler321OfQuat :: RealFloat a => Quaternion a -> Euler a Source

Convert quaternion to Euler angles

>>> euler321OfQuat (Quaternion 1.0 (V3 0.0 0.0 0.0))
Euler {eYaw = 0.0, ePitch = -0.0, eRoll = 0.0}
>>> euler321OfQuat (Quaternion (sqrt(2)/2) (V3 (sqrt(2)/2) 0.0 0.0))
Euler {eYaw = 0.0, ePitch = -0.0, eRoll = 1.5707963267948966}
>>> euler321OfQuat (Quaternion (sqrt(2)/2) (V3 0.0 (sqrt(2)/2) 0.0))
Euler {eYaw = 0.0, ePitch = 1.5707963267948966, eRoll = 0.0}
>>> euler321OfQuat (Quaternion (sqrt(2)/2) (V3 0.0 0.0 (sqrt(2)/2)))
Euler {eYaw = 1.5707963267948966, ePitch = -0.0, eRoll = 0.0}

euler321OfDcm :: RealFloat a => M33 a -> Euler a Source

Convert DCM to euler angles

>>> euler321OfDcm $ V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1)
Euler {eYaw = 0.0, ePitch = -0.0, eRoll = 0.0}
>>> euler321OfDcm $ V3 (V3 0 1 0) (V3 (-1) 0 0) (V3 0 0 1)
Euler {eYaw = 1.5707963267948966, ePitch = -0.0, eRoll = 0.0}
>>> let s = sqrt(2)/2 in euler321OfDcm $ V3 (V3 s s 0) (V3 (-s) s 0) (V3 0 0 1)
Euler {eYaw = 0.7853981633974483, ePitch = -0.0, eRoll = 0.0}

quatOfEuler321 :: (Floating a, Ord a) => Euler a -> Quaternion a Source

Convert Euler angles to quaternion

>>> quatOfEuler321 (Euler 0 0 0)
Quaternion 1.0 (V3 0.0 0.0 0.0)
>>> quatOfEuler321 (Euler (pi/2) 0 0)
Quaternion 0.7071067811865476 (V3 0.0 0.0 0.7071067811865475)
>>> quatOfEuler321 (Euler 0 (pi/2) 0)
Quaternion 0.7071067811865476 (V3 0.0 0.7071067811865475 0.0)
>>> quatOfEuler321 (Euler 0 0 (pi/2))
Quaternion 0.7071067811865476 (V3 0.7071067811865475 0.0 0.0)

dcmOfQuat :: Num a => Quaternion a -> M33 a Source

convert a quaternion to a DCM

>>> dcmOfQuat $ Quaternion 1.0 (V3 0.0 0.0 0.0)
V3 (V3 1.0 0.0 0.0) (V3 0.0 1.0 0.0) (V3 0.0 0.0 1.0)
>>> let s = sqrt(2)/2 in fmap trunc $ dcmOfQuat $ Quaternion s (V3 0.0 0.0 s)
V3 (V3 0.0 1.0 0.0) (V3 (-1.0) 0.0 0.0) (V3 0.0 0.0 1.0)
>>> dcmOfQuat $ Quaternion 0.9238795325112867 (V3 0.0 0.0 0.3826834323650898)
V3 (V3 0.7071067811865475 0.7071067811865476 0.0) (V3 (-0.7071067811865476) 0.7071067811865475 0.0) (V3 0.0 0.0 1.0)

dcmOfEuler321 :: (Floating a, Ord a) => Euler a -> M33 a Source

Convert DCM to euler angles

>>> dcmOfEuler321 $ Euler {eYaw = 0.0, ePitch = 0, eRoll = 0}
V3 (V3 1.0 0.0 0.0) (V3 0.0 1.0 0.0) (V3 0.0 0.0 1.0)
>>> fmap trunc $ dcmOfEuler321 $ Euler {eYaw = pi/2, ePitch = 0, eRoll = 0}
V3 (V3 0.0 1.0 0.0) (V3 (-1.0) 0.0 0.0) (V3 0.0 0.0 1.0)
>>> dcmOfEuler321 $ Euler {eYaw = pi/4, ePitch = 0, eRoll = 0}
V3 (V3 0.7071067811865475 0.7071067811865476 0.0) (V3 (-0.7071067811865476) 0.7071067811865475 0.0) (V3 0.0 0.0 1.0)

quatOfDcm :: RealFloat a => M33 a -> Quaternion a Source

convert a DCM to a quaternion

>>> quatOfDcm $ V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1)
Quaternion 1.0 (V3 0.0 0.0 0.0)
>>> quatOfDcm $ V3 (V3 0 1 0) (V3 (-1) 0 0) (V3 0 0 1)
Quaternion 0.7071067811865476 (V3 0.0 0.0 0.7071067811865475)
>>> let s = sqrt(2)/2 in quatOfDcm $ V3 (V3 s s 0) (V3 (-s) s 0) (V3 0 0 1)
Quaternion 0.9238795325112867 (V3 0.0 0.0 0.3826834323650898)

rotVecByDcm :: Num a => M33 a -> V3 a -> V3 a Source

vec_b = R_a2b * vec_a

rotVecByDcmB2A :: Num a => M33 a -> V3 a -> V3 a Source

vec_a = R_a2b^T * vec_b

rotVecByQuat :: Num a => Quaternion a -> V3 a -> V3 a Source

vec_b = q_a2b * vec_a * q_a2b^(-1) vec_b = R(q_a2b) * vec_a

rotVecByEuler :: (Floating a, Ord a) => Euler a -> V3 a -> V3 a Source

rotVecByEulerB2A :: (Floating a, Ord a) => Euler a -> V3 a -> V3 a Source

re-exported from linear

type M33 a = V3 (V3 a)

A 3x3 matrix with row-major representation

data V3 a :: * -> *

A 3-dimensional vector

Constructors

V3 !a !a !a 

Instances

Monad V3 
Functor V3 
MonadFix V3 
Applicative V3 
Foldable V3 
Traversable V3 
Generic1 V3 
Distributive V3 
Representable V3 
MonadZip V3 
Serial1 V3 
Traversable1 V3 
R3 V3 
R2 V3 
R1 V3 
Metric V3 
Additive V3 
Foldable1 V3 
Apply V3 
Bind V3 
Eq1 V3 
Ord1 V3 
Read1 V3 
Show1 V3 
Unbox a => Vector Vector (V3 a) 
Unbox a => MVector MVector (V3 a) 
Bounded a => Bounded (V3 a) 
Eq a => Eq (V3 a) 
Floating a => Floating (V3 a) 
Fractional a => Fractional (V3 a) 
Data a => Data (V3 a) 
Num a => Num (V3 a) 
Ord a => Ord (V3 a) 
Read a => Read (V3 a) 
Show a => Show (V3 a) 
Ix a => Ix (V3 a) 
Generic (V3 a) 
Storable a => Storable (V3 a) 
Binary a => Binary (V3 a) 
Serial a => Serial (V3 a) 
Serialize a => Serialize (V3 a) 
NFData a => NFData (V3 a) 
Hashable a => Hashable (V3 a) 
Unbox a => Unbox (V3 a) 
Ixed (V3 a) 
Epsilon a => Epsilon (V3 a) 
FunctorWithIndex (E V3) V3 
FoldableWithIndex (E V3) V3 
TraversableWithIndex (E V3) V3 
Num a => Rotation (M33 a) a 
Each (V3 a) (V3 b) a b 
Typeable (* -> *) V3 
type Rep1 V3 = D1 D1V3 (C1 C1_0V3 ((:*:) (S1 NoSelector Par1) ((:*:) (S1 NoSelector Par1) (S1 NoSelector Par1)))) 
type Rep V3 = E V3 
data MVector s (V3 a) = MV_V3 !Int (MVector s a) 
type Rep (V3 a) = D1 D1V3 (C1 C1_0V3 ((:*:) (S1 NoSelector (Rec0 a)) ((:*:) (S1 NoSelector (Rec0 a)) (S1 NoSelector (Rec0 a))))) 
data Vector (V3 a) = V_V3 !Int (Vector a) 
type Index (V3 a) = E V3 
type IxValue (V3 a) = a 

data Quaternion a :: * -> *

Quaternions

Constructors

Quaternion !a !(V3 a) 

Instances

Monad Quaternion 
Functor Quaternion 
MonadFix Quaternion 
Applicative Quaternion 
Foldable Quaternion 
Traversable Quaternion 
Generic1 Quaternion 
Distributive Quaternion 
Representable Quaternion 
MonadZip Quaternion 
Serial1 Quaternion 
Complicated Quaternion 
Hamiltonian Quaternion 
Metric Quaternion 
Additive Quaternion 
Apply Quaternion 
Bind Quaternion 
Eq1 Quaternion 
Ord1 Quaternion 
Read1 Quaternion 
Show1 Quaternion 
Unbox a => Vector Vector (Quaternion a) 
Unbox a => MVector MVector (Quaternion a) 
Eq a => Eq (Quaternion a) 
RealFloat a => Floating (Quaternion a) 
RealFloat a => Fractional (Quaternion a) 
Data a => Data (Quaternion a) 
RealFloat a => Num (Quaternion a) 
Ord a => Ord (Quaternion a) 
Read a => Read (Quaternion a) 
Show a => Show (Quaternion a) 
Ix a => Ix (Quaternion a) 
Generic (Quaternion a) 
Storable a => Storable (Quaternion a) 
Binary a => Binary (Quaternion a) 
Serial a => Serial (Quaternion a) 
Serialize a => Serialize (Quaternion a) 
NFData a => NFData (Quaternion a) 
Hashable a => Hashable (Quaternion a) 
Unbox a => Unbox (Quaternion a) 
Ixed (Quaternion a) 
(Conjugate a, RealFloat a) => Conjugate (Quaternion a) 
(RealFloat a, Epsilon a) => Epsilon (Quaternion a) 
FunctorWithIndex (E Quaternion) Quaternion 
FoldableWithIndex (E Quaternion) Quaternion 
TraversableWithIndex (E Quaternion) Quaternion 
Num a => Rotation (Quaternion a) a 
Each (Quaternion a) (Quaternion b) a b 
Typeable (* -> *) Quaternion 
type Rep1 Quaternion = D1 D1Quaternion (C1 C1_0Quaternion ((:*:) (S1 NoSelector Par1) (S1 NoSelector (Rec1 V3)))) 
type Rep Quaternion = E Quaternion 
data MVector s (Quaternion a) = MV_Quaternion !Int (MVector s a) 
type Rep (Quaternion a) = D1 D1Quaternion (C1 C1_0Quaternion ((:*:) (S1 NoSelector (Rec0 a)) (S1 NoSelector (Rec0 (V3 a))))) 
data Vector (Quaternion a) = V_Quaternion !Int (Vector a) 
type Index (Quaternion a) = E Quaternion 
type IxValue (Quaternion a) = a