package scad_ml
Module Scad_ml.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 vectors (e.g. Vec3.t) directly, and Scad.t through MultMatrix.t.
make ax angle
Create a quaternion representing a rotation of angle (in radians) around the vector ax.
Basic Arithmetic
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.
Vector Math
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.
Matrix Conversions
Utilities
slerp a b step
Spherical linear interpotation. Adapted from pyquaternion.
Vector Transformations
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.