Jump to content

Guide to Game Development/Theory/Mathematics/Quaternions

50% developed
From Wikibooks, open books for an open world

About

[edit | edit source]

Quaternions are used for rotating a geometry and points with along multiple axes of rotation. They exist in four dimensions, and so that have four parts: w, x, y and z. As x, y and z are linked and similar to each other, people sometimes use another letter to represent all three, v is common for this. To represent them you should store them in a 4-dimensional vector like so: . Quaternions are used as an alternative to Euler angles.

Benefits of Quaternions[1]:

  • No gimbal locking
  • Interpolation is smooth and direct
  • Simple to do calculations with

Basic creation of a quaternion

[edit | edit source]

So if you chose some unit length 3D-vector that you could like to rotate the geometry around () and an amount of degrees that you want to rotate the geometry () then create a rotation quaternion ().

There are generally two forms for representing quaternion, short and long. In the short notation it shows it in terms of w and v (a combination of x, y and z).

This can be represented in the long notation using w, x, y and z:

Where [2]:

If a quaternion is not rotated, then it will have the value[3]:

[edit | edit source]

The 4 components (w, x, y and z) can be broken down into one real number and three imaginary numbers:

where , and are imaginary numbers such that . From that, you can create the following statements:


Inverse Quaternions

[edit | edit source]

To invert a quaternion, simply multiply the x, y and z components by -1.

Multiplying quaternions

[edit | edit source]

When multiplying two quaternions together, order matters ().

The multiple is defined by[4]:


Clipboard

To do:
Add and understand the statement: (rotationQuaternion*pointQuaternion)*conjugateQuaternion

look into:

[Seen here]


Spherical Linear Interpolation (SLERP)

[edit | edit source]

This is how you Interpolate gradually between two quaternions, like getting a mid-point (or some other point) between two quaternions.

Superscript notation for Quaternions

[edit | edit source]

Before you can do SLERP, you need to understand the superscript notation for a quaternion.

If you have a quaternion a and you use the superscript notation to raise it to the power t, this means that it will scale the angles inside the quaternion by superscript t. As this only scales all of the angles, this means that the magnitude () of the Quaternion is still 1.

Superscript notation in short notation

[edit | edit source]

Superscript notation in long notation

[edit | edit source]

The SLERP Equation

[edit | edit source]

If your first Quaternion was q and the second quaternion was r and you wanted to find a point in-between (p) which is t percent of the way from q to r, where 0 ≤ t ≤ 1.

The final equation is defined as[5]:

See also

[edit | edit source]
[edit | edit source]

Youtube:

Wikipedia pages:

Wikibooks:

References

[edit | edit source]