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

Safe Haskell Safe-Inferred

SpatialMath

Contents

Synopsis

Documentation

data Euler a Source

3-2-1 Euler angle rotation sequence

Constructors

 Euler FieldseYaw :: a ePitch :: a eRoll :: a

Instances

 Functor Euler Typeable1 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)

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

Rotate a vector about the X axis

````>>> ````rotateXyzAboutX (V3 0 1 0) (pi/2)
```V3 0.0 6.123233995736766e-17 1.0
```
````>>> ````rotateXyzAboutX (V3 0 0 1) (pi/2)
```V3 0.0 (-1.0) 6.123233995736766e-17
```

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

Rotate a vector about the Y axis

````>>> ````rotateXyzAboutY (V3 0 0 1) (pi/2)
```V3 1.0 0.0 6.123233995736766e-17
```
````>>> ````rotateXyzAboutY (V3 1 0 0) (pi/2)
```V3 6.123233995736766e-17 0.0 (-1.0)
```

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

Rotate a vector about the Z axis

````>>> ````rotateXyzAboutZ (V3 1 0 0) (pi/2)
```V3 6.123233995736766e-17 1.0 0.0
```
````>>> ````rotateXyzAboutZ (V3 0 1 0) (pi/2)
```V3 (-1.0) 6.123233995736766e-17 0.0
```

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

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 aSource

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 aSource

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 aSource

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 dcmOfQuat \$ Quaternion s (V3 0.0 0.0 s)
```V3 (V3 0.0 1.0000000000000002 0.0) (V3 (-1.0000000000000002) 0.0 0.0) (V3 0.0 0.0 1.0000000000000002)
```
````>>> ````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 aSource

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)
```
````>>> ````dcmOfEuler321 \$ Euler {eYaw = pi/2, ePitch = 0, eRoll = 0}
```V3 (V3 2.220446049250313e-16 1.0 0.0) (V3 (-1.0) 2.220446049250313e-16 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 aSource

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 aSource

vec_b = R_a2b * vec_a

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

vec_a = R_a2b^T * vec_b

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

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 aSource

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

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 Typeable1 V3 Applicative V3 Foldable V3 Traversable V3 Distributive V3 R3 V3 R2 V3 R1 V3 Core V3 Metric V3 Additive V3 Traversable1 V3 Foldable1 V3 Apply V3 Bind V3 Eq a => Eq (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) Storable a => Storable (V3 a) Epsilon a => Epsilon (V3 a)

data Quaternion a

Quaternions

Constructors

 Quaternion !a !(V3 a)

Instances

 Monad Quaternion Functor Quaternion Typeable1 Quaternion Applicative Quaternion Foldable Quaternion Traversable Quaternion Distributive Quaternion Complicated Quaternion Hamiltonian Quaternion Core Quaternion Metric Quaternion Additive Quaternion Apply Quaternion Bind Quaternion 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) Storable a => Storable (Quaternion a) (Conjugate a, RealFloat a) => Conjugate (Quaternion a) (RealFloat a, Epsilon a) => Epsilon (Quaternion a)