package OCADml

  1. Overview
  2. Docs

Module OCADml.QuaternionSource

Provides 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.

Sourcetype t
Sourceval id : t

The identity quaternion: { x = 0.; y = 0.; z = 0.; w = 1. }

Sourceval make : V3.t -> float -> t

make ax angle

Create a quaternion representing a rotation of angle (in radians) around the vector ax.

Basic Arithmetic

Sourceval add : t -> t -> t

add a b

Hadamard (element-wise) addition of quaternions a and b.

Sourceval sub : t -> t -> t

sub a b

Hadamard (element-wise) subtraction of quaternion b from a.

Sourceval mul : t -> t -> t

mul a b

Quaternion multiplication of a and b.

Sourceval neg : t -> t

neg t

Negation of all elements of t.

Sourceval sadd : t -> float -> t

sadd t s

Add s to the magnitude of t, leaving the imaginary parts unchanged.

Sourceval ssub : t -> float -> t

ssub t s

Subtract s from the magnitude of t, leaving the imaginary parts unchanged.

Sourceval ssub_neg : t -> float -> t

ssub_neg t s

Negate the imaginary parts of t, and subtract the magnitude from s to obtain the new magnitude.

Sourceval smul : t -> float -> t

smul t s

Element-wise multiplication of t by s.

Sourceval sdiv : t -> float -> t

div_scalar t s

Element-wise division of t by s.

Vector Math

Sourceval norm : t -> float

norm t

Calculate the vector norm (a.k.a. magnitude) of t.

Sourceval normalize : t -> t

normalize t

Normalize t to a quaternion for which the magnitude is equal to 1. e.g. norm (normalize t) = 1.

Sourceval dot : t -> t -> float

dot a b

Vector dot product of a and b.

Sourceval conj : t -> t

conj t

Take the conjugate of the quaternion t, negating the imaginary parts (x, y, and z) of t, leaving the magnitude unchanged.

Sourceval distance : t -> t -> float

distance a b

Calculate the magnitude of the difference (Hadamard subtraction) between a and b.

Conversions

Sourceval of_euler : V3.t -> t

of_euler v

Create a quaternion equivalent to the Euler angle rotations represented by v.

Sourceval to_euler : t -> V3.t

to_euler t

Convert the quaternion t to equivalent Euler angles.

Sourceval to_affine : ?trans:V3.t -> t -> Affine3.t

to_affine ?trans t

Convert quaternion t into an Affine3.t, optionally providing a translation vector trans to tack on.

Vector Transformations

Sourceval align : V3.t -> V3.t -> t

align a b

Calculate a quaternion that would bring a into alignment with b.

Sourceval transform : ?about:V3.t -> t -> V3.t -> V3.t

transform ?about t v

Rotate v with the quaternion t around the origin (or the point about if provided).

Utilities

Sourceval slerp : t -> t -> float -> t

slerp a b step

Spherical linear interpotation. Adapted from pyquaternion.

Sourceval to_string : t -> string