Unit content
Three-dimensional rotations with unit quaternions
A rotation by angle $\theta$ about a unit axis
$$\mathbf n=(n_x,n_y,n_z)$$
can be represented by the unit quaternion
$$q=\cos\frac\theta2 +\sin\frac\theta2(n_x\mathbf i+n_y\mathbf j+n_z\mathbf k).$$
Rotating a vector
Represent a vector $\mathbf v=(v_x,v_y,v_z)$ as the pure quaternion
$$p=v_x\mathbf i+v_y\mathbf j+v_z\mathbf k.$$
The rotated vector is represented by
$$p'=qpq^{-1}.$$
Composition
Successive rotations are composed by quaternion multiplication. Because multiplication is noncommutative, order matters just as it does for rotation matrices.
Double cover
The quaternions $q$ and $-q$ represent the same physical rotation. Unit quaternions therefore provide a double cover of the three-dimensional rotation group.
Why quaternions are useful
A unit quaternion uses four components with one normalization constraint, avoids the gimbal-lock singularity of Euler-angle coordinates and supports stable composition without the redundant nine components of a rotation matrix.