Quaternions
Quaternions can be used to represent rotations.
- Require less memory
- Concatenating quaternions require less arithmetic
- More easily interpolated
They are represented as a 4D vector.
The 4th component is a scalar value, taking the space for w.
q=s+→v=⟨w,x,y,z⟩
Alternative representation (Grimoire uses this notation). This notation makes it look like a vector in homogenous coordinates.
q=⟨x,y,z,w⟩
Creating a quaternion from an angle and axis of rotation
q=cosθ2+→Asinθ2
where θ is an angle about the unit axis A.
Multiplying Quaternions
Multiplication is NOT commutative, so order really matters.
q1q2=s1s2−→v1⋅→v2+s1→v2+s2→v1+→v1×→v2
Rotating Vectors with Quaternions
Suppose some function ϕ represents a rotation meant to be applied to some point →P. To be a rotation it must:
- Preserve lengths
- Preserve angles
- Preserve handedness
Length is preserved if:
‖ϕ(→P)‖=‖→P‖
Angle is preserved if:
ϕ(→P1)⋅ϕ(→P2)=→P1⋅→P2
Handed is preserved if:
ϕ(→P1)×ϕ(→P2)=ϕ(→P1×→P2)
This is how you do the above with a quaternion:
→P′=qPq−1
which is equivalent to:
Rq=[1−2y2−2z22xy−2wz2xz+2wy2xy+2wz1−2x2−2z22yz−2wx2xz−2wy2yz+2wx1−2x2−2y2]
Spherical Linear Interpolation
q(t)=sinθ(1−t)sinθq1+sinθtsinθq2 where 0≤t≤1