Quaternions and spatial rotation

Quaternions and spatial rotation

Unit quaternions provide a convenient mathematical notation for representing orientations and rotations of objects in three dimensions. Compared to Euler angles they are simpler to compose and avoid the problem of gimbal lock. Compared to rotation matrices they are more efficient and more numerically stable. Quaternions have found their way into applications in computer graphics, robotics, navigation, and orbital mechanics of satellites. ["Quaternions and rotation Sequences: a Primer with Applications to Orbits, Aerospace, and Virtual Reality." Kuipers, Jack B., Princeton University Press copyright 1999.]

Quaternion rotation operations

A very strict explanation of the properties used in this section is given by Altmann. ["Rotations, Quaternions, and Double Groups." Altmann, Simon L., Dover Publications, 1986.]

Visualizing the space of rotations

Unit quaternions represent in a very straightforward way the mathematical space of rotations in three dimensions. The correspondence between rotations and quaternions can be understood by first visualizing the space of rotations itself.

Any rotation in three dimensions is a rotation by some angle about some axis. When the angle is zero the axis does not matter, so rotation by zero degrees is a single point in the space of rotations (the identity rotation). For a tiny but nonzero angle, the set of possible rotations is like a small sphere surrounding the identity rotation, where each point on the sphere represents an axis pointing in a particular direction (compare the celestial sphere). Rotations through increasingly large angles are increasingly far from the identity rotation, and we can think of them as concentric spheres of increasing radius. Thus, near the identity rotation, the abstract space of rotations looks similar to ordinary three-dimensional space (which can also be seen as a central point surrounded by concentric spheres of every radius). However, as the rotation angle increases toward 360°, rotations about different axes stop diverging and become more similar to each other, becoming identical (and equal to the identity rotation) when the angle reaches 360°.

We can see similar behavior on the surface of a sphere. If we start at the north pole and draw straight lines (that is, lines of longitude) in many directions, they will diverge but eventually converge again at the south pole. Concentric circles of increasing radius drawn around the north pole (lines of latitude) will eventually collapse to a point at the south pole once the radius reaches the distance between the poles. If we think of different directions from the pole (that is, different longitudes) as different rotation "axes", and different distances from the pole (that is, different latitudes) as different rotation "angles", we have an analogy to the space of rotations. Since the sphere's surface is two dimensional while the space of rotations is three dimensional, we must actually model the space of rotations as a hypersphere; however, we can think of the ordinary sphere as a slice through the full hypersphere (just as a circle is a slice through a sphere). We can take the slice to represent, for example, just the rotations about axes in the "xy" plane. Note that the angle of rotation is "twice" the latitude difference from the north pole: points on the equator represent rotations of 180°, not 90°, and the south pole represents a rotation of 360°, not 180°.

The north pole and the south pole represent the same rotation, and in fact this is true of any two antipodal points: if one is a rotation by "α" around the axis v, the other is a rotation by 360° − "α" around the axis −v. In fact, then, the space of rotations is not the (hyper)sphere itself but the (hyper)sphere with antipodal points identified. But for many purposes we can think of rotations as points on the sphere, even though they are twofold redundant (a so-called double cover).

Parameterizing the space of rotations

We can parameterize the surface of a sphere with two coordinates, such as latitude and longitude. But latitude and longitude are ill-behaved (degenerate) at the north and south poles, though the poles are not intrinsically different from any other points on the sphere. It can be shown that no two-parameter coordinate system can avoid such degeneracy (the hairy ball theorem). We can avoid such problems by embedding the sphere in three-dimensional space and parameterizing it with three Cartesian coordinates (here "w","x","y"), placing the north pole at ("w","x","y") = (1,0,0), the south pole at ("w","x","y") = (−1,0,0), and the equator at "w" = 0, "x"2 + "y"2 = 1. Points on the sphere satisfy the constraint "w"2 + "x"2 + "y"2 = 1, so we still have just two degrees of freedom though there are three coordinates. A point ("w","x","y") on the sphere represents a rotation around the ("x","y",0) axis by an angle alpha= 2 cos^{-1} w = 2 sin^{-1} sqrt{x^2+y^2}.

In the same way the hyperspherical space of 3D rotations can be parameterized by three angles (Euler angles), but any such parameterization is degenerate at some points on the hypersphere, leading to the problem of gimbal lock. We can avoid this by using four Euclidean coordinates "w","x","y","z", with "w"2 + "x"2 + "y"2 + "z"2 = 1. The point ("w","x","y","z") represents a rotation around the ("x","y","z") axis by an angle alpha = 2 cos^{-1} w = 2 sin^{-1} sqrt{x^2+y^2+z^2}.

Quaternions briefly

The complex numbers can be defined by introducing an abstract symbol i which satisfies the usual rules of algebra and additionally the rule i2 = −1. This is sufficient to reproduce all of the rules of complex number arithmetic: for example, (a+bmathbf{i})(c+dmathbf{i}) = ac + admathbf{i} + bmathbf{i}c + bmathbf{i}dmathbf{i} = ac + admathbf{i} + bcmathbf{i} + bdmathbf{i}^2 = (ac - bd) + (bc + ad) mathbf{i}.

In the same way the quaternions can be defined by introducing abstract symbols i, j, k which satisfy the rules i2 = j2 = k2 = ijk = −1 and the usual algebraic rules "except" the commutative law of multiplication (a familiar example of such a noncommutative algebra is matrix algebra). From this all of the rules of quaternion arithmetic follow: for example, one can show that (a + bmathbf{i} + cmathbf{j} + dmathbf{k}) (e + fmathbf{i} + gmathbf{j} + hmathbf{k}) = (ae - bf - cg - dh) + (af + eb + ch - dg) mathbf{i} + (ag + ce + df - bh) mathbf{j} + (ah + de + bg - cf) mathbf{k}.

The imaginary part bmathbf{i} + cmathbf{j} + dmathbf{k} of a quaternion behaves like a vector (b, c, d) in mathbb{R}^3, and the real part "a" behaves like a scalar in mathbb{R}. When quaternions are used in geometry, it is more convenient to define them as "a scalar plus a vector" and use the modern language of vector cross and dot products (which were originally inspired by the quaternions). In place of the rules i2 = j2 = k2 = ijk = −1 we have the vector multiplication rule mathbf{vw} = mathbf{v} imes mathbf{w} - mathbf{v} cdot mathbf{w}. Vector multiplication is noncommutative (because of the cross product), while scalar-scalar and scalar-vector multiplications commute. From these rules it follows immediately that (s + mathbf{v}) (t + mathbf{w}) = (st - mathbf{v} cdot mathbf{w}) + (smathbf{w} + tmathbf{v} + mathbf{v} imes mathbf{w}).

The (left and right) multiplicative inverse of a nonzero quaternion is (s + mathbf{v})^{-1} = frac{s - mathbf{v{s^2 + |mathbf{v}|^2}, as can be verified by direct calculation.

Parameterizing the space of rotations with quaternions

Let ("w","x","y","z") be the coordinates of a rotation as previously described. Define the quaternion:q = w + xmathbf{i} + ymathbf{j} + zmathbf{k} = w + (x,y,z) = cos (alpha/2) + mathbf{u} sin (alpha/2)where u is a unit vector. Then it can be shown (see next section) that the quaternion product:q mathbf{v} q^{-1}yields the vector v rotated by an angle "α" around the u axis. The rotation is clockwise if our line of sight points in the direction u. This operation is known as conjugation by "q".

It follows that quaternion multiplication is composition of rotations, for if "p" and "q" are quaternions representing rotations, then rotation (conjugation) by "pq" is:p q mathbf{v} (p q)^{-1} = p q mathbf{v} q^{-1} p^{-1},which is the same as rotating (conjugating) by "q" and then by "p".

The quaternion inverse of a rotation is the opposite rotation, since q^{-1} (q mathbf{v} q^{-1}) q = mathbf{v}. The square of a quaternion rotation is a rotation by twice the angle around the same axis. More generally "q""n" is a rotation by "n" times the angle around the same axis as "q". This can be extended to arbitrary real "n", allowing for smooth interpolation between spatial orientations; see Slerp.

Proof of the quaternion rotation identity

Let u be a unit vector (the rotation axis) and let q = cos frac{alpha}{2} + mathbf{u} sin frac{alpha}{2}. Our goal is to show that:mathbf{v}' = q mathbf{v} q^{-1} = left( cos frac{alpha}{2} + mathbf{u} sin frac{alpha}{2} ight) , mathbf{v} , left( cos frac{alpha}{2} - mathbf{u} sin frac{alpha}{2} ight)yields the vector v rotated by an angle "α" around the axis u. Expanding out, we have:egin{array}{lll}mathbf{v}' &=& mathbf{v} cos^2 frac{alpha}{2} + (mathbf{uv} - mathbf{vu}) sin frac{alpha}{2} cos frac{alpha}{2} - mathbf{uvu} sin^2 frac{alpha}{2} \&=& mathbf{v} cos^2 frac{alpha}{2} + 2 (mathbf{u} imes mathbf{v}) sin frac{alpha}{2} cos frac{alpha}{2} - (mathbf{v} (mathbf{u} cdot mathbf{u}) - 2 mathbf{u} (mathbf{u} cdot mathbf{v})) sin^2 frac{alpha}{2} \&=& mathbf{v} (cos^2 frac{alpha}{2} - sin^2 frac{alpha}{2}) + (mathbf{u} imes mathbf{v}) (2 sin frac{alpha}{2} cos frac{alpha}{2}) + mathbf{u} (mathbf{u} cdot mathbf{v}) (2 sin^2 frac{alpha}{2}) \&=& mathbf{v} cos alpha + (mathbf{u} imes mathbf{v}) sin alpha + mathbf{u} (mathbf{u} cdot mathbf{v}) (1 - cos alpha) \&=& (mathbf{v} - mathbf{u} (mathbf{u} cdot mathbf{v})) cos alpha + (mathbf{u} imes mathbf{v}) sin alpha + mathbf{u} (mathbf{u} cdot mathbf{v}) \&=& mathbf{v}_{ot} cos alpha + (mathbf{u} imes mathbf{v}_{ot}) sin alpha + mathbf{v}_{\end{array}where mathbf{v}_{ot} and mathbf{v}_{ are the components of v perpendicular and parallel to u respectively. This is the formula of a rotation by "α" around the u axis.

Example

Consider the rotation "f" around the axis u = "i" + "j" + "k", with a rotation angle of 120°, or ⁄3 radians.

:alpha = frac{2 pi}{3} = 120^circ

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

:z = cosfrac{alpha}{2} + sinfrac{alpha}{2},hatmathbf{u}

:z = cos 60^circ + sin 60^circ,hatmathbf{u}

:z = frac{1}{2} + frac{sqrt{3{2}cdot,hatmathbf{u}

:z = frac{1}{2} + frac{sqrt{3{2}cdot frac{(i+j+k)}{sqrt{3

:z = frac{1 + i + j + k}{2}.

Concretely,:"f"("ai" + "bj" + "ck") = "z" ("ai" + "bj" + "ck") "z"-1 .

Note that "z"-1 = 1/"z", as "z" has unit modulus; here"z"-1 = "z"* = (1−"i"−"j"−"k")/2. This can be simplified, using the ordinary rules for quaternion arithmetic, to:"f"("ai" + "bj" + "ck") = "ci" + "aj" + "bk",

as expected: the rotation corresponds to keeping a cube held fixed at one point, and rotating it 120° about the long diagonal through the fixed point (observe how the three axes are permuted cyclically).

Quaternion non-commutativity and rotations

The multiplication of quaternions is non-commutative. Since this operation corresponds to a three dimensional rotation, this property can be easily demonstrated by showing that three dimensional rotations are not commutative in general. A simple exercise of applying two rotations to an asymmetrical object (e.g., a book) can explain it. First, rotate a book 90 degrees clockwise around the z axis. Next rotate it 180 degrees clockwise around the x axis and memorize the result. Then restore the original orientation, so that the book title is again readable, and apply those rotations in opposite order. Compare the outcome to the earlier result. This shows that, in general, the composition of two different rotations around two distinct spatial axes will not commute.

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 such as the spherical linear interpolation in the quaternions, with one endpoint being the identity transformation 1 (or some other initial rotation) and the other being the intended final 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 after being normalised—a matrix that’s slightly off need not be orthogonal anymore and therefore is harder to convert back to a proper orthogonal matrix.

Quaternions also avoid a phenomenon called gimbal lock which can result when, for example in pitch/yaw/roll rotational systems, the pitch is rotated 90° up or down, so that yaw and roll then correspond to the same motion, and a degree of freedom of rotation is lost. In a gimbal-based aerospace inertial navigation system, for instance, this could have disastrous results if the aircraft is in a steep dive or ascent.

The orthogonal matrix corresponding to a rotation by the unit quaternion "z" = "a" + "bi" + "cj" + "dk" (with |z| = 1) is given by:egin{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}.

Beware the vector convention: There are two conventions for rotation matrices: one assumes row vectors on the left; the other assumes column vectors on the right; the two conventions generate matrices that are the transpose of each other. The above matrix assumes row vectors on the left. In general, a matrix for vertex transpose is ambiguous unless the vector convention is also mentioned. Historically, the column-on-the-right convention comes from math and classical mechanics, whereas row-vector-on-the-left comes from computer graphics, where typesetting row vectors was easier back in the early days.

(Compare the equivalent general formula for a 3 × 3 rotation matrix in terms of the axis and the angle.)

Note that quaternions, like any other rotation or linear transform, are not "handed" (as in left-handed vs right-handed). Handedness of a coordinate system comes from the interpretation of the numbers in physical space. No matter what the handedness convention, rotating the X vector 90 degrees around the Z vector will yield the Y vector -- the math and numbers are the same.

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

Performance comparisons with other rotation methods

This section discusses the performance implications of using quaternions versus other methods (axis/angle or rotation matrices) to perform rotations in 3D. A brief summary:

* Note: angle-axis can be stored as 3 elements by multiplying the unit rotation axis by the rotation angle; however, before using it the unit axis and angle must be recovered by normalizing, costing additional math operations.

There are three basic approaches to rotating a vector "v":
# Compute the matrix-vector product of a 3x3 rotation matrix R and the original 3x1 vector "v", giving v_{new} = mathbf{R}v. This requires 3*(3 multiplications + 2 additions) = 9 multiplications and 6 additions, the most efficient method for rotating a vector.
# Use the quaternion rotation formula derived above of v_{new}= z mathbf{v} z^{-1}. Computing this result is equivalent to transforming the quaternion to a rotation matrix R using the formula above then multiplying with a vector. Performing some common subexpression elimination yields an algorithm that costs 21 multiplies and 18 adds. As a second approach, the quaternion could first be converted to its equivalent angle/axis representation then the angle/axis representation used to rotate the vector. However, this is both less efficient and less numerically stable when the quaternion nears the no rotation point.
# Use the angle-axis formula to convert an angle/axis to a rotation matrix R then multiplying with a vector. Converting the angle/axis to R using common subexpression elimination costs 14 multiplies, 2 function calls (sin, cos), and 10 add/subtracts; from item 1, rotating using R adds an additional 9 multiplications and 6 additions for a total of 23 multiplies, 16 add/subtracts, and 2 function calls (sin, cos).

Pseudo-code for rotating using a quaternion: given a quaternion "z" = "a" + "bi" + "cj" + "dk" (with |z| = 1) and a vector "v" with elements "v1", "v2", and "v3", the following code performs a rotation. Note the use of temporary variables "t"xx. Also note one optimization of the diagonal entries of the R matrix: since a^2 + b^2 + c^2 + d^2 = 1, rewrite the top-left entry as a^2 + b^2 + c^2 + d^2 - 2c^2 - 2d^2 = 1 - 2c^2 - 2d^2; the other two diagonal entries can be similarly rewritten. t2 = a*b t3 = a*c t4 = a*d t5 = -b*b t6 = b*c t7 = b*d t8 = -c*c t9 = c*d t10 = -d*d v1new = 2*( (t8 + t10)*v1 + (t6 - t4)*v2 + (t3 + t7)*v3 ) + v1 v2new = 2*( (t4 + t6)*v1 + (t5 + t10)*v2 + (t9 - t2)*v3 ) + v2 v3new = 2*( (t7 - t3)*v1 + (t2 + t9)*v2 + (t5 + t8)*v3 ) + v3

Pseudo-code for creating an angle/axis matrix where the unit axis is ("v1", "v2", "v3") and the angle is "θ": t1 = cos(theta) t2 = 1 - t1 t3 = v1*v1 t6 = t2*v1 t7 = t6*v2 t8 = sin(theta) t9 = t8*v3 t11 = t6*v3 t12 = t8*v2 t15 = v2*v2 t19 = t2*v2*v3 t20 = t8*v1 t24 = v3*v3 R [1, 1] = t1 + t2*t3 R [1, 2] = t7 - t9 R [1, 3] = t11 + t12 R [2, 1] = t7 + t9 R [2, 2] = t1 + t2*t15 R [2, 3] = t19 - t20 R [3, 1] = t11 - t12 R [3, 2] = t19 + t20 R [3, 3] = t1 + t2*t24

Pairs of unit quaternions as rotations in 4D space

A pair of unit quaternions "z"l and "z"r 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)=z_lvz_r=egin{pmatrix}a_l&-b_l&-c_l&-d_l\b_l&a_l&-d_l&c_l\c_l&d_l&a_l&-b_l\d_l&-c_l&b_l&a_lend{pmatrix}egin{pmatrix}a_r&-b_r&-c_r&-d_r\b_r&a_r&d_r&-c_r\c_r&-d_r&a_r&b_r\d_r&c_r&-b_r&a_rend{pmatrix}egin{pmatrix}w\x\y\zend{pmatrix}.

It is straightforward to check that for each matrix "M" "M"T = "I", that is, that each matrix (and hence both matrices together) represents a rotation. Note that since ("z""l" "v") "z""r" = "z""l" ("v" "z""r"), the two matrices must commute. Therefore, there are two commuting subgroups of the set of four dimensional rotations. Arbitrary four dimensional rotations have 6 degrees of freedom, each matrix represents 3 of those 6 degrees of freedom.

Since an infinitesimal four-dimensional rotation can be represented by a pair of quaternions (as follows), all (non-infinitesimal) four-dimensional rotations can also be represented.

z_lvz_r=egin{pmatrix}1 &-dt_{ab}&-dt_{ac}&-dt_{ad}\dt_{ab}&1 &-dt_{bc}&-dt_{bd}\dt_{ac}& dt_{bc}&1 &-dt_{cd}\dt_{ad}& dt_{bd}& dt_{cd}&1end{pmatrix}egin{pmatrix}w\x\y\zend{pmatrix}

z_l=left(1+{dt_{ab}+dt_{cd}over 2}i+{dt_{ac}-dt_{bd}over 2}j+{dt_{ad}+dt_{bc}over 2}k ight)

z_r=left(1+{dt_{ab}-dt_{cd}over 2}i+{dt_{ac}+dt_{bd}over 2}j+{dt_{ad}-dt_{bc}over 2}k ight)

See also

*Slerp — spherical linear interpolation
*conversion between quaternions and Euler angles
*rotation group
*coordinate rotations
*Clifford algebras
*spinor group
*covering map
*3-sphere
*SO(4)

References

External links and resources

* [ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z Shoemake, Ken. Quaternion tutorial]
* [http://graphics.stanford.edu/courses/cs348c-95-fall/software/quatdemo/ Hart, Francis, Kauffman. Quaternion demo]
* [http://www.diku.dk/publikationer/tekniske.rapporter/1998/98-5.ps.gz Dam, Koch, Lillholm. Quaternions, Interpolation and Animation]
* [http://home.ewha.ac.kr/~bulee/quaternion.pdf Byung-Uk Lee, Unit Quaternion Representation of Rotation]
* [http://www.itk.org/CourseWare/Training/QuaternionsI.pdf Ibanez, Luis, Quaternion Tutorial I]
* [http://www.itk.org/CourseWare/Training/QuaternionsII.pdf Ibanez, Luis, Quaternion Tutorial II]
* [http://citeseer.ist.psu.edu/vicci01quaternions.html Leandra Vicci, Quaternions and Rotations in 3-Space: The Algebra and its Geometric Interpretation]


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Conversion between quaternions and Euler angles — Spatial rotations in three dimensions can be parametrized using both Euler angles and unit quaternions. This article explains how to convert between the two representations. Actually this simple use of quaternions was first presented by Euler… …   Wikipedia

  • Rotation (mathematics) — Rotation of an object in two dimensions around a point O. In geometry and linear algebra, a rotation is a transformation in a plane or in space that describes the motion of a rigid body around a fixed point. A rotation is different from a… …   Wikipedia

  • Rotation matrix — In linear algebra, a rotation matrix is a matrix that is used to perform a rotation in Euclidean space. For example the matrix rotates points in the xy Cartesian plane counterclockwise through an angle θ about the origin of the Cartesian… …   Wikipedia

  • Rotation group — This article is about rotations in three dimensional Euclidean space. For rotations in four dimensional Euclidean space, see SO(4). For rotations in higher dimensions, see orthogonal group. In mechanics and geometry, the rotation group is the… …   Wikipedia

  • History of quaternions — This article is an indepth story of the history of quaternions. It tells the story of who and when. To find out what quaternions are see quaternions and to learn about historical quaternion notation of the 19th century see classical quaternions… …   Wikipedia

  • Quaternion — Quaternions, in mathematics, are a non commutative extension of complex numbers. They were first described by the Irish mathematician Sir William Rowan Hamilton in 1843 and applied to mechanics in three dimensional space. They find uses in both… …   Wikipedia

  • Dual quaternion — The set of dual quaternions is an algebra that can be used to represent spatial rigid body displacements.[1] A dual quaternion is an ordered pair of quaternions  = (A, B) and therefore is constructed from eight real parameters. Because rigid… …   Wikipedia

  • Charts on SO(3) — In mathematics, the special orthogonal group in three dimensions, otherwise known as the rotation group SO(3), is a naturally occurring example of a manifold. The various charts on SO(3) set up rival coordinate systems: in this case there cannot… …   Wikipedia

  • Spinor — In mathematics and physics, in particular in the theory of the orthogonal groups (such as the rotation or the Lorentz groups), spinors are elements of a complex vector space introduced to expand the notion of spatial vector. Unlike tensors, the… …   Wikipedia

  • Euler angles — The Euler angles were developed by Leonhard Euler to describe the orientation of a rigid body (a body in which the relative position of all its points is constant) in 3 dimensional Euclidean space. To give an object a specific orientation it may… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”