# Quaternion Calculator

Created by Maciej Kowalski, PhD candidate
Reviewed by Anna Szczepanek, PhD and Steven Wooding
Last updated: Jan 18, 2024

Welcome to Omni's quaternion calculator, where we'll deal with this mysterious extension of complex numbers: the quaternions. In short, we represent them using four real values, each corresponding to one of the basic unity quaternions: $1$, $\text i$, $\text j$, and $\text k$. To some, they may seem like an artificial creation to make math even more tricky than it already is. To others, they are a useful tool in 3D geometry: mainly to study quaternion rotation. Unfortunately, this doesn't kill the "tricky" part, and, e.g., quaternion multiplication is not a straightforward operation.

But let's not get ahead of ourselves! We begin with where every math topic begins: with an introduction. In our case, it's the quaternion definition.

## The quaternion definition

Quaternions are an extension of complex numbers. They were first introduced by , who used them to describe several properties of the three-dimensional space (for more, see the dedicated section).

However, nowadays, most often, we introduce them from the algebraic point of view. Let's take a look at the formal quaternion definition.

💡 Quaternions are expressions of the form $q = a + b \,\text i + c \,\text j + d \, \text k$, where $a$, $b$, $c$, and $d$ are arbitrary real numbers and $\text i$, $\text j$, and $\text k$ are base elements sometimes called the basic unity quaternions.

By the above quaternion definition, we see that the space is spanned by four base elements: $1$, $\text i$, $\text j$, and $\text k$. The three letters don't stand for any particular value: they simply denote independent base vectors. Nevertheless, if $\text i$ seems familiar, it well should! In fact, if the coefficients of $\text j$ and $\text k$ (i.e., $c$ and $d$ in the above quaternion definition) are both zero, then we obtain the (well-known) complex numbers! As such, we indeed obtain their extension.

More or less, Hamilton's idea was to have one expression whose individual parts (i.e., the base elements' coefficients) describe the distinct directions in a three-dimensional space. From there, he only needed to introduce operations between these new thingies. On the one hand, we'd like them to satisfy some properties and form a nice algebraic structure. On the other, the operations should be usable and have real-life explanations. After all, quaternions originated from geometry — a very real-life area of mathematics.

Now that we know what a quaternion is, we can go further. The subsequent sections describe the basic rules governing these numbers. Note how Omni's quaternion calculator lets you find all values and objects we mention. For more information on how to use the tool, see the last section.

This one's easy. Recall from the above section that quaternions are spanned by four base elements: $1$, $\text i$, $\text j$, and $\text k$. As such, if we want to add or subtract two such expressions, we do it the same way as in any vector space: move from one base element to the other and add or subtract the respective coefficients of the two quaternions. And since these coefficients are simply real numbers, it boils down to the very basics of mathematics which we learned in primary school.

$\footnotesize \begin{split} & (a + b\,\text i + c\,\text j + d\,\text i) + (e + f\,\text i + g\,\text j + h\,\text k) = \\ &(a + e) + (b + f)\,\text i + (c + g)\,\text j + (d + h)\,\text k \\[1.5em] & (a + b\,\text i + c\,\text j + d\,\text i) - (e + f\,\text i + g\,\text j + h\,\text k) = \\ &(a - e) + (b - f)\,\text i + (c - g)\,\text j + (d - h)\,\text k \end{split}$

Plain sailing, wouldn't you say? Such addition satisfies all the reasonable properties: it's associative, commutative, and every quaternion $q$ has its opposite $-q$ such that $q + (-q) = (-q) + q = 0$.

Unfortunately, the story is a bit more difficult for multiplication and even more so for division.

## Quaternion multiplication and division

In real and complex numbers, we got used to the distributive property of multiplication over addition, so we'd like to have a similar law here. After all, quaternions are sums of four elements: the real part and the $\text i$, $\text j$, and $\text k$ parts. In other words, we want to have:

$\footnotesize \begin{split} &(a + b\,\text i + c\,\text j + d\,\text k) \cdot (e + f\,\text i + g\,\text j + h\,\text k) \\ &= a \cdot (e + f\,\text i + g\,\text j + h\,\text k) \\ &+ b\,\text i \cdot (e + f\,\text i + g\,\text j + h\,\text k) \\ &+ c\,\text j \cdot (e + f\,\text i + g\,\text j + h\,\text k) \\ &+ d\,\text k \cdot (e + f\,\text i + g\,\text j + h\,\text k) \\ \end{split}$

And indeed, it is so. However, we now have to explain how quaternity multiplication works on the individual parts, i.e., on the basic unity quaternions. The following table contains the answer:

·1

·i

·j

·k

1

i

j

k

i

-1