By: Laura Downs
Contents: Review of Complex Numbers, Review of Quaternions, Representing Rotations, Concatenating Rotations, For the Mathematically Inclined, A Matrix Representation for Quaternion Multiplication, Computing Rotation Matrices from Quaternions, Euler Angles
If you would like a hard copy of these notes, a gzipped postscript version can be found in the file quatnotes.ps. The LaTeX source can be found in the file quatnotes.tex.
If you are interested in better understanding quaternions, look at the proof that quaternions can be used to compute rotations
As you know, the system of complex numbers is
defined in terms of i, a square root of -1.
Although i is not a real number, we can
write any complex number in terms of real numbers, using a real
and a complex part. We can also define a conjugate and a
magnitude (or absolute value) for these numbers.
Using the properties above, we can describe
multiplication for complex numbers
Quaternions are an extension of complex
numbers. Instead of just i, we have three different
numbers that are all square roots of -1 labelled i, j,
and k.
When you multiply two of these numbers
together, they behave similarly to cross products of the unit
basis vectors.
The conjugate and magnitude of a quaternion are
found in much the same way as complex conjugate and magnitude.
| Unit quaternions | |
| Quaternions are associative | |
| Quaternions are not commutative |
The inverse of a quaternion refers to the multiplicative inverse (or 1/q) and can be computed by q-1=q'/(q*q')
If a quaternion q has length 1, we say that q is a unit quaternion. The inverse of a unit quaternion is its conjugate, q-1=q'
We can represent a quaternion in several ways,
We can write the product of two quaternions in
terms of the (s,v) representation using standard vector
products in the following way:
We will compute a rotation about the unit
vector, u by an angle theta. The quaternion that
computes this rotation is
We will represent a point p in space by the quaternion P=(0,p)
We compute the desired rotation of that point by this formula:
You may want to confirm that q is a unit quaternion,
since that will allow us to use the fact that the inverse of q
is q' if q is a unit quaternion.
Suppose we want to perform two rotations on an object. This may come up in a manipulation interface where each movement of the mouse adds another rotation to the current object pose. This is very easy and numerically stable with a quaternion representation.
Suppose q1 and q2
are unit quaternions representing two rotations. We want to
perform q1 first and then q2.
To do this, we apply q2 to the result of
q1, regroup the product using
associativity, and find that the composite rotation is
represented by the quaternion q2*q1.
Therefore, the only time we need to compute the matrix is when we
want to transform the object. For other operations we need only
look at the quaternions. A matrix product requires many more
operations than a quaternion product so we can save a lot of time
and preserve more numerical accuracy with quaternions than with
matrices.
(ref: Topics in Algebra by I.N.Herstein pp120-126)
The complex numbers are a field. This means that:
Essentially what this says is that complex numbers act just like numbers as we know them. We can add, multiply, subtract, and divide them and we can use any of our standard algebraic manipulations. Other examples of fields are the real numbers and the rational numbers.
The quaternions have all of the same properties except
that quaternion multiplication is not commutative. In
general, q1*q2
!= q2*q1. We
call this structure a division ring. This means that we
can do any kind of arithmetic with quaternions as long as we are
careful to note the order of multiplication.
The inverse of a quaternion refers to the multiplicative
inverse (or 1/q) and can be computed by q-1=q'/(q*q')
for any non-zero quaternion.
The set of all 3x3 matrices (or all 4x4 matrices) with standard matrix addition and multiplication is a ring but not a division ring, because not all matrices have inverses.
(ref: Graphics Gems II, pp351-354 - warning: the final matrix is transposed!)
We can use the rules above to compute the
product of two quaternions.
If you examine each term in this product, you can see that each term depends linearly on the coefficients for q1. Also each term depends linearly on the coefficients for q2. So, we can write the product of two quaternions in terms of a matrix multiplication.
When the matrix Lrow(q1) multiplies a row vector q2, the result is a row vector representation for q1 * q2.
When the matrix Rrow(q2)
multiplies a row vector q1, the result
is also a row vector representation for q1
* q2.
Now we have all the tools we need to use
quaternions to generate a rotation matrix for the given rotation.
We have a matrix form for left-multiplication by q
and a matrix form for right-multiplication by q'.
The resulting rotation matrix is the product of these two
matrices.
q * P * q' = q * ( P * q') = q * (P Rrow(q')) = (P Rrow(q')) Lrow(q) = P (Rrow(q') Lrow(q)) = P Qrow(q)
So using this matrix, we could compute Protated
another way:
In many fields Euler angles are used to represent rotations. Any rotation can be broken down into a series of three rotations about the major axes.
We can simulate any arbitrary rotation with one rotation about the x-axis, one about the y-axis, and then one about the z-axis. For example, consider an airplane pointing along the x-axis with the z-axis pointing up. We can represent any pose by
as a vector (roll,pitch,yaw). This representation is useful and intuitive in some cases, such as this one, but Euler angles have some drawbacks.
[kdtop wrote this paragraph (and the "contents" above):] This page was originally created by Laura Downs. Her home page was found at: http://www.cs.berkeley.edu/~laura/ The original version of this file can be found at: http://www.cs.berkeley.edu/~laura/cs184/quat/quaternion.html
Last modified: Fri Apr 19 16:22:10 2002
Laura Downs (laura@cs.berkeley.edu)