Scad_ml.Quaternion
Provides functions for the creation of and operations between quaternions. These can be used to create composable and interpolatable rotations to be applied to vectors (e.g. Vec3.t
) directly, and Scad.t
through MultMatrix.t
.
val id : t
The identity quaternion: (0., 0., 0., 1.)
make ax angle
Create a quaternion representing a rotation of angle
(in radians) around the vector ax
.
add_scalar t s
Add s
to the magnitude of t
, leaving the imaginary parts unchanged.
sub_scalar t s
Subtract s
from the magnitude of t
, leaving the imaginary parts unchanged.
scalar_sub_quat t s
Negate the imaginary parts of t
, and subtract the magnitude from s
to obtain the new magnitude.
val norm : t -> float
norm 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
.
val of_rotmatrix : RotMatrix.t -> t
val to_multmatrix : t -> MultMatrix.t
val to_string : t -> string
val get_x : t -> float
val get_y : t -> float
val get_z : t -> float
val get_w : t -> float
slerp a b step
Spherical linear interpotation. Adapted from pyquaternion.
rotate_vec3_about_pt t p v
Translates v
along the vector p
, rotating the resulting vector with the quaternion t
, and finally, moving back along the vector p
. Functionally, rotating about the point in space arrived at by the initial translation along the vector p
.