fbpx
Wikipedia

Quaternions and spatial rotation

Unit quaternions, known as versors, provide a convenient mathematical notation for representing spatial orientations and rotations of elements in three dimensional space. Specifically, they encode information about an axis-angle rotation about an arbitrary axis. Rotation and orientation quaternions have applications in computer graphics,[1] computer vision, robotics,[2] navigation, molecular dynamics, flight dynamics,[3] orbital mechanics of satellites,[4] and crystallographic texture analysis.[5]

When used to represent rotation, unit quaternions are also called rotation quaternions as they represent the 3D rotation group. When used to represent an orientation (rotation relative to a reference coordinate system), they are called orientation quaternions or attitude quaternions. A spatial rotation around a fixed point of radians about a unit axis that denotes the Euler axis is given by the quaternion , where and .

Compared to rotation matrices, quaternions are more compact, efficient, and numerically stable. Compared to Euler angles, they are simpler to compose. However, they are not as intuitive and easy to understand and, due to the periodic nature of sine and cosine, rotation angles differing precisely by the natural period will be encoded into identical quaternions and recovered angles in radians will be limited to .

Using quaternions as rotations

 
3D visualization of a sphere and a rotation about an Euler axis ( ) by an angle of  

In 3-dimensional space, according to Euler's rotation theorem, any rotation or sequence of rotations of a rigid body or coordinate system about a fixed point is equivalent to a single rotation by a given angle   about a fixed axis (called the Euler axis) that runs through the fixed point. The Euler axis is typically represented by a unit vector   (  in the picture). Therefore, any rotation in three dimensions can be represented as a combination of a vector   and a scalar  .

Quaternions give a simple way to encode this axis–angle representation in four numbers, and can be used to apply (calculate) the corresponding rotation to a position vector (x,y,z), representing a point relative to the origin in R3.

Euclidean vectors such as (2, 3, 4) or (ax, ay, az) can be rewritten as 2 i + 3 j + 4 k or axi + ayj + azk, where i, j, k are unit vectors representing the three Cartesian axes (traditionally x, y, z), and also obey the multiplication rules of the fundamental quaternion units.

Therefore, a rotation of angle   around the axis defined by the unit vector

 

can be represented by a quaternion. This can be done using an extension of Euler's formula:

 

It can be shown[further explanation needed] that the desired rotation can be applied to an ordinary vector   in 3-dimensional space, considered as a quaternion with a real coordinate equal to zero, by evaluating the conjugation of p by q:

 

using the Hamilton product, where p′ = (px′, py′, pz′) is the new position vector of the point after the rotation. In a programmatic implementation, the conjugation is achieved by constructing a quaternion whose vector part is p and real part equals zero, and then performing the quaternion multiplication. The vector part of the resulting quaternion is the desired vector p.

A geometric fact independent of quaternions is the existence of a two-to-one mapping from physical rotations to rotational transformation matrices. If 0 ⩽   , a physical rotation about   by   and a physical rotation about   by   both achieve the same final orientation by disjoint paths through intermediate orientations. By inserting those vectors and angles into the formula for q above, one finds that if q represents the first rotation, -q represents the second rotation. This is a geometric proof that conjugation by q and by q must produce the same rotational transformation matrix. That fact is confirmed algebraically by noting that the conjugation is quadratic in q, so the sign of q cancels, and does not affect the result. (See 2:1 mapping of SU(2) to SO(3)) If both rotations are a half-turn  , both q and -q will have a real coordinate equal to zero. Otherwise, one will have a positive real part, representing a rotation by an angle less than  , and the other will have a negative real part, representing a rotation by an angle greater than  .

Mathematically, this operation carries the set of all "pure" quaternions p (those with real part equal to zero)—which constitute a 3-dimensional space among the quaternions—into itself, by the desired rotation about the axis u, by the angle θ. (Each real quaternion is carried into itself by this operation. But for the purpose of rotations in 3-dimensional space, we ignore the real quaternions.)

The rotation is clockwise if our line of sight points in the same direction as  .

In this instance, q is a unit quaternion and

 

It follows that conjugation by the product of two quaternions is the composition of conjugations by these quaternions: If p and q are unit quaternions, then rotation (conjugation) by pq is

 ,

which is the same as rotating (conjugating) by q and then by p. The scalar component of the result is necessarily zero.

The quaternion inverse of a rotation is the opposite rotation, since  . The square of a quaternion rotation is a rotation by twice the angle around the same axis. More generally qn 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.

Two rotation quaternions can be combined into one equivalent quaternion by the relation:

 

in which q corresponds to the rotation q1 followed by the rotation q2. Thus, an arbitrary number of rotations can be composed together and then applied as a single rotation. (Note that quaternion multiplication is not commutative.)

Example conjugation operation

 
A rotation of 120° around the first diagonal permutes i, j, and k cyclically

Conjugating p by q refers to the operation pqpq−1.

Consider the rotation f around the axis  , with a rotation angle of 120°, or 2π/3 radians.

 
 
pq p for q = 1 + i + j + k/2 on the unit 3-sphere. Note this one-sided (namely, left) multiplication yields a 60° rotation of quaternions

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

 

If f is the rotation function,

 

It can be proven that the inverse of a unit quaternion is obtained simply by changing the sign of its imaginary components. As a consequence,

 

and

 

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

 

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-derived rotation matrix

A quaternion rotation   (with  ) can be algebraically manipulated into a matrix rotation  , where   is the rotation matrix given by:[6]

 

Here   and if q is a unit quaternion,  .

This can be obtained by using vector calculus and linear algebra if we express   and   as scalar and vector parts and use the formula for the multiplication operation in the equation  . If we write   as  ,   as   and   as  , where  , our equation turns into  . By using the formula for multiplication of two quaternions that are expressed as scalar and vector parts,

 

this equation can be rewritten as

 

where   denotes the outer product,   is the identity matrix and   is the transformation matrix that when multiplied from the right with a vector   gives the cross product  .

Since  , we can identify   as  , which upon expansion should result in the expression written in matrix form above.

Recovering the axis-angle representation

The expression   rotates any vector quaternion   around an axis given by the vector   by the angle  , where   and   depends on the quaternion  .

  and   can be found from the following equations:

 

where   is the two-argument arctangent.

Care should be taken when the quaternion approaches a scalar, since due to degeneracy the axis of an identity rotation is not well-defined.

The composition of spatial rotations

A benefit of the quaternion formulation of the composition of two rotations RB and RA is that it yields directly the rotation axis and angle of the composite rotation RC = RBRA.

Let the quaternion associated with a spatial rotation R be constructed from its rotation axis S with the rotation angle   around this axis. The associated quaternion is given by

 
Then the composition of the rotation RB with RA is the rotation RC = RBRA with rotation axis and angle defined by the product of the quaternions
 
that is
 

Expand this product to obtain

 

Divide both sides of this equation by the identity, which is the law of cosines on a sphere,

 
and compute
 

This is Rodrigues' formula for the axis of a composite rotation defined in terms of the axes of the two rotations. He derived this formula in 1840 (see page 408).[7]

The three rotation axes A, B, and C form a spherical triangle and the dihedral angles between the planes formed by the sides of this triangle are defined by the rotation angles. Hamilton[8] presented the component form of these equations showing that the quaternion product computes the third vertex of a spherical triangle from two given vertices and their associated arc-lengths, which is also defines an algebra for points in Elliptic geometry.

Axis–angle composition

The normalized rotation axis, removing the   from the expanded product, leaves the vector which is the rotation axis, times some constant. Care should be taken normalizing the axis vector when   is   or   where the vector is near  ; which is identity, or 0 rotation around any axis.

 

Or with angle addition trigonometric substitutions...

 

finally normalizing the rotation axis:   or  .

Differentiation with respect to the rotation quaternion

The rotated quaternion p' = q p q−1 needs to be differentiated with respect to the rotating quaternion q, when the rotation is estimated from numerical optimization. The estimation of rotation angle is an essential procedure in 3D object registration or camera calibration. For unitary q and pure imaginary p, that is for a rotation in 3D space, the derivatives of the rotated quaternion can be represented using matrix calculus notation as

 

A derivation can be found in.[9]

Background

Quaternions

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:

 

In the same way the quaternions can be defined by introducing abstract symbols i, j, k which satisfy the rules i2 = j2 = k2 = i j k = −1 and the usual algebraic rules except the commutative law of multiplication (a familiar example of such a noncommutative multiplication is matrix multiplication). From this all of the rules of quaternion arithmetic follow, such as the rules on multiplication of quaternion basis elements. Using these rules, one can show that:

 

The imaginary part   of a quaternion behaves like a vector   in three-dimensional vector space, and the real part a behaves like a scalar in R. When quaternions are used in geometry, it is more convenient to define them as a scalar plus a vector:

 

Some might find it strange to add a number to a vector, as they are objects of very different natures, or to multiply two vectors together, as this operation is usually undefined. However, if one remembers that it is a mere notation for the real and imaginary parts of a quaternion, it becomes more legitimate. In other words, the correct reasoning is the addition of two quaternions, one with zero vector/imaginary part, and another one with zero scalar/real part:

 

We can express quaternion multiplication in the modern language of vector cross and dot products (which were actually inspired by the quaternions in the first place[10]). When multiplying the vector/imaginary parts, in place of the rules i2 = j2 = k2 = ijk = −1 we have the quaternion multiplication rule:

 

where:

  •   is the resulting quaternion,
  •   is vector cross product (a vector),
  •   is vector scalar product (a scalar).

Quaternion multiplication is noncommutative (because of the cross product, which anti-commutes), while scalar–scalar and scalar–vector multiplications commute. From these rules it follows immediately that (see details):

 

The (left and right) multiplicative inverse or reciprocal of a nonzero quaternion is given by the conjugate-to-norm ratio (see details):

 

as can be verified by direct calculation (note the similarity to the multiplicative inverse of complex numbers).

Rotation identity

Let   be a unit vector (the rotation axis) and let  . Our goal is to show that

 

yields the vector   rotated by an angle   around the axis  . Expanding out (and bearing in mind that  ), we have

 

Using trigonometric identities:

 

where   and   are the components of v (perpendicular and parallel to u respectively). This is the formula of a rotation by   around the u axis.

Quaternion rotation operations

A very formal explanation of the properties used in this section is given by Altman.[11]

The hypersphere of rotations

Visualizing the space of rotations

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

 
Two separate rotations, differing by both angle and axis, in the space of rotations. Here, the length of each axis vector is relative to the respective magnitude of the rotation about that axis.

In order to visualize the space of rotations, it helps to consider a simpler case. Any rotation in three dimensions can be described by a rotation by some angle about some axis; for our purposes, we will use an axis vector to establish handedness for our angle. Consider the special case in which the axis of rotation lies in the xy plane. We can then specify the axis of one of these rotations by a point on a circle through which the vector crosses, and we can select the radius of the circle to denote the angle of rotation.

Similarly, a rotation whose axis of rotation lies in the xy plane can be described as a point on a sphere of fixed radius in three dimensions. Beginning at the north pole of a sphere in three-dimensional space, we specify the point at the north pole to be the identity rotation (a zero angle rotation). Just as in the case of the identity rotation, no axis of rotation is defined, and the angle of rotation (zero) is irrelevant. A rotation having a very small rotation angle can be specified by a slice through the sphere parallel to the xy plane and very near the north pole. The circle defined by this slice will be very small, corresponding to the small angle of the rotation. As the rotation angles become larger, the slice moves in the negative z direction, and the circles become larger until the equator of the sphere is reached, which will correspond to a rotation angle of 180 degrees. Continuing southward, the radii of the circles now become smaller (corresponding to the absolute value of the angle of the rotation considered as a negative number). Finally, as the south pole is reached, the circles shrink once more to the identity rotation, which is also specified as the point at the south pole.

Notice that a number of characteristics of such rotations and their representations can be seen by this visualization. The space of rotations is continuous, each rotation has a neighborhood of rotations which are nearly the same, and this neighborhood becomes flat as the neighborhood shrinks. Also, each rotation is actually represented by two antipodal points on the sphere, which are at opposite ends of a line through the center of the sphere. This reflects the fact that each rotation can be represented as a rotation about some axis, or, equivalently, as a negative rotation about an axis pointing in the opposite direction (a so-called double cover). The "latitude" of a circle representing a particular rotation angle will be half of the angle represented by that rotation, since as the point is moved from the north to south pole, the latitude ranges from zero to 180 degrees, while the angle of rotation ranges from 0 to 360 degrees. (the "longitude" of a point then represents a particular axis of rotation.) Note however that this set of rotations is not closed under composition. Two successive rotations with axes in the xy plane will not necessarily give a rotation whose axis lies in the xy plane, and thus cannot be represented as a point on the sphere. This will not be the case with a general rotation in 3-space, in which rotations do form a closed set under composition.

 
The sphere of rotations for the rotations that have a "horizontal" axis (in the xy plane).

This visualization can be extended to a general rotation in 3-dimensional space. The identity rotation is a point, and a small angle of rotation about some axis can be represented as a point on a sphere with a small radius. As the angle of rotation grows, the sphere grows, until the angle of rotation reaches 180 degrees, at which point the sphere begins to shrink, becoming a point as the angle approaches 360 degrees (or zero degrees from the negative direction). This set of expanding and contracting spheres represents a hypersphere in four dimensional space (a 3-sphere). Just as in the simpler example above, each rotation represented as a point on the hypersphere is matched by its antipodal point on that hypersphere. The "latitude" on the hypersphere will be half of the corresponding angle of rotation, and the neighborhood of any point will become "flatter" (i.e. be represented by a 3-D Euclidean space of points) as the neighborhood shrinks. This behavior is matched by the set of unit quaternions: A general quaternion represents a point in a four dimensional space, but constraining it to have unit magnitude yields a three-dimensional space equivalent to the surface of a hypersphere. The magnitude of the unit quaternion will be unity, corresponding to a hypersphere of unit radius. The vector part of a unit quaternion represents the radius of the 2-sphere corresponding to the axis of rotation, and its magnitude is the cosine of half the angle of rotation. Each rotation is represented by two unit quaternions of opposite sign, and, as in the space of rotations in three dimensions, the quaternion product of two unit quaternions will yield a unit quaternion. Also, the space of unit quaternions is "flat" in any infinitesimal neighborhood of a given unit quaternion.

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. At the poles (latitudes +90° and −90°), the longitude becomes meaningless.

It can be shown that no two-parameter coordinate system can avoid such degeneracy. We can avoid such problems by embedding the sphere in three-dimensional space and parameterizing it with three Cartesian coordinates (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, x2 + y2 = 1. Points on the sphere satisfy the constraint w2 + x2 + y2 = 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 in the ordinary space around the horizontal axis directed by the vector (x, y, 0) by an angle  .

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 w2 + x2 + y2 + z2 = 1. The point (w, x, y, z) represents a rotation around the axis directed by the vector (x, y, z) by an angle  

Explaining quaternions' properties with rotations

Non-commutativity

The multiplication of quaternions is non-commutative. This fact explains how the pq p q−1 formula can work at all, having q q−1 = 1 by definition. Since the multiplication of unit quaternions corresponds to the composition of three-dimensional rotations, this property can be made intuitive by showing that three-dimensional rotations are not commutative in general.

Set two books next to each other. Rotate one of them 90 degrees clockwise around the z axis, then flip it 180 degrees around the x axis. Take the other book, flip it 180° around x axis first, and 90° clockwise around z later. The two books do not end up parallel. This shows that, in general, the composition of two different rotations around two distinct spatial axes will not commute.

Orientation

The vector cross product, used to define the axis–angle representation, does confer an orientation ("handedness") to space: in a three-dimensional vector space, the three vectors in the equation a × b = c will always form a right-handed set (or a left-handed set, depending on how the cross product is defined), thus fixing an orientation in the vector space. Alternatively, the dependence on orientation is expressed in referring to such   that specifies a rotation as to axial vectors. In quaternionic formalism the choice of an orientation of the space corresponds to order of multiplication: ij = k but ji = −k. If one reverses the orientation, then the formula above becomes pq−1p q, i.e., a unit q is replaced with the conjugate quaternion – the same behaviour as of axial vectors.

Alternative conventions

It is reported[12] that the existence and continued usage of an alternative quaternion convention in the aerospace and, to a lesser extent, robotics community is incurring a significant and ongoing cost [sic]. This alternative convention is proposed by Shuster M.D. in [13] and departs from tradition by reversing the definition for multiplying quaternion basis elements such that under Shuster's convention,   whereas Hamilton's definition is  . This convention is also referred to as "JPL convention" for its use in some parts of NASA's Jet Propulsion Laboratory.

Under Shuster's convention, the formula for multiplying two quaternions is altered such that

 

The formula for rotating a vector by a quaternion is altered to be

 

To identify the changes under Shuster's convention, see that the sign before the cross product is flipped from plus to minus.

Finally, the formula for converting a quaternion to a rotation matrix is altered to be

 

which is exactly the transpose of the rotation matrix converted under the traditional convention.

Software applications by convention used

The table below groups applications by their adherence to either quaternion convention:[12]

Hamilton multiplication convention Shuster multiplication convention

While use of either convention does not impact the capability or correctness of applications thus created, the authors of [12] argued that the Shuster convention should be abandoned because it departs from the much older quaternion multiplication convention by Hamilton and may never be adopted by the mathematical or theoretical physics areas.

Comparison with other representations of rotations

Advantages of quaternions

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 video 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 is slightly off still represents a rotation after being normalized: a matrix that is slightly off may not be orthogonal any more and 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.

Conversion to and from the matrix representation

From a quaternion to an orthogonal matrix

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

 

This rotation matrix is used on vector w as  . The quaternion representation of this rotation is given by:

 

where   is the conjugate of the quaternion  , given by  

Also, quaternion multiplication is defined as (assuming a and b are quaternions, like z above):

 

where the order a, b is important since the cross product of two vectors is not commutative.

A more efficient calculation in which the quaternion does not need to be unit normalized is given by[16]

 

where the following intermediate quantities have been defined:

 

From an orthogonal matrix to a quaternion

One must be careful when converting a rotation matrix to a quaternion, as several straightforward methods tend to be unstable when the trace (sum of the diagonal elements) of the rotation matrix is zero or very small. For a stable method of converting an orthogonal matrix to a quaternion, see the Rotation matrix#Quaternion.

Fitting quaternions

The above section described how to recover a quaternion q from a 3 × 3 rotation matrix Q. Suppose, however, that we have some matrix Q that is not a pure rotation—due to round-off errors, for example—and we wish to find the quaternion q that most accurately represents Q. In that case we construct a symmetric 4 × 4 matrix

 

and find the eigenvector (x, y, z, w) corresponding to the largest eigenvalue (that value will be 1 if and only if Q is a pure rotation). The quaternion so obtained will correspond to the rotation closest to the original matrix Q[dubious ].[17]

Performance comparisons

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

Results

Storage requirements
Method Storage
Rotation matrix 9
Quaternion 3 or 4 (see below)
Angle–axis 3 or 4 (see below)

Only three of the quaternion components are independent, as a rotation is represented by a unit quaternion. For further calculation one usually needs all four elements, so all calculations would suffer additional expense from recovering the fourth component. Likewise, angle–axis can be stored in a three-component vector by multiplying the unit direction by the angle (or a function thereof), but this comes at additional computational cost when using it for calculations.

Performance comparison of rotation chaining operations
Method # multiplies # add/subtracts total operations
Rotation matrices 27 18 45
Quaternions 16 12 28
Performance comparison of vector rotating operations[18][19]
Method # multiplies # add/subtracts # sin/cos total operations
Rotation matrix 9 6 0 15
Quaternions * Without intermediate matrix 15 15 0 30
With intermediate matrix 21 18 0 39
Angle–axis Without intermediate matrix 18 13 2 30 + 3
With intermediate matrix 21 16 2 37 + 2

* Quaternions can be implicitly converted to a rotation-like matrix (12 multiplications and 12 additions/subtractions), which levels the following vectors rotating cost with the rotation matrix method.

Used methods

There are three basic approaches to rotating a vector v:

  1. Compute the matrix product of a 3 × 3 rotation matrix R and the original 3 × 1 column matrix representing v. This requires 3 × (3 multiplications + 2 additions) = 9 multiplications and 6 additions, the most efficient method for rotating a vector.
  2. A rotation can be represented by a unit-length quaternion q = (w, r) with scalar (real) part w and vector (imaginary) part r. The rotation can be applied to a 3D vector v via the formula  . This requires only 15 multiplications and 15 additions to evaluate (or 18 multiplications and 12 additions if the factor of 2 is done via multiplication.) This formula, originally thought to be used with axis/angle notation (Rodrigues' formula), can also be applied to quaternion notation. This yields the same result as the less efficient but more compact formula of quaternion multiplication  .
  3. Use the angle/axis formula to convert an angle/axis to a rotation matrix R then multiplying with a vector, or, similarly, use a formula to convert quaternion notation to a rotation matrix, then multiplying with a vector. Converting the angle/axis to R costs 12 multiplications, 2 function calls (sin, cos), and 10 additions/subtractions; from item 1, rotating using R adds an additional 9 multiplications and 6 additions for a total of 21 multiplications, 16 add/subtractions, and 2 function calls (sin, cos). Converting a quaternion to R costs 12 multiplications and 12 additions/subtractions; from item 1, rotating using R adds an additional 9 multiplications and 6 additions for a total of 21 multiplications and 18 additions/subtractions.
Performance comparison of n vector rotating operations
Method # multiplies # add/subtracts # sin/cos total operations
Rotation matrix 9n 6n 0 15n
Quaternions * Without intermediate matrix 15n 15n 0 30n
With intermediate matrix 9n + 12 6n + 12 0 15n + 24
Angle–axis Without intermediate matrix 18n 12n + 1 2 30n + 3
With intermediate matrix 9n + 12 6n + 10 2 15n + 24

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 assuming that it is a quaternion, we can rotate the vector v like this:

 

The pair of matrices represents a rotation of ℝ4. Note that since  , the two matrices must commute. Therefore, there are two commuting subgroups of the group of four dimensional rotations. Arbitrary four-dimensional rotations have 6 degrees of freedom; each matrix represents 3 of those 6 degrees of freedom.

Since the generators of the four-dimensional rotations can be represented by pairs of quaternions (as follows), all four-dimensional rotations can also be represented.

quaternions, spatial, rotation, unit, quaternions, known, versors, provide, convenient, mathematical, notation, representing, spatial, orientations, rotations, elements, three, dimensional, space, specifically, they, encode, information, about, axis, angle, ro. Unit quaternions known as versors provide a convenient mathematical notation for representing spatial orientations and rotations of elements in three dimensional space Specifically they encode information about an axis angle rotation about an arbitrary axis Rotation and orientation quaternions have applications in computer graphics 1 computer vision robotics 2 navigation molecular dynamics flight dynamics 3 orbital mechanics of satellites 4 and crystallographic texture analysis 5 When used to represent rotation unit quaternions are also called rotation quaternions as they represent the 3D rotation group When used to represent an orientation rotation relative to a reference coordinate system they are called orientation quaternions or attitude quaternions A spatial rotation around a fixed point of 8 displaystyle theta radians about a unit axis X Y Z displaystyle X Y Z that denotes the Euler axis is given by the quaternion C X S Y S Z S displaystyle C X S Y S Z S where C cos 8 2 displaystyle C cos theta 2 and S sin 8 2 displaystyle S sin theta 2 Compared to rotation matrices quaternions are more compact efficient and numerically stable Compared to Euler angles they are simpler to compose However they are not as intuitive and easy to understand and due to the periodic nature of sine and cosine rotation angles differing precisely by the natural period will be encoded into identical quaternions and recovered angles in radians will be limited to 0 2 p displaystyle 0 2 pi Contents 1 Using quaternions as rotations 1 1 Example conjugation operation 1 2 Quaternion derived rotation matrix 1 3 Recovering the axis angle representation 1 4 The composition of spatial rotations 1 4 1 Axis angle composition 1 5 Differentiation with respect to the rotation quaternion 2 Background 2 1 Quaternions 2 2 Rotation identity 3 Quaternion rotation operations 3 1 The hypersphere of rotations 3 1 1 Visualizing the space of rotations 3 1 2 Parameterizing the space of rotations 4 Explaining quaternions properties with rotations 4 1 Non commutativity 4 2 Orientation 5 Alternative conventions 5 1 Software applications by convention used 6 Comparison with other representations of rotations 6 1 Advantages of quaternions 6 2 Conversion to and from the matrix representation 6 2 1 From a quaternion to an orthogonal matrix 6 2 2 From an orthogonal matrix to a quaternion 6 2 3 Fitting quaternions 6 3 Performance comparisons 6 3 1 Results 6 3 2 Used methods 7 Pairs of unit quaternions as rotations in 4D space 8 See also 9 References 10 Further reading 11 External links and resourcesUsing quaternions as rotations EditThis section needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed January 2022 Learn how and when to remove this template message 3D visualization of a sphere and a rotation about an Euler axis e displaystyle hat e by an angle of 8 displaystyle theta In 3 dimensional space according to Euler s rotation theorem any rotation or sequence of rotations of a rigid body or coordinate system about a fixed point is equivalent to a single rotation by a given angle 8 displaystyle theta about a fixed axis called the Euler axis that runs through the fixed point The Euler axis is typically represented by a unit vector u displaystyle vec u e displaystyle hat e in the picture Therefore any rotation in three dimensions can be represented as a combination of a vector u displaystyle vec u and a scalar 8 displaystyle theta Quaternions give a simple way to encode this axis angle representation in four numbers and can be used to apply calculate the corresponding rotation to a position vector x y z representing a point relative to the origin in R3 Euclidean vectors such as 2 3 4 or ax ay az can be rewritten as 2 i 3 j 4 k or ax i ay j az k where i j k are unit vectors representing the three Cartesian axes traditionally x y z and also obey the multiplication rules of the fundamental quaternion units Therefore a rotation of angle 8 displaystyle theta around the axis defined by the unit vector u u x u y u z u x i u y j u z k displaystyle vec u u x u y u z u x mathbf i u y mathbf j u z mathbf k can be represented by a quaternion This can be done using an extension of Euler s formula q e 8 2 u x i u y j u z k cos 8 2 u x i u y j u z k sin 8 2 displaystyle mathbf q e frac theta 2 u x mathbf i u y mathbf j u z mathbf k cos frac theta 2 u x mathbf i u y mathbf j u z mathbf k sin frac theta 2 It can be shown further explanation needed that the desired rotation can be applied to an ordinary vector p p x p y p z p x i p y j p z k displaystyle mathbf p p x p y p z p x mathbf i p y mathbf j p z mathbf k in 3 dimensional space considered as a quaternion with a real coordinate equal to zero by evaluating the conjugation of p by q p q p q 1 displaystyle mathbf p mathbf q mathbf p mathbf q 1 using the Hamilton product where p px py pz is the new position vector of the point after the rotation In a programmatic implementation the conjugation is achieved by constructing a quaternion whose vector part is p and real part equals zero and then performing the quaternion multiplication The vector part of the resulting quaternion is the desired vector p A geometric fact independent of quaternions is the existence of a two to one mapping from physical rotations to rotational transformation matrices If 0 8 displaystyle theta 2 p displaystyle 2 pi a physical rotation about u displaystyle vec u by 8 displaystyle theta and a physical rotation about u displaystyle vec u by 2 p 8 displaystyle 2 pi theta both achieve the same final orientation by disjoint paths through intermediate orientations By inserting those vectors and angles into the formula for q above one finds that if q represents the first rotation q represents the second rotation This is a geometric proof that conjugation by q and by q must produce the same rotational transformation matrix That fact is confirmed algebraically by noting that the conjugation is quadratic in q so the sign of q cancels and does not affect the result See 2 1 mapping of SU 2 to SO 3 If both rotations are a half turn 8 p displaystyle theta pi both q and q will have a real coordinate equal to zero Otherwise one will have a positive real part representing a rotation by an angle less than p displaystyle pi and the other will have a negative real part representing a rotation by an angle greater than p displaystyle pi Mathematically this operation carries the set of all pure quaternions p those with real part equal to zero which constitute a 3 dimensional space among the quaternions into itself by the desired rotation about the axis u by the angle 8 Each real quaternion is carried into itself by this operation But for the purpose of rotations in 3 dimensional space we ignore the real quaternions The rotation is clockwise if our line of sight points in the same direction as u displaystyle vec u In this instance q is a unit quaternion and q 1 e 8 2 u x i u y j u z k cos 8 2 u x i u y j u z k sin 8 2 displaystyle mathbf q 1 e frac theta 2 u x mathbf i u y mathbf j u z mathbf k cos frac theta 2 u x mathbf i u y mathbf j u z mathbf k sin frac theta 2 It follows that conjugation by the product of two quaternions is the composition of conjugations by these quaternions If p and q are unit quaternions then rotation conjugation by pq is p q v p q 1 p q v q 1 p 1 p q v q 1 p 1 displaystyle mathbf pq vec v mathbf pq 1 mathbf pq vec v mathbf q 1 mathbf p 1 mathbf p mathbf q vec v mathbf q 1 mathbf p 1 which is the same as rotating conjugating by q and then by p The scalar component of the result is necessarily zero The quaternion inverse of a rotation is the opposite rotation since q 1 q v q 1 q v displaystyle mathbf q 1 mathbf q vec v mathbf q 1 mathbf q vec v The square of a quaternion rotation is a rotation by twice the angle around the same axis More generally qn 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 Two rotation quaternions can be combined into one equivalent quaternion by the relation q q 2 q 1 displaystyle mathbf q mathbf q 2 mathbf q 1 in which q corresponds to the rotation q1 followed by the rotation q2 Thus an arbitrary number of rotations can be composed together and then applied as a single rotation Note that quaternion multiplication is not commutative Example conjugation operation Edit A rotation of 120 around the first diagonal permutes i j and k cyclically Conjugating p by q refers to the operation p qpq 1 Consider the rotation f around the axis v i j k displaystyle vec v mathbf i mathbf j mathbf k with a rotation angle of 120 or 2p 3 radians a 2 p 3 displaystyle alpha frac 2 pi 3 p q p for q 1 i j k 2 on the unit 3 sphere Note this one sided namely left multiplication yields a 60 rotation of quaternions The length of v displaystyle vec v is 3 the half angle is p 3 60 with cosine 1 2 cos 60 0 5 and sine 3 2 sin 60 0 866 We are therefore dealing with a conjugation by the unit quaternion u cos a 2 sin a 2 1 v v cos p 3 sin p 3 1 3 v 1 2 3 2 1 3 v 1 2 3 2 i j k 3 1 i j k 2 displaystyle begin aligned u amp cos frac alpha 2 sin frac alpha 2 cdot frac 1 vec v vec v amp cos frac pi 3 sin frac pi 3 cdot frac 1 sqrt 3 vec v amp frac 1 2 frac sqrt 3 2 cdot frac 1 sqrt 3 vec v amp frac 1 2 frac sqrt 3 2 cdot frac mathbf i mathbf j mathbf k sqrt 3 amp frac 1 mathbf i mathbf j mathbf k 2 end aligned If f is the rotation function f a i b j c k u a i b j c k u 1 displaystyle f a mathbf i b mathbf j c mathbf k u a mathbf i b mathbf j c mathbf k u 1 It can be proven that the inverse of a unit quaternion is obtained simply by changing the sign of its imaginary components As a consequence u 1 1 i j k 2 displaystyle u 1 dfrac 1 mathbf i mathbf j mathbf k 2 and f a i b j c k 1 i j k 2 a i b j c k 1 i j k 2 displaystyle f a mathbf i b mathbf j c mathbf k dfrac 1 mathbf i mathbf j mathbf k 2 a mathbf i b mathbf j c mathbf k dfrac 1 mathbf i mathbf j mathbf k 2 This can be simplified using the ordinary rules for quaternion arithmetic to f a i b j c k c i a j b k displaystyle f a mathbf i b mathbf j c mathbf k c mathbf i a mathbf j b mathbf k 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 derived rotation matrix Edit A quaternion rotation p q p q 1 displaystyle mathbf p mathbf q mathbf p mathbf q 1 with q q r q i i q j j q k k displaystyle mathbf q q r q i mathbf i q j mathbf j q k mathbf k can be algebraically manipulated into a matrix rotation p R p displaystyle mathbf p mathbf Rp where R displaystyle mathbf R is the rotation matrix given by 6 R 1 2 s q j 2 q k 2 2 s q i q j q k q r 2 s q i q k q j q r 2 s q i q j q k q r 1 2 s q i 2 q k 2 2 s q j q k q i q r 2 s q i q k q j q r 2 s q j q k q i q r 1 2 s q i 2 q j 2 displaystyle mathbf R begin bmatrix 1 2s q j 2 q k 2 amp 2s q i q j q k q r amp 2s q i q k q j q r 2s q i q j q k q r amp 1 2s q i 2 q k 2 amp 2s q j q k q i q r 2s q i q k q j q r amp 2s q j q k q i q r amp 1 2s q i 2 q j 2 end bmatrix Here s q 2 displaystyle s q 2 and if q is a unit quaternion s 1 2 1 displaystyle s 1 2 1 This can be obtained by using vector calculus and linear algebra if we express p displaystyle mathbf p and q displaystyle mathbf q as scalar and vector parts and use the formula for the multiplication operation in the equation p q p q 1 displaystyle mathbf p mathbf q mathbf p mathbf q 1 If we write p displaystyle mathbf p as 0 p displaystyle left 0 mathbf p right p displaystyle mathbf p as 0 p displaystyle left 0 mathbf p right and q displaystyle mathbf q as q r v displaystyle left q r mathbf v right where v q i q j q k displaystyle mathbf v left q i q j q k right our equation turns into 0 p q r v 0 p s q r v displaystyle left 0 mathbf p right left q r mathbf v right left 0 mathbf p right s left q r mathbf v right By using the formula for multiplication of two quaternions that are expressed as scalar and vector parts r 1 v 1 r 2 v 2 r 1 r 2 v 1 v 2 r 1 v 2 r 2 v 1 v 1 v 2 displaystyle left r 1 vec v 1 right left r 2 vec v 2 right left r 1 r 2 vec v 1 cdot vec v 2 r 1 vec v 2 r 2 vec v 1 vec v 1 times vec v 2 right this equation can be rewritten as 0 p q r v 0 p s q r v q r 0 v p q r p 0 v v p s q r v s v p q r p v p q r v s v p q r q r p v p v v p v q r q r p v p q r p v p v s v p q r q r v p v v p q r 2 p q r v p v q r p v p 0 s v v q r 2 I 2 q r v v 2 p displaystyle begin aligned 0 mathbf p amp q r mathbf v 0 mathbf p s q r mathbf v amp q r 0 mathbf v cdot mathbf p q r mathbf p 0 mathbf v mathbf v times mathbf p s q r mathbf v amp s mathbf v cdot mathbf p q r mathbf p mathbf v times mathbf p q r mathbf v amp s mathbf v cdot mathbf p q r q r mathbf p mathbf v times mathbf p cdot mathbf v mathbf v cdot mathbf p mathbf v q r q r mathbf p mathbf v times mathbf p q r mathbf p mathbf v times mathbf p times mathbf v amp s left mathbf v cdot mathbf p q r q r mathbf v cdot mathbf p mathbf v left mathbf v cdot mathbf p right q r 2 mathbf p q r mathbf v times mathbf p mathbf v times left q r mathbf p mathbf v times mathbf p right right amp left 0 s left mathbf v otimes mathbf v q r 2 mathbf I 2q r mathbf v times mathbf v times 2 right mathbf p right end aligned where displaystyle otimes denotes the outer product I displaystyle mathbf I is the identity matrix and v displaystyle mathbf v times is the transformation matrix that when multiplied from the right with a vector u displaystyle mathbf u gives the cross product v u displaystyle mathbf v times mathbf u Since p R p displaystyle mathbf p mathbf R mathbf p we can identify R displaystyle mathbf R as s v v q r 2 I 2 q r v v 2 displaystyle s left mathbf v otimes mathbf v q r 2 mathbf I 2q r mathbf v times mathbf v times 2 right which upon expansion should result in the expression written in matrix form above Recovering the axis angle representation Edit The expression q p q 1 displaystyle mathbf q mathbf p mathbf q 1 rotates any vector quaternion p displaystyle mathbf p around an axis given by the vector a displaystyle mathbf a by the angle 8 displaystyle theta where a displaystyle mathbf a and 8 displaystyle theta depends on the quaternion q q r q i i q j j q k k displaystyle mathbf q q r q i mathbf i q j mathbf j q k mathbf k a displaystyle mathbf a and 8 displaystyle theta can be found from the following equations a x a y a z q i q j q k q i 2 q j 2 q k 2 8 2 atan2 q i 2 q j 2 q k 2 q r displaystyle begin aligned a x a y a z amp frac q i q j q k sqrt q i 2 q j 2 q k 2 2pt theta 2 operatorname atan2 amp left sqrt q i 2 q j 2 q k 2 q r right end aligned where atan2 displaystyle operatorname atan2 is the two argument arctangent Care should be taken when the quaternion approaches a scalar since due to degeneracy the axis of an identity rotation is not well defined The composition of spatial rotations Edit A benefit of the quaternion formulation of the composition of two rotations RB and RA is that it yields directly the rotation axis and angle of the composite rotation RC RBRA Let the quaternion associated with a spatial rotation R be constructed from its rotation axis S with the rotation angle f displaystyle varphi around this axis The associated quaternion is given byS cos f 2 S sin f 2 displaystyle S cos frac varphi 2 mathbf S sin frac varphi 2 Then the composition of the rotation RB with RA is the rotation RC RBRA with rotation axis and angle defined by the product of the quaternions A cos a 2 A sin a 2 and B cos b 2 B sin b 2 displaystyle A cos frac alpha 2 mathbf A sin frac alpha 2 quad text and quad B cos frac beta 2 mathbf B sin frac beta 2 that is C cos g 2 C sin g 2 cos b 2 B sin b 2 cos a 2 A sin a 2 displaystyle C cos frac gamma 2 mathbf C sin frac gamma 2 left cos frac beta 2 mathbf B sin frac beta 2 right left cos frac alpha 2 mathbf A sin frac alpha 2 right Expand this product to obtaincos g 2 C sin g 2 cos b 2 cos a 2 B A sin b 2 sin a 2 B sin b 2 cos a 2 A sin a 2 cos b 2 B A sin b 2 sin a 2 displaystyle cos frac gamma 2 mathbf C sin frac gamma 2 left cos frac beta 2 cos frac alpha 2 mathbf B cdot mathbf A sin frac beta 2 sin frac alpha 2 right left mathbf B sin frac beta 2 cos frac alpha 2 mathbf A sin frac alpha 2 cos frac beta 2 mathbf B times mathbf A sin frac beta 2 sin frac alpha 2 right Divide both sides of this equation by the identity which is the law of cosines on a sphere cos g 2 cos b 2 cos a 2 B A sin b 2 sin a 2 displaystyle cos frac gamma 2 cos frac beta 2 cos frac alpha 2 mathbf B cdot mathbf A sin frac beta 2 sin frac alpha 2 and compute C tan g 2 B tan b 2 A tan a 2 B A tan b 2 tan a 2 1 B A tan b 2 tan a 2 displaystyle mathbf C tan frac gamma 2 frac mathbf B tan frac beta 2 mathbf A tan frac alpha 2 mathbf B times mathbf A tan frac beta 2 tan frac alpha 2 1 mathbf B cdot mathbf A tan frac beta 2 tan frac alpha 2 This is Rodrigues formula for the axis of a composite rotation defined in terms of the axes of the two rotations He derived this formula in 1840 see page 408 7 The three rotation axes A B and C form a spherical triangle and the dihedral angles between the planes formed by the sides of this triangle are defined by the rotation angles Hamilton 8 presented the component form of these equations showing that the quaternion product computes the third vertex of a spherical triangle from two given vertices and their associated arc lengths which is also defines an algebra for points in Elliptic geometry Axis angle composition Edit The normalized rotation axis removing the cos g 2 textstyle cos frac gamma 2 from the expanded product leaves the vector which is the rotation axis times some constant Care should be taken normalizing the axis vector when g displaystyle gamma is 0 displaystyle 0 or k 2 p displaystyle k2 pi where the vector is near 0 displaystyle 0 which is identity or 0 rotation around any axis g 2 cos 1 cos b 2 cos a 2 B A sin b 2 sin a 2 D B sin b 2 cos a 2 A sin a 2 cos b 2 B A sin b 2 sin a 2 displaystyle begin aligned gamma amp 2 cos 1 left cos frac beta 2 cos frac alpha 2 mathbf B cdot mathbf A sin frac beta 2 sin frac alpha 2 right mathbf D amp mathbf B sin frac beta 2 cos frac alpha 2 mathbf A sin frac alpha 2 cos frac beta 2 mathbf B times mathbf A sin frac beta 2 sin frac alpha 2 end aligned Or with angle addition trigonometric substitutions g 2 cos 1 1 A B cos b a 2 1 A B cos b a 2 D sin b a 2 sin b a 2 A sin b a 2 sin b a 2 B cos b a 2 cos b a 2 B A displaystyle begin aligned gamma amp 2 cos 1 left left 1 mathbf A cdot mathbf B right cos frac beta alpha 2 left 1 mathbf A cdot mathbf B right cos frac beta alpha 2 right mathbf D amp left sin frac beta alpha 2 sin frac beta alpha 2 right mathbf A left sin frac beta alpha 2 sin frac beta alpha 2 right mathbf B left cos frac beta alpha 2 cos frac beta alpha 2 right mathbf B times mathbf A end aligned finally normalizing the rotation axis D 2 sin 1 2 g textstyle frac mathbf D 2 sin frac 1 2 gamma or D D textstyle frac mathbf D mathbf D Differentiation with respect to the rotation quaternion Edit The rotated quaternion p q p q 1 needs to be differentiated with respect to the rotating quaternion q when the rotation is estimated from numerical optimization The estimation of rotation angle is an essential procedure in 3D object registration or camera calibration For unitary q and pure imaginary p that is for a rotation in 3D space the derivatives of the rotated quaternion can be represented using matrix calculus notation as p q p q 0 p q x p q y p q z p q p q p q i p q i p q j p q j p q k p q k displaystyle begin aligned frac partial mathbf p partial mathbf q equiv left frac partial mathbf p partial q 0 frac partial mathbf p partial q x frac partial mathbf p partial q y frac partial mathbf p partial q z right left mathbf pq mathbf pq mathbf pqi mathbf pqi mathbf pqj mathbf pqj mathbf pqk mathbf pqk right end aligned A derivation can be found in 9 Background EditQuaternions Edit Main article Quaternions 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 b i c d i a c a d i b i c b i d i a c a d i b c i b d i 2 a c b d b c a d i displaystyle a b mathbf i c d mathbf i ac ad mathbf i b mathbf i c b mathbf i d mathbf i ac ad mathbf i bc mathbf i bd mathbf 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 i j k 1 and the usual algebraic rules except the commutative law of multiplication a familiar example of such a noncommutative multiplication is matrix multiplication From this all of the rules of quaternion arithmetic follow such as the rules on multiplication of quaternion basis elements Using these rules one can show that a b i c j d k e f i g j h k a e b f c g d h a f b e c h d g i a g b h c e d f j a h b g c f d e k displaystyle begin aligned amp a b mathbf i c mathbf j d mathbf k e f mathbf i g mathbf j h mathbf k amp ae bf cg dh af be ch dg mathbf i ag bh ce df mathbf j ah bg cf de mathbf k end aligned The imaginary part b i c j d k displaystyle b mathbf i c mathbf j d mathbf k of a quaternion behaves like a vector v b c d displaystyle vec v b c d in three dimensional vector space and the real part a behaves like a scalar in R When quaternions are used in geometry it is more convenient to define them as a scalar plus a vector a b i c j d k a v displaystyle a b mathbf i c mathbf j d mathbf k a vec v Some might find it strange to add a number to a vector as they are objects of very different natures or to multiply two vectors together as this operation is usually undefined However if one remembers that it is a mere notation for the real and imaginary parts of a quaternion it becomes more legitimate In other words the correct reasoning is the addition of two quaternions one with zero vector imaginary part and another one with zero scalar real part q 1 s v s 0 0 v displaystyle q 1 s vec v left s vec 0 right left 0 vec v right We can express quaternion multiplication in the modern language of vector cross and dot products which were actually inspired by the quaternions in the first place 10 When multiplying the vector imaginary parts in place of the rules i2 j2 k2 ijk 1 we have the quaternion multiplication rule v w v w v w displaystyle vec v vec w vec v cdot vec w vec v times vec w where v w displaystyle vec v vec w is the resulting quaternion v w displaystyle vec v times vec w is vector cross product a vector v w displaystyle vec v cdot vec w is vector scalar product a scalar Quaternion multiplication is noncommutative because of the cross product which anti commutes while scalar scalar and scalar vector multiplications commute From these rules it follows immediately that see details q 1 q 2 s v t w s t v w s w t v v w displaystyle q 1 q 2 left s vec v right left t vec w right left st vec v cdot vec w right left s vec w t vec v vec v times vec w right The left and right multiplicative inverse or reciprocal of a nonzero quaternion is given by the conjugate to norm ratio see details q 1 1 s v 1 s v s v 2 s v s 2 v 2 displaystyle q 1 1 left s vec v right 1 frac left s vec v right lVert s vec v rVert 2 frac s vec v s 2 lVert vec v rVert 2 as can be verified by direct calculation note the similarity to the multiplicative inverse of complex numbers Rotation identity Edit Main article Rodrigues rotation formula Let u displaystyle vec u be a unit vector the rotation axis and let q cos a 2 u sin a 2 displaystyle q cos frac alpha 2 vec u sin frac alpha 2 Our goal is to show that v q v q 1 cos a 2 u sin a 2 v cos a 2 u sin a 2 displaystyle vec v q vec v q 1 left cos frac alpha 2 vec u sin frac alpha 2 right vec v left cos frac alpha 2 vec u sin frac alpha 2 right yields the vector v displaystyle vec v rotated by an angle a displaystyle alpha around the axis u displaystyle vec u Expanding out and bearing in mind that u v u v u v displaystyle vec u vec v vec u times vec v vec u cdot vec v we have v v cos 2 a 2 u v v u sin a 2 cos a 2 u v u sin 2 a 2 v cos 2 a 2 2 u v sin a 2 cos a 2 u v u v u sin 2 a 2 v cos 2 a 2 2 u v sin a 2 cos a 2 u v u u v u sin 2 a 2 v cos 2 a 2 2 u v sin a 2 cos a 2 u v u u v u u v u sin 2 a 2 v cos 2 a 2 2 u v sin a 2 cos a 2 v u v u 0 u v u sin 2 a 2 v cos 2 a 2 2 u v sin a 2 cos a 2 v 2 u u v sin 2 a 2 v cos 2 a 2 2 u v sin a 2 cos a 2 v sin 2 a 2 2 u u v sin 2 a 2 v cos 2 a 2 sin 2 a 2 u v 2 sin a 2 cos a 2 u u v 2 sin 2 a 2 displaystyle begin aligned vec v amp vec v cos 2 frac alpha 2 left vec u vec v vec v vec u right sin frac alpha 2 cos frac alpha 2 vec u vec v vec u sin 2 frac alpha 2 6pt amp vec v cos 2 frac alpha 2 2 left vec u times vec v right sin frac alpha 2 cos frac alpha 2 left left vec u times vec v right left vec u cdot vec v right right vec u sin 2 frac alpha 2 6pt amp vec v cos 2 frac alpha 2 2 left vec u times vec v right sin frac alpha 2 cos frac alpha 2 left left vec u times vec v right vec u left vec u cdot vec v right vec u right sin 2 frac alpha 2 6pt amp vec v cos 2 frac alpha 2 2 left vec u times vec v right sin frac alpha 2 cos frac alpha 2 left left left vec u times vec v right times vec u left vec u times vec v right cdot vec u right left vec u cdot vec v right vec u right sin 2 frac alpha 2 6pt amp vec v cos 2 frac alpha 2 2 left vec u times vec v right sin frac alpha 2 cos frac alpha 2 left left vec v left vec u cdot vec v right vec u right 0 left vec u cdot vec v right vec u right sin 2 frac alpha 2 6pt amp vec v cos 2 frac alpha 2 2 left vec u times vec v right sin frac alpha 2 cos frac alpha 2 left vec v 2 vec u left vec u cdot vec v right right sin 2 frac alpha 2 6pt amp vec v cos 2 frac alpha 2 2 left vec u times vec v right sin frac alpha 2 cos frac alpha 2 vec v sin 2 frac alpha 2 2 vec u left vec u cdot vec v right sin 2 frac alpha 2 6pt amp vec v left cos 2 frac alpha 2 sin 2 frac alpha 2 right left vec u times vec v right left 2 sin frac alpha 2 cos frac alpha 2 right vec u left vec u cdot vec v right left 2 sin 2 frac alpha 2 right 6pt end aligned Using trigonometric identities v v cos 2 a 2 sin 2 a 2 u v 2 sin a 2 cos a 2 u u v 2 sin 2 a 2 v cos a u v sin a u u v 1 cos a v cos a u v sin a u u v u u v cos a v u u v cos a u v sin a u u v v cos a u v sin a v displaystyle begin aligned vec v amp vec v left cos 2 frac alpha 2 sin 2 frac alpha 2 right left vec u times vec v right left 2 sin frac alpha 2 cos frac alpha 2 right vec u left vec u cdot vec v right left 2 sin 2 frac alpha 2 right 6pt amp vec v cos alpha left vec u times vec v right sin alpha vec u left vec u cdot vec v right left 1 cos alpha right 6pt amp vec v cos alpha left vec u times vec v right sin alpha vec u left vec u cdot vec v right vec u left vec u cdot vec v right cos alpha 6pt amp left vec v vec u left vec u cdot vec v right right cos alpha left vec u times vec v right sin alpha vec u left vec u cdot vec v right 6pt amp vec v bot cos alpha left vec u times vec v right sin alpha vec v end aligned where v displaystyle vec v bot and v displaystyle vec v are the components of v perpendicular and parallel to u respectively This is the formula of a rotation by a displaystyle alpha around the u axis Quaternion rotation operations EditA very formal explanation of the properties used in this section is given by Altman 11 The hypersphere of rotations Edit Main article Rotation group SO 3 Visualizing the space of rotations Edit Unit quaternions represent the group of Euclidean rotations in three dimensions in a very straightforward way The correspondence between rotations and quaternions can be understood by first visualizing the space of rotations itself Two separate rotations differing by both angle and axis in the space of rotations Here the length of each axis vector is relative to the respective magnitude of the rotation about that axis In order to visualize the space of rotations it helps to consider a simpler case Any rotation in three dimensions can be described by a rotation by some angle about some axis for our purposes we will use an axis vector to establish handedness for our angle Consider the special case in which the axis of rotation lies in the xy plane We can then specify the axis of one of these rotations by a point on a circle through which the vector crosses and we can select the radius of the circle to denote the angle of rotation Similarly a rotation whose axis of rotation lies in the xy plane can be described as a point on a sphere of fixed radius in three dimensions Beginning at the north pole of a sphere in three dimensional space we specify the point at the north pole to be the identity rotation a zero angle rotation Just as in the case of the identity rotation no axis of rotation is defined and the angle of rotation zero is irrelevant A rotation having a very small rotation angle can be specified by a slice through the sphere parallel to the xy plane and very near the north pole The circle defined by this slice will be very small corresponding to the small angle of the rotation As the rotation angles become larger the slice moves in the negative z direction and the circles become larger until the equator of the sphere is reached which will correspond to a rotation angle of 180 degrees Continuing southward the radii of the circles now become smaller corresponding to the absolute value of the angle of the rotation considered as a negative number Finally as the south pole is reached the circles shrink once more to the identity rotation which is also specified as the point at the south pole Notice that a number of characteristics of such rotations and their representations can be seen by this visualization The space of rotations is continuous each rotation has a neighborhood of rotations which are nearly the same and this neighborhood becomes flat as the neighborhood shrinks Also each rotation is actually represented by two antipodal points on the sphere which are at opposite ends of a line through the center of the sphere This reflects the fact that each rotation can be represented as a rotation about some axis or equivalently as a negative rotation about an axis pointing in the opposite direction a so called double cover The latitude of a circle representing a particular rotation angle will be half of the angle represented by that rotation since as the point is moved from the north to south pole the latitude ranges from zero to 180 degrees while the angle of rotation ranges from 0 to 360 degrees the longitude of a point then represents a particular axis of rotation Note however that this set of rotations is not closed under composition Two successive rotations with axes in the xy plane will not necessarily give a rotation whose axis lies in the xy plane and thus cannot be represented as a point on the sphere This will not be the case with a general rotation in 3 space in which rotations do form a closed set under composition The sphere of rotations for the rotations that have a horizontal axis in the xy plane This visualization can be extended to a general rotation in 3 dimensional space The identity rotation is a point and a small angle of rotation about some axis can be represented as a point on a sphere with a small radius As the angle of rotation grows the sphere grows until the angle of rotation reaches 180 degrees at which point the sphere begins to shrink becoming a point as the angle approaches 360 degrees or zero degrees from the negative direction This set of expanding and contracting spheres represents a hypersphere in four dimensional space a 3 sphere Just as in the simpler example above each rotation represented as a point on the hypersphere is matched by its antipodal point on that hypersphere The latitude on the hypersphere will be half of the corresponding angle of rotation and the neighborhood of any point will become flatter i e be represented by a 3 D Euclidean space of points as the neighborhood shrinks This behavior is matched by the set of unit quaternions A general quaternion represents a point in a four dimensional space but constraining it to have unit magnitude yields a three dimensional space equivalent to the surface of a hypersphere The magnitude of the unit quaternion will be unity corresponding to a hypersphere of unit radius The vector part of a unit quaternion represents the radius of the 2 sphere corresponding to the axis of rotation and its magnitude is the cosine of half the angle of rotation Each rotation is represented by two unit quaternions of opposite sign and as in the space of rotations in three dimensions the quaternion product of two unit quaternions will yield a unit quaternion Also the space of unit quaternions is flat in any infinitesimal neighborhood of a given unit quaternion Parameterizing the space of rotations Edit 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 At the poles latitudes 90 and 90 the longitude becomes meaningless It can be shown that no two parameter coordinate system can avoid such degeneracy We can avoid such problems by embedding the sphere in three dimensional space and parameterizing it with three Cartesian coordinates 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 x2 y2 1 Points on the sphere satisfy the constraint w2 x2 y2 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 in the ordinary space around the horizontal axis directed by the vector x y 0 by an angle a 2 cos 1 w 2 sin 1 x 2 y 2 displaystyle 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 w2 x2 y2 z2 1 The point w x y z represents a rotation around the axis directed by the vector x y z by an angle a 2 cos 1 w 2 sin 1 x 2 y 2 z 2 displaystyle alpha 2 cos 1 w 2 sin 1 sqrt x 2 y 2 z 2 Explaining quaternions properties with rotations EditNon commutativity Edit The multiplication of quaternions is non commutative This fact explains how the p q p q 1 formula can work at all having q q 1 1 by definition Since the multiplication of unit quaternions corresponds to the composition of three dimensional rotations this property can be made intuitive by showing that three dimensional rotations are not commutative in general Set two books next to each other Rotate one of them 90 degrees clockwise around the z axis then flip it 180 degrees around the x axis Take the other book flip it 180 around x axis first and 90 clockwise around z later The two books do not end up parallel This shows that in general the composition of two different rotations around two distinct spatial axes will not commute Orientation Edit The vector cross product used to define the axis angle representation does confer an orientation handedness to space in a three dimensional vector space the three vectors in the equation a b c will always form a right handed set or a left handed set depending on how the cross product is defined thus fixing an orientation in the vector space Alternatively the dependence on orientation is expressed in referring to such u displaystyle vec u that specifies a rotation as to axial vectors In quaternionic formalism the choice of an orientation of the space corresponds to order of multiplication ij k but ji k If one reverses the orientation then the formula above becomes p q 1 p q i e a unit q is replaced with the conjugate quaternion the same behaviour as of axial vectors Alternative conventions EditIt is reported 12 that the existence and continued usage of an alternative quaternion convention in the aerospace and to a lesser extent robotics community is incurring a significant and ongoing cost sic This alternative convention is proposed by Shuster M D in 13 and departs from tradition by reversing the definition for multiplying quaternion basis elements such that under Shuster s convention i j k displaystyle mathbf i mathbf j mathbf k whereas Hamilton s definition is i j k displaystyle mathbf i mathbf j mathbf k This convention is also referred to as JPL convention for its use in some parts of NASA s Jet Propulsion Laboratory Under Shuster s convention the formula for multiplying two quaternions is altered such that r 1 v 1 r 2 v 2 r 1 r 2 v 1 v 2 r 1 v 2 r 2 v 1 v 1 v 2 Alternative convention usage discouraged displaystyle left r 1 vec v 1 right left r 2 vec v 2 right left r 1 r 2 vec v 1 cdot vec v 2 r 1 vec v 2 r 2 vec v 1 mathbin color red mathbf vec v 1 times vec v 2 right qquad text Alternative convention usage discouraged The formula for rotating a vector by a quaternion is altered to be p alt v v q r 2 I 2 q r v v 2 p Alternative convention usage discouraged I 2 q r v 2 v 2 p displaystyle begin aligned mathbf p text alt amp mathbf v otimes mathbf v q r 2 mathbf I mathbin color red mathbf 2q r mathbf v times mathbf v times 2 mathbf p amp text Alternative convention usage discouraged amp mathbf I mathbin color red mathbf 2q r mathbf v times 2 mathbf v times 2 mathbf p amp end aligned To identify the changes under Shuster s convention see that the sign before the cross product is flipped from plus to minus Finally the formula for converting a quaternion to a rotation matrix is altered to be R a l t I 2 q r v 2 v 2 Alternative convention usage discouraged 1 2 s q j 2 q k 2 2 q i q j q k q r 2 q i q k q j q r 2 q i q j q k q r 1 2 s q i 2 q k 2 2 q j q k q i q r 2 q i q k q j q r 2 q j q k q i q r 1 2 s q i 2 q j 2 displaystyle begin aligned mathbf R alt amp mathbf I mathbin color red mathbf 2q r mathbf v times 2 mathbf v times 2 qquad text Alternative convention usage discouraged amp begin bmatrix 1 2s q j 2 q k 2 amp 2 q i q j q k q r amp 2 q i q k q j q r 2 q i q j q k q r amp 1 2s q i 2 q k 2 amp 2 q j q k q i q r 2 q i q k q j q r amp 2 q j q k q i q r amp 1 2s q i 2 q j 2 end bmatrix end aligned which is exactly the transpose of the rotation matrix converted under the traditional convention Software applications by convention used Edit The table below groups applications by their adherence to either quaternion convention 12 Hamilton multiplication convention Shuster multiplication conventionWolfram MathematicaMATLAB Robotics System ToolboxMATLAB Aerospace Toolbox 15 ROSEigenBoost quaternionsQuaternion jsCeres SolverSciPy spatial transform Rotation librarySymPy symbolic mathematics librarynumpy quaternion library Microsoft DirectX Math LibraryWhile use of either convention does not impact the capability or correctness of applications thus created the authors of 12 argued that the Shuster convention should be abandoned because it departs from the much older quaternion multiplication convention by Hamilton and may never be adopted by the mathematical or theoretical physics areas Comparison with other representations of rotations EditAdvantages of quaternions Edit 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 video 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 is slightly off still represents a rotation after being normalized a matrix that is slightly off may not be orthogonal any more and 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 Conversion to and from the matrix representation Edit From a quaternion to an orthogonal matrix Edit The orthogonal matrix corresponding to a rotation by the unit quaternion z a b i c j d k with z 1 when post multiplying with a column vector is given by R a 2 b 2 c 2 d 2 2 b c 2 a d 2 b d 2 a c 2 b c 2 a d a 2 b 2 c 2 d 2 2 c d 2 a b 2 b d 2 a c 2 c d 2 a b a 2 b 2 c 2 d 2 displaystyle R begin pmatrix a 2 b 2 c 2 d 2 amp 2bc 2ad amp 2bd 2ac 2bc 2ad amp a 2 b 2 c 2 d 2 amp 2cd 2ab 2bd 2ac amp 2cd 2ab amp a 2 b 2 c 2 d 2 end pmatrix This rotation matrix is used on vector w as w rotated R w displaystyle w text rotated R cdot w The quaternion representation of this rotation is given by 0 w rotated z 0 w z displaystyle begin bmatrix 0 w text rotated end bmatrix z begin bmatrix 0 w end bmatrix z where z displaystyle z is the conjugate of the quaternion z displaystyle z given by z a b i c j d k displaystyle mathbf z a b mathbf i c mathbf j d mathbf k Also quaternion multiplication is defined as assuming a and b are quaternions like z above a b a 0 b 0 a b a 0 b b 0 a a b displaystyle ab left a 0 b 0 vec a cdot vec b a 0 vec b b 0 vec a vec a times vec b right where the order a b is important since the cross product of two vectors is not commutative A more efficient calculation in which the quaternion does not need to be unit normalized is given by 16 R 1 c c d d b c a d b d a c b c a d 1 b b d d c d a b b d a c c d a b 1 b b c c displaystyle R begin pmatrix 1 cc dd amp bc ad amp bd ac bc ad amp 1 bb dd amp cd ab bd ac amp cd ab amp 1 bb cc end pmatrix where the following intermediate quantities have been defined s 2 a a b b c c d d b s b s c s c s d s d s a b a b s a c a c s a d a d s b b b b s b c b c s b d b d s c c c c s c d c d s d d d d s displaystyle begin alignedat 2 amp s 2 a cdot a b cdot b c cdot c d cdot d amp begin array lll bs b cdot s amp cs c cdot s amp ds d cdot s ab a cdot bs amp ac a cdot cs amp ad a cdot ds bb b cdot bs amp bc b cdot cs amp bd b cdot ds cc c cdot cs amp cd c cdot ds amp dd d cdot ds end array end alignedat From an orthogonal matrix to a quaternion Edit One must be careful when converting a rotation matrix to a quaternion as several straightforward methods tend to be unstable when the trace sum of the diagonal elements of the rotation matrix is zero or very small For a stable method of converting an orthogonal matrix to a quaternion see the Rotation matrix Quaternion Fitting quaternions Edit The above section described how to recover a quaternion q from a 3 3 rotation matrix Q Suppose however that we have some matrix Q that is not a pure rotation due to round off errors for example and we wish to find the quaternion q that most accurately represents Q In that case we construct a symmetric 4 4 matrix K 1 3 Q x x Q y y Q z z Q y x Q x y Q z x Q x z Q z y Q y z Q y x Q x y Q y y Q x x Q z z Q z y Q y z Q x z Q z x Q z x Q x z Q z y Q y z Q z z Q x x Q y y Q y x Q x y Q z y Q y z Q x z Q z x Q y x Q x y Q x x Q y y Q z z displaystyle K frac 1 3 begin bmatrix Q xx Q yy Q zz amp Q yx Q xy amp Q zx Q xz amp Q zy Q yz Q yx Q xy amp Q yy Q xx Q zz amp Q zy Q yz amp Q xz Q zx Q zx Q xz amp Q zy Q yz amp Q zz Q xx Q yy amp Q yx Q xy Q zy Q yz amp Q xz Q zx amp Q yx Q xy amp Q xx Q yy Q zz end bmatrix and find the eigenvector x y z w corresponding to the largest eigenvalue that value will be 1 if and only if Q is a pure rotation The quaternion so obtained will correspond to the rotation closest to the original matrix Q dubious discuss 17 Performance comparisons Edit This section discusses the performance implications of using quaternions versus other methods axis angle or rotation matrices to perform rotations in 3D Results Edit Storage requirements Method StorageRotation matrix 9Quaternion 3 or 4 see below Angle axis 3 or 4 see below Only three of the quaternion components are independent as a rotation is represented by a unit quaternion For further calculation one usually needs all four elements so all calculations would suffer additional expense from recovering the fourth component Likewise angle axis can be stored in a three component vector by multiplying the unit direction by the angle or a function thereof but this comes at additional computational cost when using it for calculations Performance comparison of rotation chaining operations Method multiplies add subtracts total operationsRotation matrices 27 18 45Quaternions 16 12 28Performance comparison of vector rotating operations 18 19 Method multiplies add subtracts sin cos total operationsRotation matrix 9 6 0 15Quaternions Without intermediate matrix 15 15 0 30With intermediate matrix 21 18 0 39Angle axis Without intermediate matrix 18 13 2 30 3With intermediate matrix 21 16 2 37 2 Quaternions can be implicitly converted to a rotation like matrix 12 multiplications and 12 additions subtractions which levels the following vectors rotating cost with the rotation matrix method Used methods Edit There are three basic approaches to rotating a vector v Compute the matrix product of a 3 3 rotation matrix R and the original 3 1 column matrix representing v This requires 3 3 multiplications 2 additions 9 multiplications and 6 additions the most efficient method for rotating a vector A rotation can be represented by a unit length quaternion q w r with scalar real part w and vector imaginary part r The rotation can be applied to a 3D vector v via the formula v new v 2 r r v w v displaystyle vec v text new vec v 2 vec r times vec r times vec v w vec v This requires only 15 multiplications and 15 additions to evaluate or 18 multiplications and 12 additions if the factor of 2 is done via multiplication This formula originally thought to be used with axis angle notation Rodrigues formula can also be applied to quaternion notation This yields the same result as the less efficient but more compact formula of quaternion multiplication v new q v q 1 displaystyle vec v text new q vec v q 1 Use the angle axis formula to convert an angle axis to a rotation matrix R then multiplying with a vector or similarly use a formula to convert quaternion notation to a rotation matrix then multiplying with a vector Converting the angle axis to R costs 12 multiplications 2 function calls sin cos and 10 additions subtractions from item 1 rotating using R adds an additional 9 multiplications and 6 additions for a total of 21 multiplications 16 add subtractions and 2 function calls sin cos Converting a quaternion to R costs 12 multiplications and 12 additions subtractions from item 1 rotating using R adds an additional 9 multiplications and 6 additions for a total of 21 multiplications and 18 additions subtractions Performance comparison of n vector rotating operations Method multiplies add subtracts sin cos total operationsRotation matrix 9n 6n 0 15nQuaternions Without intermediate matrix 15n 15n 0 30nWith intermediate matrix 9n 12 6n 12 0 15n 24Angle axis Without intermediate matrix 18n 12n 1 2 30n 3With intermediate matrix 9n 12 6n 10 2 15n 24Pairs of unit quaternions as rotations in 4D space EditA pair of unit quaternions zl and zr can represent any rotation in 4D space Given a four dimensional vector v and assuming that it is a quaternion we can rotate the vector v like this f v z l v z r 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 l w x y z 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 r displaystyle f left vec v right mathbf z rm l vec v mathbf z rm r begin pmatrix a rm l amp b rm l amp c rm l amp d rm l b rm l amp a rm l amp d rm l amp c rm l c rm l amp d rm l amp a rm l amp b rm l d rm l amp c rm l amp b rm l amp a rm l end pmatrix begin pmatrix w x y z end pmatrix begin pmatrix a rm r amp b rm r amp c rm r amp d rm r b rm r amp a rm r amp d rm r amp c rm r c rm r amp d rm r amp a rm r amp b rm r d rm r amp c rm r amp b rm r amp a rm r end pmatrix The pair of matrices represents a rotation of ℝ4 Note that since z l v z r z l v z r displaystyle mathbf z rm l vec v mathbf z rm r mathbf z rm l vec v mathbf z rm r the two matrices must commute Therefore there are two commuting subgroups of the group of four dimensional rotations Arbitrary four dimensional rotations have 6 degrees of freedom each matrix represents 3 of those 6 degrees of freedom Since the generators of the four dimensional rotations can be represented by pairs of quaternions as follows all four dimensional rotations can also be represented z l v z r 1 d t a b d t a c d t a d d t a b 1 d t b c d t b d d t a c d t b c 1 d t c d d t a d d t b d d t c d 1 w x y z z l 1 d t a b d t c d 2 i d t a c d t b d 2 j d t a d d t b c 2 k z r 1 d t a b d t c d 2 i d t a c d t b d 2 j d t a d d t b c 2, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.