What is a quaternion and what is it used for

310 views

I’ve seen quaternions in an essay type video about imaginary numbers and it comes up quite a bit in game dev? What does it even mean.

In: 2

5 Answers

Anonymous 0 Comments

Quaternions are exactly like your normal complex numbers, but with four components instead of two. They obey all the same rules.

I’ve heard too they’re used in generating graphics, but don’t know in what exact capacity.

Anonymous 0 Comments

Complex numbers are often used to represent coordinates on a two-dimensional plane. One of the advantages of doing so is that you can rotate and scale a set of coordinates via multiplication.

Let’s say we have the cartesian coordinates (3,4). This corresponds to (3 + 4i). If we want to rotate this 90 degrees to the left, we’d simply multiply by (0 + 1i) – the coordinates of the position on the unit circle 90 degrees to the left of 0 degrees (along the x-axis). The result of our multiplication would be (4 + 3i) – a 90 degree rotation to the left.

Extending this model to 3 dimensions is what quaternions do. You can use them in the same way to indicate position and perform rotations in 3 dimensional space.

Anonymous 0 Comments

A quaternion is a number of the form a+bi+cj+dk, where a,b,c,d are reals (or any other type of number) and i,j,k are formal(!) imaginary units. This is a 4-dimensional thing, as there are 4 parameters to pick. They are added in the “intuitive” way and multiplication comes from i² = j² = k² = -1, i·j = k = -j·i, j·k = i = -k·j, k·i = j = -i·k. Maybe unintuitively for the layman, this is not _commutative_ as i·j and j·i give different results. However:

Multiplication by quaternions with a²+b²+c²+d² = 1 can be interpreted as rotations of the entire 4-dimensional space, and setting a=0 as well then as rotations in 3 dimensions; i.e. something arising in computer graphics very often. This also explains why commutativity is not really an option then: two rotations around skew axes do not commute, as one can easily check by consecutively rotating either a ball (or even better a Rubik’s cube) by 90° along two orthogonal axes.

Anonymous 0 Comments

Quaternions are mathematical things that represent rotations in 3D. They can be used everywhere, where you need to rotate stuff, or keep track of rotations. Each quaternion represents a rotation. The inverse is not true, as there are many quaternions, that give the same rotation: `2q`, `3q`, `1.5q`, `-5q`, etc. are the same rotation as just `q`.

Quaternions are made of 4 basic components:

* “Do nothing”. Does not rotate anything. Represented by number `1`.
* 180 deg around X (in YZ plane). Represented by `i`.
* 180 deg around Y (in XZ plane). Represented by `j`.
* 180 deg around Z (in XY plane). Represented by `k`.

You can then add that components. When you add two components, you get an “in between” rotation. For ex., `i + j` is a 180 deg rotation “in between” XZ and YZ. The `1 + i` is “in between” 180 deg around X and do nothing – so it is 90 deg around X. `2 + i` is similar, but “do nothing” is twice as strong, so it is around 60-ish deg around X. By adding some portions of the bases you can get any rotation.

You can also multiply quaternions: `A*B` is a rotation, which you get by applying first `B`, and then `A`. Note, that `A*B` is not the same as `B*A`, because in 3D the order of rotations matter.

Anonymous 0 Comments

Quaternions are a way to represent a rotation. All the imaginary number stuff is true, but you don’t really need to understand that to know what it’s used for.

So In video games, they get used to keep track of what direction things are facing. So let’s say you spawn in a gun. It’ll come in a default orientation. Now let’s say you want to put the gun on a gun rack. A quaternion is what’s used to keep track of how the gun has rotated from that initial position.

This technically isn’t a quaternion, but you can think about it like this. Imagine a line coming out of an object (let’s use that video game gun from earlier) at some angle. now rotate the gun around that line by 20 degrees as an example. For any orientation that you want, you can find that axis and angle like this. When people talk about the imaginary and real component for a quarternion, the imaginary part correlates to that axis and the real part corresponds to the rotation. Although technically this is a different thing.

Quaternions can be pretty tricky to understand, but they have some really useful properties so they get used a lot.