42
$\begingroup$

I've recently started reading about Quaternions, and I keep reading that for example they're used in computer graphics and mechanics calculations to calculate movement and rotation, but without real explanations of the benefits of using them.

I'm wondering what exactly can be done with Quaternions that can't be done as easily (or easier) using more tradition approaches, such as with Vectors?

$\endgroup$
2
  • 5
    $\begingroup$ In a word: Rotating. $\endgroup$
    – bobobobo
    Commented Oct 9, 2011 at 21:47
  • 1
    $\begingroup$ Game development. (though I simply use matrixes to rotate.) $\endgroup$
    – Calmarius
    Commented Sep 22, 2013 at 17:51

8 Answers 8

29
$\begingroup$

I believe they are used in quantum physics as well, because rotation with quaternions models Spinors extremely well (due to the lovely property that you need to rotate a point in quaternionic space around 2 full revolutions to get back to your 'original', which is exactly what happens with spin-1/2 particles).

They are also, as you said, used in computer graphics a lot for several reasons:

  1. they are much more space efficient to store than rotation matrices (4 floats rather than 16)
  2. They are much easier to interpolate than euler angle rotations (spherical interpolation or normalised liner interpolation)
  3. They avoid gimbal lock
  4. It's much cooler to say that your rotation is described as 'a great circle on the surface of a unit 4 dimensional hypersphere' :)

I think there are other uses, but a lot of them have been superseded by more general Vectors.

$\endgroup$
6
  • 6
    $\begingroup$ A rotation matrix can be represented in 9 floats rather than 16. Also, in regards to computer graphics, smooth interpolation between two quaternions is easy compared to rotation matrices. $\endgroup$ Commented Jul 20, 2010 at 20:08
  • $\begingroup$ true, only 9 are needed for a rotation matrix. And point two makes the point about interpolation :) $\endgroup$
    – workmad3
    Commented Jul 20, 2010 at 22:09
  • $\begingroup$ The relationship between spinors and quaternions could be made stronger. The quaternions are the dual of spinors within a 3D geometric algebra. The quaternions are made up of linear combinations of the oriented planes and a scalar, while the spinors are linear combinations of a vector and the 3d oriented volume or pseudoscalar. Their union makes up the entire 3D GA. The 720 degree is tangential. It comes from four ways to make the angle between two vectors: clockwise theta, clockwise 2pi - theta, counter clockwise theta, counter clockwise 2pi - theta. In all that covers 4pi. $\endgroup$ Commented Jul 21, 2010 at 0:12
  • 2
    $\begingroup$ In quantum physics spin-1/2 spinors are almost never written as a quaternion. Instead, a 2x1 matrix of complex numbers is often used, because it can be decomposed into a 'spin-up' and 'spin-down' component. Of course one could find an isomorphism between it and quaternions, but talking about real world uses, this is not a good example. $\endgroup$
    – kennytm
    Commented Jul 24, 2010 at 20:05
  • 1
    $\begingroup$ My comment above is definitely wrong in regards to the relationship between spinors and quaterions. Quaternions are a low dimensional version of spinors (isometrically). en.wikipedia.org/wiki/Spinor#Three_dimensions. The spinors make up the even graded portions of 3D GA. $\endgroup$ Commented Aug 4, 2010 at 2:03
19
$\begingroup$

To understand the benefits of using quaternions you have to consider different ways to represent rotations.

Here are few ways with a summary of the pros and cons:

  • Euler angles
  • Rotation matrices
  • Axis angle
  • Quaternions
  • Rotors (normalized Spinors)

Euler angles are the best choice if you want a user to specify an orientation in a intuitive way. They are are also space efficient (three numbers). However, it is more difficult to linear interpolate values. Consider the case where you want to interpolate between 359 and 0 degrees. Linearly interpolating would cause a large rotation, even though the two orientations are almost the same. Writing shortest path interpolation, is easy for one axis, but non-trivial when considering the three Euler angles(for instance the shortest route between (240, 57, 145) and (35, -233, -270) is not immediately clear).

Rotation matrices specify a new frame of reference using three normalized and orthogonal vectors (Right, Up, Out, which when multiplied become the new x, y, z). Rotation matrices are useful for operations like strafing (side ways movement), which only requires translating along the Right vector of the camera's rotation matrix. However, there is no clear method of interpolating between them. The are also expensive to normalize which is necessary to prevent scaling from being introduced.

Axis angle, as the name suggests, are a way of specifying a rotation axis and angle to rotate around that axis. You can think of Euler angles, as three axis angle rotations, where the axises are the x, y, z axis respectively. Linearly interpolating the angle in a axis angle is pretty straight forward (if you remember to take the shortest path), however linearly interpolating between different axises is not.

Quaternions are a way of specifying a rotation through a axis and the cosine of half the angle. They main advantage is I can pick any two quaternions and smoothly interpolate between them.

Rotors are another way to perform rotations. Rotors are basically quaternions, but instead of thinking of them as 4D complex numbers, rotors are thought of as real 3D multivectors. This makes their visualization much more understandable (compared to quaternions), but requires fluency in geometric algebra to grasp their significance.

Okay with that as the background I can discuss a real world example.

Say you are writing a computer game where the characters are animated in 3ds Max. You need to export a animation of the character to play in your game, but cannot faithfully represent the interpolation used by the animation program, and thus have to sample. The animation is going to be represented as a list of rotations for each joint. How should we store the rotations?

If I am going to sample every frame, not interpolate, and space is not an issue, I would probably store the rotations as rotation matrices. If space was issue, then Euler angles. That would also let me do things like only store one angle for joints like the knee that have only one degree of freedom.

If I only sampled every 4 frames, and need to interpolate it depends on whether I am sure the frame-rate will hold. If I am positive that the frame-rate will hold I can use axis angle relative rotations to perform the interpolation. This is atypical. In most games the frame rate can drop past my sampling interval, which would require skipping an element in the list to maintain the correct playback speed. If I am unsure of what two orientations I need to interpolate between, then I would use quaternions or rotors.

$\endgroup$
1
  • $\begingroup$ Axis angles are just extrinsic Euler angles right? You seem to make a distinction here by referring to extrinsic Euler angles as axis angles and instrinsic Euler angles as just Euler angles. $\endgroup$
    – DKNguyen
    Commented Nov 6, 2019 at 3:23
10
$\begingroup$

One place they are frequently used is in computer games when you want to smoothly transition from one rotation to another. An artist might have said "at this time I want the head oriented like this and at that time I want it like this". The computer needs to work out what happens in-between these poses. It's quite easy to find in-between poses using quaternions. If the two poses are reasonably similar, then you can get a half-way orientation simply by taking the average of the quaternions. You can find out more here.

$\endgroup$
4
$\begingroup$

I want to add one application of quaternions. In multiantenna radio transmission the so called Alamouti code is based on the algebra of Hamiltonian quaternions. See

http://en.wikipedia.org/wiki/Space%E2%80%93time_block_code

for more information. That Wikipedia article is a bit more general about Space-Time coding, but you can find the Alamouti construction there. The quaternion algebra shows there as a way of disentangling two Alamouti coded signals transmitted by a pair of antennas. The advantages come from the fact that even if the signal from one antenna is lost for a particular receiver (due to sitting in a node for that particular radio wave), then the signal from the other antenna saves the day. A moving receiver will drop a signal from one antenna in a random fashion, so when two independent antennas are used in this way total signal loss becomes a rarer event.

$\endgroup$
1
  • $\begingroup$ :0 I had not known quaternions had entered coding theory... $\endgroup$
    – rschwieb
    Commented Mar 23, 2017 at 13:28
3
$\begingroup$

You can view a real-world example of quaternions in computer graphics with the open source program known as NASA WorldWind (http://worldwind.arc.nasa.gov/java/).

It uses a Quaternion object to represent rotation of various geometries. The class definition itself is located in the src/gov/nasa/worldwind/geom/Quaternion.java file.

$\endgroup$
2
$\begingroup$

Modern Inertial Navigation programs use quaternions to represent rotations both of the craft body frame (pitch, yaw, roll) and geomatic position (lat, long.) Actually since these programs integrate measurements in the millisecond range, this use of quaternions is an example of calculus on a manifold, since the three dimensional sphere is a smooth manifold.

$\endgroup$
0
$\begingroup$

I believe it was Hamilton who coined the terms scalar, vector, dot product, cross product, divergence, gradient, and curl (but I am not 100% sure on that attribution). These all show up when either multiplying two quaternions or taking a 4-derivative of a quaternion-valued function. In 4D, vectors and quaternions can be isomorphic (the same thing, just a different name).

For rotations, quaternions are superior to using Euler angles. The reason is that quaternions avoid a problem known as gimbal lock. That happens if two of the three rotational axes happen to align. When then a small change makes the system make a big jump.

I do research into quaternions, available at http://visualphysics.org and in blogs at http://Science20.com/standup_physics. There certainly is a huge amount of overlap between quaternions and vectors in 4D. There is much new to figure out too. For example, I know how to make animations out of quaternion expressions: think analytic animations, a 21th century update to analytic geometry.

$\endgroup$
0
$\begingroup$

In the late 80's at Kaiser Electronics I developed software to combine three 3-D rotations by multiplying their quaternions for pointing to a target like an approaching missile or aircraft using a fighter pilot's helmet mounted display: orientations of target to ground reference frame, aircraft to ground, and helmet to aircraft. Everyone else in the company used much slower 4-D matrix multiplication, having never heard of quaternions as they were not in their computer graphics "bible" by Foley and Van Dam. Some years later I saw that book somewhere and saw quaternions mentioned in it.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .