Quaternions and spatial rotation

Quaternions are used in computer graphics and related fields because they allow for compact representations of rotations in 3D space. This will be explained in this article.

A pair of quaternions also allows for compact representations of rotations in 4D space. This won’t be explained much in this article, except for a short comment at the end.

Contents

Introduction

Every quaternion z = a + bi + cj + dk can be viewed as a sum a + u of a real number a (called the “real part” of the quaternion) and a 3-vector u = (b, c, d) = bi + cj + dk in R3 (called the “imaginary part”). In this view, quaternions are “mixed sums” of scalars and 3-vectors, and the quaternions i, j, and k correspond to the unit vectors i, j, and k.

Two such quaternions are added by adding the real parts and the imaginary parts separately:

(a + u) + (b + v) = (a + b) + (u + v)

The multiplication of quaternions translates into the following rule:

(a + u) (b + v) = (ab − <u, v>) + (av + bu + u × v)

Here, <u, v> denotes the scalar product and u × v the vector product of u and v.

This formula shows that two quaternions z and w commute, i.e., zw = wz, if and only if their imaginary parts are collinear vectors (because, in this case, the vector product of their imaginary parts will simply be equal to the zero vector).

Quaternion rotation

It is well known that the vector product is related to rotation in space. The goal then is to find a formula which expresses rotation in 3D space using quaternion multiplication, similar to the formula for a rotation in 2D using complex multiplication,

<math>f(w) = zw<math>,

where

<math>z = e^{\alpha i}<math>

is used for rotation by an angle α.

The formula in 3D cannot be a simple multiplication with a quaternion, because rotating a vector should yield a vector. Multiplying a vector with a non-trivial quaternion yields a result with non-zero real part, and thus not a vector.

It turns out that we can cancel the real part if we multiply by a quaternion from one side and with its inverse from the other side. Let z = a + u be a non-zero quaternion, and consider the function

f(v) = z v z−1,

where z−1 is the multiplicative inverse of z and v is a vector, considered as a quaternion with zero real part. The function f is known as conjugation by z. Note that the real part of f(v) is zero, because in general zw and wz have the same real part for any quaternions z and w, and so

<math>\mathfrak{R}(z \ \mathbf{v} \ z^{-1}) = \mathfrak{R}(\mathbf{v} \ z^{-1} \ z) = \mathfrak{R}(\mathbf{v} \ 1) = 0<math>

Furthermore, f is a R-linear and we have f(v) = v if and only if v and the imaginary part u of z are collinear (because f(v) = v means v z = z v). Hence f is a rotation whose axis of rotation passes through the origin and is given by the vector u.

Note that conjugation with z is the same as conjugation with rz for any real number r. We can thus restrict our attention to the quaternions of absolute value 1, the so-called unit quaternions. (The absolute value |z| of the quaternion z = a + v is defined as the square root of a2 + ||v||2. It is multiplicative: |zw| = |z| |w|.) Inverting unit quaternions is especially easy: If |z| = 1, then z−1 = z* (the conjugate z* of the quaternion z = a + v is defined as z* = av) and this makes our rotation formula even easier.

It turns out that the angle of rotation α is also easy to read off if we are dealing with a unit quaternion z = a + v: we have

<math>a = \cos \frac{\alpha}{2}<math>.

To summarize, a counterclockwise rotation through an angle α about an axis v can be represented via conjugation by the unit quaternion z

<math>z = a + \sin\frac{\alpha}{2}\,\hat\mathbf{v} <math>,
<math>z = \cos\frac{\alpha}{2} + \sin\frac{\alpha}{2}\,\hat\mathbf{v}<math>,

where <math>\hat\mathbf{v}<math> is the normalized vector

<math>\hat\mathbf{v} = \frac{\mathbf{v}}{||\mathbf{v}||}<math>.

The composition of two rotations corresponds to quaternion multiplication: if the rotation f is represented by conjugation with the quaternion z and the rotation g is represented by conjugation with w, then the composition f o g is represented by conjugation with zw.

If one wishes to rotate about an axis that doesn’t pass through the origin, then one first translates the vectors into the origin, conjugates, and translates back.

An example

Let us consider the rotation f around the axis u = i + j + k, with an rotation angle of 120°—i.e., 3 radians.

<math>\alpha = \frac{2 \pi}{3} = 120^\circ<math>

The length of u is √3, the half angle is π3 ( 60° ) with cosine ½ ( cos 60° = 0.5 ) and sine √32 ( sin 60° = 0.866 ). We are therefore dealing with a conjugation by the unit quaternion

<math>z = \cos\frac{\alpha}{2} + \sin\frac{\alpha}{2}\,\hat\mathbf{u}<math>
<math>z = \cos 60^\circ + \sin 60^\circ\,\hat\mathbf{u}<math>
<math>z = \frac{1}{2} + \frac{\sqrt{3}}{2}\cdot\,\hat\mathbf{u}<math>
<math>z = \frac{1}{2} + \frac{\sqrt{3}}{2}\cdot \frac{(i+j+k)}{\sqrt{3}}<math>
<math>z = \frac{1 + i + j + k}{2}<math>.

Concretely,

f(ai + bj + ck) = z (ai + bj + ck) z*

which, using the ordinary rules for quaternion arithmetic, can be simplified to

f(ai + bj + ck) = ci + aj + bk,

as expected.

Quaternions versus other representations of rotations

The representation of a rotation as a quaternion (4 numbers) is more compact than the representation as an orthogonal matrix (9 numbers). Furthermore, for a given axis and angle, one can easily construct the corresponding quaternion, and conversely, for a given quaternion one can easily read off the axis and the angle. Both of these are much harder with matrices or Euler angles.

In computer games and other applications, one is often interested in “smooth rotations,” meaning that the scene should slowly rotate and not in a single step. This can be accomplished by choosing a curve in the quaternions, with one endpoint being the identity transformation 1 and the other being the intended total rotation. This is more problematic with other representations of rotations.

When composing several rotations on a computer, rounding errors necessarily accumulate. A quaternion that’s slightly off still represents a rotation—a matrix that’s slightly off need not be orthogonal anymore and therefore need not represent a rotation at all. It is hard to turn such a matrix back into a proper orthogonal one.

The orthogonal matrix corresponding to a rotation by the unit quaternion z = a + bi + cj + dk (with |z| = 1) is given by

<math>\begin{pmatrix}

a^2+b^2-c^2-d^2&2bc-2ad &2ac+2bd \\ 2ad+2bc &a^2-b^2+c^2-d^2&2cd-2ab \\ 2bd-2ac &2ab+2cd &a^2-b^2-c^2+d^2\\ \end{pmatrix}<math>

See also: Charts on SO(3), Euler angles

Pairs of unit quaternions as rotations in 4D space

A pair of unit quaternions zl and zr can represent any rotation in 4D space. Given a four dimensional vector v, and pretending that it is a quaternion, we can rotate the vector v like this:

f(v) = zl v zr

Related topics

External links and resources

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools