quaternion

Provides basic functions for quaternion arithmetics and 3D rotations. A quaternion is represented as a vec4, where x, y, and z are the imaginary components – the coefficients of i, j, and k, and w is the real component.

Addition and subtraction of quaternions, as well as multiplication and division with a scalar value can be performed with mathematical operators.

Get the absolute value of quaternion x

float quatAbs(vec4 x);

Multiply quaternions a and b; operation is not commutative, can be used to combine rotations

vec4 quatMult(vec4 a, vec4 b);

Divide quaternion a by b

vec4 quatDiv(vec4 a, vec4 b);

Exponentiate quaternion x

vec4 quatExp(vec4 x);

Compute the natural logarithm of quaternion x

vec4 quatLog(vec4 x);

Compute the y's power of quaternion x

vec4 quatPow(vec4 x, float y);

Construct a quaternion out of a complex number or a pair of complex numbers

vec4 quatFromComplex(vec2 x);
vec4 quatFromComplex(vec2 x, vec2 y);

Quaternion rotation

A quaternion that represents zero rotation is available as the constant QUAT_IDENTITY.

Construct the quaternion representing the 3D rotation of angle around axis

vec4 rotationQuat(vec3 axis, float angle);

Apply the rotation represented by quaternion q to the vector v

vec3 quatRotate(vec3 v, vec4 q);

Get the angle of the rotation represented by quaternion q

float quatRotationAngle(vec4 x);

Get the axis of the rotation represented by quaternion q

vec3 quatRotationAxis(vec4 x);