If you've worked on computer graphics, computer vision, robotics or something related to quaternions. It's likely that you have heard of quaternions. There are already a plethora amount of videos, and online resources, explaining quaternions. However many of these resources either focus only on the application, skipping over a lot of the math, or explain using algebra. This doesn't build an intuitive relation behind quaternions and 3D rotation. This blog is my attempt to explain quaternions in a mathematical way, building from the foundation and giving a geometric interpretation of quaternions. We will start from real numbers, work our way into 2 dimensions, explain the famous
When we think of numbers we usually think of numbers, numbers such as 1, 2, 3.14159265 seem to come to mind. We are familiar with these numbers as they are used all the time. These numbers are called real numbers(kind of a terrible name but whatever). When it comes to visualizing the real numbers, a common way of doing so is with a number line. The number line starts from 0 and as the values get bigger as you go right, and as it gets smaller you go left.
Every point on the line represents a single real number. This provides a way of associating geometry to the reals.
Numbers in it of itself are not interesting, instead operations and relationships between these numbers make them useful.
Addition is one of these operations. To think about addition in the number line we'll start by thinking about numbers in a different manner. As said earlier a number is a point in the number, and therefore we can draw an arrow starting from 0 and extend it to this point. This arrow will represent the number, the length will represent the value, and the direction will decide the sign. Now addition then can be thought up as connecting these to arrows.
Subtraction is the same as adding up a negative number, and since negative numbers are just arrows with the same length pointing backwards, subtraction is already defined.
We can also visualize multiplication in plane.
We have worked with 1 number, now let’s see how we can think of 2 numbers(I will write a pair of numbers as
These pairs of numbers are referred to as vectors, more specifically 2 dimensional vectors, I will be calling them as vectors for the rest of this blog convenience sake.
These vectors similar to real numbers can be added up. The definition of this addition is this
When we do this we can see that each of the horizontal components are added up, and each of the vertical components are also added up. Therefore it satisfies our definition of vector addition.
Now there is no way to multiply 2 vector, or at least no one universial way. There is a Freya Holmér Video about this topic. However, we can multiply a vector with a real number. The defintion is
I would like you to imagine(pun unintended) an equation.
However, let us make up a new number
-
$i$ is not real(as in numbers) $i^2={-1}$
Now that we define imaginary numbers and real numbers. Let's add them together. Let's say we have a number
when adding up 2 complex numbers
Multiplication of
As we can see the complex numbers mirror 2 dimensional vectors, addition, and multiplication with real numbers are the same. Therefore complex numbers can be mapped to a plane. Let's call this plane the complex plane.
A fact that differentiates complex numbers from vectors is multiplication. Vectors can't be multiplied by themselves, however there is one universal way to multiply 2 complex numbers. Complex number multiplication satisfies the properties of real number multiplication. That being
- associativity
$a{\cdot}(b{\cdot}c)=(a{\cdot}b){\cdot}c=a{\cdot}b{\cdot}c$ - distributivity
$a{\cdot}(b+c)=a{\cdot}b+a{\cdot}c$ - commutativity
$a{\cdot}b = b{\cdot}a$
With these properties we can define complex number multiplications.
There is a sense in which complex numbers can encode rotating in 2d spaces. there is a famous equation showing this
when a {i}
s and $1
s, This extends to all the complex numbers.
Now the important part, let’s think about the
When a circle, whose center is the origin. Then think about a moving point in a circle. We will find that the tangent to the circle is to the position from the origin. Since the tangent is the direction in which the point moves, you can induce that the function
Now we currently don’t know the radius of the circle in which
Now let us observe the speed in which this point moves. The speed in which the point moves is equal to the length of
In conclusion the
If we look back at the definition of imaginary numbers. We used the equation
Using these properties we can derive other equalities, such as
-
$ij = k$ -
$jk = i$ -
$ki = j$ -
$ji = -k$ -
$kj = -i$ -
$ik = -j$
One thing to note unlike complex numbers quaternions will not commute. commutativity only applies with imaginary and real numbers. When multiplying 2 different imaginary units, we can see that when the numbers are swapped the result will be negated. This property is called anti-commutivity.
Since quaternions are made up of 4 numbers we would have to use a 4d space to represent the number. Unfortunately we live in 3d space(spatial). Therefore it’s hard for us to wrap our heads around 4d space. Therefore instead of using 4d space, we will use 3d space, with each axis representing an imaginary part. I will call this the imaginary space for convenience. When the real part of the quaternions is needed we will just use the complex plane.
In the imaginary space, when multiplying
We can see the parallel with the complex numbers. using this fact Let's multiply
With this we have successfully defined a rotation around the
Except… NO! watch what happens when
You can see that
One way to remedy this we can multiply
Just like we did with
We have used the notation
Through this blog, We've explored ways to represent numbers, real and imaginary in a geometric space. We've also looked through ways to expand