Processing math: 100%

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=s1s2v1v2+s1v2+s2v1+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)=P1P2

Handed is preserved if:

ϕ(P1)×ϕ(P2)=ϕ(P1×P2)

This is how you do the above with a quaternion:

P=qPq1

which is equivalent to:

Rq=[12y22z22xy2wz2xz+2wy2xy+2wz12x22z22yz2wx2xz2wy2yz+2wx12x22y2]

Spherical Linear Interpolation

q(t)=sinθ(1t)sinθq1+sinθtsinθq2 where 0t1