HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulenumeric-prelude-0.4.4Haskell98

Number.Quaternion

Quaternions

  • 1 type
  • 18 values

Cartesian form

5 declarations
datadata T a
#

Quaternions could be defined based on Complex numbers. However quaternions are often considered as real part and three imaginary parts.

Instances12Sqr, Eq, Read, Show, C, …
  • C TDefined in numeric-prelude-0.4.4 · Number.Quaternion
  • C a b => C a (T b)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • C a b => C a (T b)Defined in numeric-prelude-0.4.4 · Number.Quaternion

    The (*>) method can't replace scale because it requires the Algebra.Module constraint

  • (C a, Sqr a b) => C a (T b)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • Sqr a b => Sqr a (T b)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • Eq a => Eq (T a)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • Read a => Read (T a)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • Show a => Show (T a)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • C a => C (T a)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • C a => C (T a)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • C a => C (T a)Defined in numeric-prelude-0.4.4 · Number.Quaternion
  • C a => C (T a)Defined in numeric-prelude-0.4.4 · Number.Quaternion
valuereal :: T a -> a
#

real part

valueimag :: T a -> (a, a, a)
#

imaginary parts

value(+::) :: a -> (a, a, a) -> T a
#

Construct a quaternion from real and imaginary part.

Conversions

5 declarations
valuetoRotationMatrix :: C a => T a -> Array (Int, Int) a
#

Let c be a unit quaternion, then it holds similarity c (0+::x) == toRotationMatrix c * x

valuetoComplexMatrix :: C a => T a -> Array (Int, Int) (T a)
#

Map a quaternion to complex valued 2x2 matrix, such that quaternion addition and multiplication is mapped to matrix addition and multiplication. The determinant of the matrix equals the squared quaternion norm (normSqr). Since complex numbers can be turned into real (orthogonal) matrices, a quaternion could also be converted into a real matrix.

Operations

9 declarations
valueconjugate :: C a => T a -> T a
#

The conjugate of a quaternion.

valuescale :: C a => a -> T a -> T a
#

Scale a quaternion by a real number.

valuenormSqr :: C a => T a -> a
#

the same as NormedEuc.normSqr but with a simpler type class constraint

valuenormalize :: C a => T a -> T a
#

scale a quaternion into a unit quaternion

valuesimilarity :: C a => T a -> T a -> T a
#

similarity mapping as needed for rotating 3D vectors

It holds similarity (cos(a/2) +:: scaleImag (sin(a/2)) v) (0 +:: x) == (0 +:: y) where y results from rotating x around the axis v by the angle a.

valueslerp
  1. :: C a
  2. => a

    For 0 return vector v, for 1 return vector w

  3. -> (a, a, a)

    vector v, must be normalized

  4. -> (a, a, a)

    vector w, must be normalized

  5. -> (a, a, a)
#

Spherical Linear Interpolation

Can be generalized to any transcendent Hilbert space. In fact, we should also include the real part in the interpolation.