A rotation as x, y, z, w, with the vector part in xyz and the scalar part last. A default Quaternion.{} is the identity (w is 1). A unit quaternion rotates; the procedures that expect one (rotate, set_rotation) do not normalize it, so call normalize_or_identity after arithmetic that drifts.
a * b is the Hamilton product and applies b's rotation first. Also supports +, -, unary -, * float and ==, which act on the four components.
q: Quaternion;
set_from_axis_and_angle(*q, xyz(0, 0, 1), PI / 2); // quarter turn about z
v := rotate(xyz(1, 0, 0), q);
assert(abs(v.x) < 0.0001 && abs(v.y - 1) < 0.0001);
assert(Quaternion.{} == Quaternion.{ 0, 0, 0, 1 });Fields
- x: float
- y: float
- z: float
- w: := 1.0
- xyz: Vector3
- component: [4] float