Quick guide to Quaternions

Introduction

Quaternions are an alternative way of specifying rotations. They do not store redundant information like Euler Angles do, and they require less multiplication operations to combine rotations than rotation matrices. It is also extremely easy to interpolate between two quaternions. Information on quaternions is widely available on the net in different shapes and forms. During my assignment I spent a lot of time researching quaternions and found useful bits and pieces scattered across the web. This guide is an attempt to compile all the material I use now for future reference. Maybe someone will find this useful aswell? Who knows? :)

Conventions

  • All angles are in radians.
  • All source code is MATLAB. Remember in MATLAB indices start at 1, not 0.

Definition

Rotation about vector in quaternion form is expressed as:

It can be thought of as a complex number with 3 complex parts:

Multiplying Quaternions

Quaternions are cool because they can represent any rotation in a compact way. Rotations can also be combined using quaternions by multiplying them. Here is how you multiply quaternions. Suppose we call our 4 coefficients .

Then multiplication is as follows:

Combining quaternions

Successive rotations can then be expressed as follows. Say, we have 3 rotations expressed as quaternions: , , . We can then combine these into a single rotation (rotate by , then by and finally by ) by doing:

More quaternion operations

Some more common quaternion operations.

Conjugate

Magnitude

Normalisation

Transforming quaternions into other representations


Quaternion to 3x3 Rotation Matrix


Quaternion to Axis Angle



Quaternion to Euler Angles

This transformation depends on your multiplication order. Have a look at my other post for a general implementation. It's based on this paper.


Spherical Interpolation - SLERP


Approximating SLERP with LERP (Linear Interpolation)

Have a look at "Understanding SLERP and approximating it". It's a very good article, it explains advantages and disadvantages of this method and also shows some ways in which you can improve the method.


Useful links and additional reading

Wikipedia - Quaternions and spatial rotation
EucledianSpace - Quaternions
Understanding SLERP and approximating it

For those of you who have access to eJournals, here is an interesting paper:
Fast Quaternion SLERP