In this article, we describe what Quaternions are, how to use them, and their applications in Computer Graphics.
Defining a Quaternion
Mathematical Definition
Recall a complex number . All complex numbers can be represented as
Where , and , the imaginary number.
Quaternions were invented as an extension of these imaginary numbers . Mathematically, a quaternion is defined as
Note that is a vector, and can be used with normal vector operations!
Where are real components of our quaternion, and are imaginary units such that
Note that by this definition, multiplication with these units is not commutative.
Components of each of these imaginary units are closely related to the axes of rotation!
One convenient way of understanding these imaginary unit conversions is by imagining the following cycle
graph LR
i -.-> j -.-> k -.-> i;
Where for the product of any two units, its result is the third unit, and its sign is determined by if we βfollow the arrowsβ (positive) or not (negative) on this cycle.
Example: Product of Imaginary Units
Using our cycle above, we see that the product of is j, and as the path from to goes against the arrow, our result is negative. Thus,
Quaternion Operations
Suppose we have two quaternions and .
Then, the following operations are defined.
These operations can easily be defined by considering their normal meanings, and applying them to the quaternions as so. See below for an example derivation.
Example: Quaternion Product
We calculate the product of two quaternions below, by considering their definition, taking the product, and distributing.
From these definitions, we can define a variety of other rules! They are given below.
Unit Quaternions
Definition
A quaternion is a unit quaternion when .
Now suppose we have any 3-dimensional unit vector . Using this, we can write a unit quaternion as
And observe that
This definition of unit quaternions is, interestingly enough, extremely well-suited for rotations and orientations!
This is described in the next section.
Quaternion Transforms
Consider a quaternion , where represents a 3D position in space, and consider a unit quaternion .
We can prove that the quaternion product
Rotates (and thus our point ) around the axis by the angle ! Thus, this product is equal to us applying a rotation transform onto our point !
Note that because is a unit quaternion, .
By this, and our definition of quaternion product, we see that if we wanted to perform multiple transforms, we have
Where . In other words, the product of our unit quaternions gave us a new quaternion representing the transform of applying both!
This provides us a simple operation that gives us a very convenient way to apply rotations on points in 3D space!
Matrix Conversions
Itβs often the case that several different transforms need to be applied to a point, and most of these transforms are given in a matrix form.
It can be shown that for our unit quaternion , we can convert it to matrix form
Note that given this, we donβt need to compute any trigonometric functions to get our transform! This makes our matrix conversion process very efficient in practice.