“Curiouser and curiouser!” cried Alice (she was so much surprised, that for the moment she quite forgot how to speak good English). ~ Alice’s Adventures in Wonderland

Definition

A quaternion is one of several mathematical ways to represent the orientation and rotation of an object in three dimensions. (Another way is to use Euler angle-based rotation matrices like I did on this post and this post (i.e., roll, pitch, and yaw), as well as the cover image of this tutorial (below).) Quaternions are often used instead of Euler angle rotation matrices because “compared to rotation matrices they are more compact, more numerically stable, and more efficient” (Source: Wikipedia). Note that a quaternion describes just the rotation of a coordinate frame (i.e., some object in 3D space) about an arbitrary axis, but it doesn’t tell you anything about that object’s position.1

Who

When I worked as a Guidance, Navigation and Control flight controller7 on the Space Shuttle program, I became intrigued with quaternions and how they were used in the Space Shuttle software. Not that everyone interested in mathematics should study quaternions, but they should be aware of their existence and where and how they are used.

“Quaternions came from Hamilton after his really good work had been done; and, though beautifully ingenious, have been an unmixed evil to those who have touched them in any way, including Clerk Maxwell.”

Lord Kelvin

What

Today, quaternions have applications in astronautics, robotics, navigation, computer visualization, animation and special effects in movies, and many other areas.4

Below is a graphical representation of products of quaternion units as 90° rotations in the planes of 4-dimensional space spanned by two of {1, i, j, k}. The left factor can be viewed as being rotated by the right factor to arrive at the product. Visually i ⋅ j = −(j ⋅ i). 9

In blue:
1 ⋅ i = i (1/i plane)
i ⋅ j = k (i/k plane)

In red:
1 ⋅ j = j (1/j plane)
j ⋅ i = −k (j/k plane)

Why

An attempt is made to show how quaternions can be used. It is noted that the quaternion caught on rather quickly when the software was faced with both a ‘core’ and ‘CPU’ scrub. It was at this point in the Shuttle program that all disciplines seriously considered using quaternions to perform the guidance, navigation, and control functions required to support mission objectives. A review of today’s software requirements shows that the quaternion found a home in nearly all principal functions in the Space Shuttle software.2

You don’t need to know everything about quaternions to program robots, but it’s good to know the basics of it and in general about rotation and different ways to represent rotation (Rotation Matrix, Euler, Quaternion, Axis Angle, etc.)3

So that’s quaternions, the magical rotation vectors. Every serious 3D engine supports them, and if you’ve played any sort of 3D game within the last 15 years, you were most likely controlling a quaternion camera. Whether it’s head-tracking on an Oculus Rift, or the attitude control of a spacecraft (a real one), these problems become much simpler when we give up our silly three dimensional notions and accept 3D rotation as the four dimensional curly beast that it is.5

Quaternions are very convenient way to describe 3D rotations. This is exploited by 3D computer graphics software (DirectX has quaternion class for example) and navigation software on spacecraft. The primary advantage of quaternions is low memory requirements. In 128-bit register you could fit single quaternion in 32-bit float format.6

Quaternions are used in pure mathematics, but also have practical uses in applied mathematics, particularly for calculations involving three-dimensional rotations, such as in three-dimensional computer graphics, computer vision, and crystallographic texture analysis. They can be used alongside other methods of rotation, such as Euler angles and rotation matrices, or as an alternative to them, depending on the application.10

How

Many of the References and Additional Reading links, and Videos will assist you with understanding and using quaternions.

As some professors say: “It is intuitively obvious to even the most casual observer.

References

2 Schletz, B. 1982. “Use Of Quaternions In Shuttle Guidance, Navigation, And Control”. Guidance And Control Conference, 753-760. https://ui.adsabs.harvard.edu/abs/1982guco.conf..753S/abstract.

3 “Quaternion Orientation”. 2015. ABB Robotics User Forums. https://forums.robotstudio.com/discussion/9435/quaternion-orientation.

4 “The Many Modern Uses Of Quaternions”. 2018. ThatsMaths. https://thatsmaths.com/2018/10/04/the-many-modern-uses-of-quaternions/.

5 Wittens, Steven. 2013. “Animate Your Way To Glory – Part II — acko.net”. acko.net. https://acko.net/blog/animate-your-way-to-glory-pt2/#quaternions.

6 Janiszewski, Witold. “How Are Quaternions Used?”. 2022. Quora. https://www.quora.com/How-are-quaternions-used.

7 One of the flight controllers in the Space Shuttle MCC is the Guidance, Navigation, and Control (GNC) officer. To understand the roles of the GNC officer, one must first understand the basics of the GNC system. Guidance equipment (gyroscopes and accelerometers) and software first compute the location of the vehicle and the orientation required to satisfy mission requirements. Navigation software then tracks the vehicle’s actual location and orientation, allowing the flight controllers to use hardware to transport the space shuttle to the required location and orientation. The job of the GNC officer is to ensure the hardware and software that perform these functions are working correctly. This control portion of the process consists of two modes: automatic and manual. In the automatic mode, the primary avionics software system allows the onboard computers to control the guidance and navigation of the space shuttle. In the manual mode, the crew uses data from the GNC displays and hand controls for guidance and navigation. The GNC officer ensures that the GNC system has the accuracy and capacity necessary to control the space shuttle in both modes and that it is being utilized correctly. The state vector of the spacecraft is the primary data used to determine the guidance function. The space shuttle’s state vector is an estimate of vehicle position in space and velocity at a given time. Beginning with a known initial position, velocity, and orientation (such as on the launch pad just prior to launch), all sensed accelerations from that point can be integrated and incorporated with a physics model to calculate the new position, velocity, and orientation. For accurate control of the spacecraft, the GNC officer must ensure that the state vector is accurate at all times during each mission phase (ascent, orbit operations, and reentry).8

8 “SPACE SHUTTLE GUIDANCE, NAVIGATION, AND CONTROL DATA”. 2022. nasa.gov. https://www.nasa.gov/pdf/570699main_AP_ED_Calc_ShuttleGNC_Nspire.pdf.

9 Maschen, CC BY-SA 3.0 https://creativecommons.org/licenses/by-sa/3.0, via Wikimedia Commons

10 “Quaternion – Wikipedia”. 2022. en.wikipedia.org. https://en.wikipedia.org/wiki/Quaternion.

Amit, Alon. “Can Quaternions Be Explained To A Nonmathematician?” 2019. Quora. https://www.quora.com/Can-quaternions-be-explained-to-a-nonmathematician.

In mathematics, quaternions are a centerpiece of non-commutative algebra, number theory, geometry and many, many other things. The “next” algebra of their ilk, the Cayley numbers or Octonions, already gives up on another property, associativity, and this makes them far less useful. Quaternions may not be as useful as the ubiquitous complex numbers, but they are awesome.

Barendse, Peter. 2011. “Quaternion Properties And Interactive Rotations With Wolfram | Alpha—Wolfram | Alpha Blog”. blog.wolframalpha.com. https://blog.wolframalpha.com/2011/08/25/quaternion-properties-and-interactive-rotations-with-wolframalpha/.

“Quaternion — From Wolfram Mathworld”. 2022. mathworld.wolfram.com. https://mathworld.wolfram.com/Quaternion.html.

“Maths – Quaternions – Martin Baker”. 2022. euclideanspace.com. https://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/.

“Maths – Quaternion Arithmetic – Martin Baker”. 2022. euclideanspace.com. https://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/arithmetic/index.htm.

“Maths – Conversion Matrix To Quaternion – Martin Baker”. 2022. euclideanspace.com. https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/.

For a pure rotation, two conditions must be met. (1) the matrix is orthogonal and (2) the matrix is special orthogonal which gives additional condition: det(matrix)= +1

“Maths – Conversion Quaternion To Matrix – Martin Baker”. 2022. euclideanspace.com. https://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm.

“Quaternions: A Practical Guide”. 2022. anyleaf.org. https://www.anyleaf.org/blog/quaternions:-a-practical-guide.

This article demonstrates how to use quaternions for practical applications. In it, we build intuition about how to use them as building blocks to solve engineering and geometry problems. Applications include computer graphics, attitude systems for air and spacecraft, biomechanics, and structural chemistry models. You may have read that quaternions have advantages over Euler angles to represent orientations, including preventing gimbal lock, and advantages over rotation matrices, such as more efficient computation, and compact form. This is true. You may have also read that they’re complicated, difficult to use, or counter-intuitive. This isn’t!

This article describes several operations that use quaternions and vectors. It doesn’t discuss why they work. There are many articles and videos available where you can learn about this, including perspectives from numerical algorithms, visualizations (including stereographic projections of 4d space!), and symbolic operations. Examples are included in the References section at the bottom. This article, in contrast, will make you effective at using quaternions as an engineering tool.

Why are we taking this approach instead of building deeper knowledge? We’re building intuition so you’ll be able to learn a few general tools, then be able to apply them to a broad range of applications. You should be able to recognize when they’re appropriate, how to combine them, and how to apply them to physical systems and models. A deeper approach might describe why the arithmetic we define them with works. A shallower approach might provide complete orientation and rotation systems, like in a computer graphics library. Hopefully we’ve hit a sweet spot.

“Quaternions And Spatial Rotation – Wikipedia”. 2022. en.wikipedia.org. https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation.

Sanderson, Grant. “Visualizing Quaternions, An Explorable Video Series”. 2022. eater.net. https://eater.net/quaternions.

One of the main practical uses of quaternions is in how they describe 3d-rotation. These first two modules will help you build an intuition for which quaternions correspond to which 3d rotations, although how exactly this works will, for the moment, remain a black box. Analogous to opening a car hood for the first time, all of the parts will be exposed to you, especially as you poke at it more, but understanding how it all fits together will come in due time. Here we are just looking at the “what”, before the “how” and the “why”.

“Understanding Quaternions”. 2012. 3D Game Engine Programming. https://www.3dgep.com/understanding-quaternions/.

In this article I will attempt to explain the concept of Quaternions in an easy to understand way. I will explain how you might visualize a Quaternion as well as explain the different operations that can be applied to quaternions. I will also compare applications of matrices, euler angles, and quaternions and try to explain when you would want to use quaternions instead of Euler angles or matrices and when you would not.