MarkCC has a post about quaternions and the fact that they can be used for rotation, so I thought I’d chime in with exactly how they represent rotations.
A 2D rotation by an angle θ can be represented by the complex number on the unit circle
cos θ + i sin θ
Then multiplying complex numbers is the same as multiplying rotations.
A 3D rotation by an angle θ about a line defined by a unit vector (b,c,d) can be represented by the quaternion on the unit hypersphere
cos θ/2 + sin θ/2(bi + cj + dk)
Then multiplying quaternions is the same as multiplying rotations.
But why is it θ/2 instead of θ?
Well, in 3D, in some sense you have to rotate through 720° to really get back where you started from. There’s a nice animation of the Dirac Belt Trick that shows how you can remove a 720° twist from a belt without moving the ends. However, you can’t remove a 360° twist. The quaternions q and -q are different but both represent the same 3D rotation.