OCADml.QuaternionProvides functions for the creation of and operations between quaternions. These can be used to create composable and interpolatable rotations to be applied to 3d vectors (V3.t), and shapes.
val id : tThe identity quaternion: { x = 0.; y = 0.; z = 0.; w = 1. }
make ax angle
Create a quaternion representing a rotation of angle (in radians) around the vector ax.
sadd t s
Add s to the magnitude of t, leaving the imaginary parts unchanged.
ssub t s
Subtract s from the magnitude of t, leaving the imaginary parts unchanged.
ssub_neg t s
Negate the imaginary parts of t, and subtract the magnitude from s to obtain the new magnitude.
val norm : t -> floatnorm t
Calculate the vector norm (a.k.a. magnitude) of t.
normalize t
Normalize t to a quaternion for which the magnitude is equal to 1. e.g. norm (normalize t) = 1.
conj t
Take the conjugate of the quaternion t, negating the imaginary parts (x, y, and z) of t, leaving the magnitude unchanged.
distance a b
Calculate the magnitude of the difference (Hadamard subtraction) between a and b.
Conversions
of_euler v
Create a quaternion equivalent to the Euler angle rotations represented by v.
to_affine ?trans t
Convert quaternion t into an Affine3.t, optionally providing a translation vector trans to tack on.
align a b
Calculate a quaternion that would bring a into alignment with b.
transform ?about t v
Rotate v with the quaternion t around the origin (or the point about if provided).
slerp a b step
Spherical linear interpotation. Adapted from pyquaternion.
val to_string : t -> string