Algorithm Search⌘K

Definitioncore

Unit quaternion representation of rotation

Also called rotation quaternion, versor.

A rotation as a unit quaternion q = (cos(theta/2), sin(theta/2) times the axis), acting on a vector v by q v q*, where q and -q give the same rotation.

A unit quaternion is a list of four numbers q=(w,x,y,z)q = (w, x, y, z) with w2+x2+y2+z2=1w^2 + x^2 + y^2 + z^2 = 1, and it describes a rotation of 3D space. The rotation by the angle θ\theta about the unit axis ω^\hat\omega has the quaternion q=(cos⁡θ2,sin⁡θ2 ω^)q = (\cos\frac\theta2, \sin\frac\theta2\,\hat\omega), and it moves a vector vv to the vector part of the product q (0,v) q∗q\,(0, v)\,q^*, where q∗=(w,−x,−y,−z)q^* = (w, -x, -y, -z). The product of two quaternions gives the composition of the two rotations, and qq and −q-q give the same rotation. Quaternions are compact, have no singular orientation, and are easy to keep valid by normalization, so robotics, aerospace, computer graphics and CAD use them to store and combine orientations.

Notation on this page: quaternions are in the Hamilton convention with the scalar first, rotations are active (they move vectors), and [ω][\omega] is the skew-symmetric matrix of ω\omega, so that [ω]v=ω×v[\omega]v = \omega \times v.

Definition

The quaternions H\mathbb{H} are the numbers q=w+x i+y j+z kq = w + x\,i + y\,j + z\,k with real w,x,y,zw, x, y, z and the rules of Hamilton,

i2=j2=k2=ijk=−1,ij=k,jk=i,ki=j,ji=−k.i^2 = j^2 = k^2 = ijk = -1, \qquad ij = k, \quad jk = i, \quad ki = j, \quad ji = -k.

Write q=(w,u)q = (w, u) with the scalar part ww and the vector part u=(x,y,z)∈R3u = (x, y, z) \in \mathbb{R}^3. The product, the conjugate and the norm are

(a,u)(b,v)=(ab−u⋅v,  av+bu+u×v),q∗=(w,−u),∣q∣2=qq∗=w2+∣u∣2.(a, u)(b, v) = (ab - u \cdot v,\; a v + b u + u \times v), \qquad q^* = (w, -u), \qquad |q|^2 = q q^* = w^2 + |u|^2 .

The product is associative but not commutative, and ∣pq∣=∣p∣ ∣q∣|pq| = |p|\,|q|. A unit quaternion has ∣q∣=1|q| = 1; the unit quaternions form the sphere S3S^3 in R4\mathbb{R}^4, and for them q−1=q∗q^{-1} = q^*. A vector v∈R3v \in \mathbb{R}^3 is identified with the pure quaternion (0,v)(0, v).

Definition. The rotation of a unit quaternion qq is the map R(q):R3→R3R(q) : \mathbb{R}^3 \to \mathbb{R}^3 with

(0,R(q) v)=q (0,v) q∗.(0, R(q)\,v) = q\,(0, v)\,q^* .

A unit quaternion representation of a rotation R∈SO(3)R \in SO(3) is a unit quaternion qq with R(q)=RR(q) = R.

For q=(w,x,y,z)q = (w, x, y, z) the matrix is

R(q)=(1−2(y2+z2)2(xy−wz)2(xz+wy)2(xy+wz)1−2(x2+z2)2(yz−wx)2(xz−wy)2(yz+wx)1−2(x2+y2))=(w2−∣u∣2)I+2uuT+2w[u].R(q) = \begin{pmatrix} 1 - 2(y^2 + z^2) & 2(xy - wz) & 2(xz + wy) \\ 2(xy + wz) & 1 - 2(x^2 + z^2) & 2(yz - wx) \\ 2(xz - wy) & 2(yz + wx) & 1 - 2(x^2 + y^2) \end{pmatrix} = (w^2 - |u|^2) I + 2 u u^{\mathsf T} + 2w[u].

The basic facts are:

  • It is a rotation. R(q)R(q) keeps lengths, because ∣q(0,v)q∗∣=∣v∣|q (0, v) q^*| = |v|, and it has determinant 1, because S3S^3 is connected and R(1)=IR(1) = I. So R(q)R(q) is in the special orthogonal group SO(3).
  • Axis and angle. If q=(cos⁡θ2,sin⁡θ2 ω^)q = (\cos\frac\theta2, \sin\frac\theta2\,\hat\omega) with a unit ω^\hat\omega, the matrix above is I+sin⁡θ [ω^]+(1−cos⁡θ)[ω^]2I + \sin\theta\,[\hat\omega] + (1 - \cos\theta)[\hat\omega]^2, which is Rodrigues' formula. Every unit quaternion has this form with θ∈[0,2π]\theta \in [0, 2\pi], and by Euler's rotation theorem every rotation is reached.
  • Composition. R(pq)=R(p) R(q)R(pq) = R(p)\,R(q), because pq (0,v) (pq)∗=p (q (0,v) q∗) p∗pq\,(0, v)\,(pq)^* = p\,(q\,(0, v)\,q^*)\,p^*.
  • Double cover. R(p)=R(q)R(p) = R(q) if and only if p=±qp = \pm q. So q↦R(q)q \mapsto R(q) is a two-to-one map from S3S^3 onto SO(3), and the angles θ\theta and θ+2π\theta + 2\pi give qq and −q-q.
  • Inverse. R(q∗)=R(q)TR(q^*) = R(q)^{\mathsf T}, the inverse rotation.

The JPL convention, used in some estimation papers, writes the scalar last and takes ij=−kij = -k. Its quaternion of a given rotation equals the Hamilton quaternion with the vector part negated, and its products come in the reverse order. Convert at every interface, and never mix the two in one formula.

Examples and non-examples

  • A quarter turn about zz. θ=π/2\theta = \pi/2 and ω^=(0,0,1)\hat\omega = (0, 0, 1) give q=(cos⁡π4,0,0,sin⁡π4)=(0.70711,0,0,0.70711)q = (\cos\frac\pi4, 0, 0, \sin\frac\pi4) = (0.70711, 0, 0, 0.70711). The matrix formula gives R(q)=Rz(π/2)R(q) = R_z(\pi/2), which maps xx to yy.
  • A half turn about xx. q=(0,1,0,0)q = (0, 1, 0, 0), and R(q)=diag⁡(1,−1,−1)R(q) = \operatorname{diag}(1, -1, -1). Here w=0w = 0, so a formula that divides by ww fails; Shepperd's method handles this case.
  • Composition. With c=0.70711c = 0.70711, the quarter turns qz=(c,0,0,c)q_z = (c, 0, 0, c) about zz and qx=(c,c,0,0)q_x = (c, c, 0, 0) about xx give qzqx=(c2,  c(c,0,0)+c(0,0,c)+(0,0,c)×(c,0,0))=(0.5,0.5,0.5,0.5)q_z q_x = (c^2,\; c(c, 0, 0) + c(0, 0, c) + (0, 0, c) \times (c, 0, 0)) = (0.5, 0.5, 0.5, 0.5). This is θ=2π/3\theta = 2\pi/3 about (1,1,1)/3(1, 1, 1)/\sqrt3, so Rz(π/2)Rx(π/2)=(001100010)R_z(\pi/2) R_x(\pi/2) = \begin{pmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{pmatrix}, the map (x,y,z)↦(z,x,y)(x, y, z) \mapsto (z, x, y). The product in the other order, qxqz=(0.5,0.5,−0.5,0.5)q_x q_z = (0.5, 0.5, -0.5, 0.5), is a different rotation.
  • Acting on a vector. With q=(0.5,0.5,0.5,0.5)q = (0.5, 0.5, 0.5, 0.5) and v=(1,0,0)v = (1, 0, 0): q (0,v)=(−0.5,0.5,0.5,−0.5)q\,(0, v) = (-0.5, 0.5, 0.5, -0.5), and (−0.5,0.5,0.5,−0.5) q∗=(0,0,1,0)(-0.5, 0.5, 0.5, -0.5)\,q^* = (0, 0, 1, 0). So R(q)R(q) maps xx to yy, as the matrix says.
  • The sign. −q=(−0.5,−0.5,−0.5,−0.5)-q = (-0.5, -0.5, -0.5, -0.5) is the rotation by 2π/3+2π2\pi/3 + 2\pi about the same axis, which is the same rotation. A test that compares two quaternions must allow both signs.
  • Non-example: a quaternion that is not a unit. For q=(2,0,0,0)q = (2, 0, 0, 0), q (0,v) q∗=(0,4v)q\,(0, v)\,q^* = (0, 4v), a scaling by ∣q∣2=4|q|^2 = 4. After a numerical integration or many products, ∣q∣|q| drifts from 1, and the map is then a rotation times a scaling. Divide by ∣q∣|q| to return to S3S^3.
  • Non-example: the product without the conjugate. q (0,v) qq\,(0, v)\,q is not a rotation of vv in general; for q=(c,0,0,c)q = (c, 0, 0, c) and v=(0,0,1)v = (0, 0, 1) it gives (−1,0,0,0)(-1, 0, 0, 0), which is not even a pure quaternion. The conjugate on the right is essential.
  • Non-example: a pure quaternion as a rotation. (0,v)(0, v) with ∣v∣=1|v| = 1 is the rotation by π\pi about vv. It is not "the vector vv turned into a rotation" in any other sense.
  • Axis-angle representation. The pair (ω^,θ)(\hat\omega, \theta) that the quaternion encodes by the half angle. The vector θω^\theta\hat\omega is the result of the logarithm map of SO(3).
  • Euler-Rodrigues parameters. The four numbers (cos⁡θ2,sin⁡θ2 ω^)(\cos\frac\theta2, \sin\frac\theta2\,\hat\omega) under their older name, used for the composition of rotations before the quaternion notation.
  • Cayley parameters. The vector c=u/w=tan⁡θ2 ω^c = u/w = \tan\frac\theta2\,\hat\omega, the quaternion divided by its scalar part. It is singular at the half turn, where w=0w = 0.
  • Euler angles and roll-pitch-yaw angles. Three-angle charts of SO(3) with gimbal lock. Stuelpnagel's theorem shows that every three-parameter chart has a singular point, which is the reason for the fourth number of the quaternion.
  • Dual quaternion. Two quaternions that represent a rigid motion, a rotation and a translation together.
  • Algorithms. Shepperd's method converts a matrix to a quaternion, spherical linear interpolation interpolates two quaternions, and the quaternion kinematic equation moves a quaternion with an angular velocity.

References

  1. William Rowan Hamilton, On quaternions; or on a new system of imaginaries in algebra, Philosophical Magazine (third series) 25, 10-13, 1844, the first part of the series (the units i, j, k and their products)
  2. Kevin M. Lynch and Frank C. Park, Modern Robotics, Mechanics, Planning, and Control, Cambridge University Press, 2017, Appendix B, Section B.3 (unit quaternions, equations B.9 to B.12)
  3. Bruno Siciliano, Lorenzo Sciavicco, Luigi Villani and Giuseppe Oriolo, Robotics, Modelling, Planning and Control, Springer, 2009, Chapter 2, Section 2.6 (unit quaternion)
  4. Joan Sola, Quaternion kinematics for the error-state Kalman filter, 2017, Sections 1 and 2 (quaternion algebra and the rotation by a unit quaternion) and Section 3 (the Hamilton and JPL conventions)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/F08Y79/text.yaml