#### Quaternions and Rotations

First we elaborate how quaternions may be used to describe an orientation. With Wolfram we view a quaternion as a pair (r, v) where r is a real and v is a vector from the 3D Euclidean space whose rotations we examine. For reals a, b, c & d, (a, b, c, d) = (a, (b, c, d)) where the quartet depicts the quaternion with 4 reals, (b, c, d) depicts a 3D vector with 3 components and the duo depicts a quaternion as just introduced here.

We define here quaternions in terms of Gibbs’ vector notions even though quaternions came first historically:
Quaternion addition: (r, u) + (s, v) = (r+s, u+v)
Quaternion multiplication: (r, u)(s, v) = (rs − u⋅v, rv + su + u×v)
This is a retro definition in terms of Gibbs’ notions which had not been invented. Hamilton’s definitions amount to:
Quaternion addition: (a, b, c, d) + (e, f, g, h) = (a+e, b+f, c+g, d+h)
Quaternion multiplication: (a, b, c, d)(e, f, g, h) = (ae − (bf + cg + dh), af + be + ch − dg, ag + ce + df − bh, ah + de + bg − cf)

A 3D rotation, in the sense of an operator, thru angle θ about a fixed axis containing the unit vector n, may be represented by quaternion ρ = (cos(θ/2), n sin(θ/2)). −ρ represents the same orientation. Note that |ρ| = 1. Composition of rotations now corresponds to multiplication of the related quaternions.

We compute the rotation of a vector p by ρ by taking the vector part of ρ(0, p)ρ−1. For this formula ρ and aρ perform the same rotation for any nonzero real a. Here is some Scheme code that does this.

Conventionally using quaternions to model rotations uses only quaternions with unit magnitude and addition of quaternions plays no role. The multiplicative group of the unit quaternions is the complete rotation model.

Note that the 2nd definition for q2m takes a quaternion which is bq where b is a real and q is a unit quaternion, and returns a linear transformation that preserves angles but where lengths are multiplied by b2, a linear similarity transformation.

Hamilton knew all this but he didn’t use the Gibbs notation which had not been invented.