I'm using quaternions as a means to rotate an object in the application I'm developing. If one quaternion represents a rotation and the second quaternion represents another rotation, what does their multiplication represent? Many web sites talk about formulas and matrices, but I want to know what exactly are we doing multiplication for?

  • 4
    $\begingroup$ The product $z_1z_2$ corresponds geometrically to doing rotation attatched to $z_2$ and then rotation attatched to $z_1$. Be careful about ordering though since quaternion multiplication is noncommutative. $\endgroup$ – fretty Apr 13 '13 at 11:12

The multiplication of quaternions represents composing the two rotations: perform one rotation and then perform the other one. It's clear that this should represent a rotation (imagine rotating, say, a bowling ball in place). What's not necessarily immediately clear — and this is what in some sense 'motivates' the quaternion representation of a rotation — is the fact that that every rotation in three dimensions can be written as a rotation by some amount about a single axis: for instance, the combination of a rotation by $\frac\pi4$ about the $x$-axis followed by a rotation by $\frac\pi3$ about the axis $(1,1,1)$ can still be written as a single rotation about some axis.

As pointed out in the comments, composition of rotations isn't necessarily commutative (and thus the multiplication of quaternions can't be); for instance, imagine labeling the six faces of a cube $\pm X, \pm Y, \pm Z$ according to which way they're facing, and then looking at the $+X$ face with the $+Y$ axis to your right and the $+Z$ axis up. Now, perform two (clockwise, $90^\circ$) rotations: one about the $+Z$ axis and one about the $+Y$ axis. Doing the rotation about $Z$ first will bring the $+Y$ face of the cube to face you, with the $+Z$ face still up; then rotating about $Y$ will bring the $-Z$ face of the cube facing you, with $+Y$ on top. By contrast, if you rotate about the $+Y$ face first then $-Z$ will be facing you, with $+X$ up and $+Y$ to the right; then rotating about the $+Z$ axis will have $+Y$ facing you with $+X$ up.

Also, you need to be a little careful about 'mixing metaphors' with your representations: quaternions represent rotations and multiplication of quaternions represents composition of those represented rotations, but — for instance — if $q$ is some rotation and $v$ is a vector, then multiplying $qv$ (representing $v$ via the 'fully imaginary' quaternion $v_x{\bf i}+v_y{\bf j}+v_z{\bf k}$) does not represent the rotation of that vector according to the given rotation (it's hard to see how it could, since generally such a multiplication would have a non-zero real component); instead, the result of rotating by the specified quaternion is calculated by $v_{\rm{rot}} = q^{-1}vq$ (and it can be shown that this value is also purely imaginary, so it can be converted 'back' to a three-vector consistently).

  • $\begingroup$ Your quaternion multiplication for applying rotation is opposite from the standard convention: should be v' = qvq' Not a big deal, as this would merely mean rotation in the opposite direction. $\endgroup$ – Codesmith Nov 13 '16 at 2:01

Multiplication of quaternions works pretty much the same way the multiplication of rotation (or transformation) matrices works. So multiplication of two quaternions combines the rotations, just as multiplying matrices does (e.g. in OpenGL glRotate() function).

A nice thing is that multiplication of two normalized quaternions again produces a normalized quaternion.

Quaternion inversion (or just conjugate for the normalized case) creates the inverse rotation (the same rotation in the opposite direction). This is arguably easier to compute (on current computers) than to calculate inverse of a rotation matrix (just have to negate w in quaternion, instead of transposing a rotation matrix).

  • $\begingroup$ There’s nothing to calculate to find the inverse of a rotation matrix. Rotation matrices can simply be transposed to get their inverse. $\endgroup$ – johnbakers Jun 9 '19 at 9:57
  • $\begingroup$ @johnbakers As the answer already states, rotation matrix needs to be transposed to get the inverse. contrary to what you're thinking, 3x3 matrix transpose will be about 6 or 9 moves to swap the off-diagonal elements. If you use SIMD, those would be shuffles. Compare that to a single scalar negation that is easy to execute even if the quaternion sits in a SIMD register. $\endgroup$ – the swine Jun 11 '19 at 1:40
  • $\begingroup$ Sorry I missed that part in your comment. Though this is the first I've seen that merely negating one of the four elements of the quaternion (w) gives the inverse; the calculation of the conjugate or inverse seems to be slightly more involved formula on the various wikis I've looked at. You are saying that just negate the w is the same effect? That would make sense if the elements of the quaternion directly corresponded to the axis and its angle, in which case negating the w would be the inverse, but in quaternions the elements don't directly map that way. $\endgroup$ – johnbakers Jun 12 '19 at 8:43
  • $\begingroup$ @johnbakers In fact, they do; the quaternion representation of a rotation of $\theta$ degrees about the axis $\mathbf{v}$ (represented as a unit-length purely imaginary quaternion) is $\cos(\theta/2)+\sin(\theta/2)\mathbf{v}$. This implies that the rotation of $-\theta$ about that axis - the inverse - is $\cos(\theta/2)-\sin(\theta/2)\mathbf{v}$, i.e. the conjugate; in terms of computer representation this is negating the x/y/z components of the quaternion. But since $\mathbf{q}$ and $-\mathbf{q}$ represent the same rotation, rather than negating x, y, and z we can just negate w. $\endgroup$ – Steven Stadnicki Jul 27 '19 at 16:46
  • $\begingroup$ @theswine can you explain why multiplying 2 normalized quaternions produces a normalized quaternion? I know is true but is there any mathematical proof that can convince me? $\endgroup$ – off99555 Nov 12 '20 at 8:07

Consider the quaternions as a four-dimensional real algebra $\mathbb{H}$, where elements have the form $a+bi+cj+dk$ subject to the muliplication rules $i^2=j^2=k^2=ijk=-1$. Further, consider the function $f:\mathbb{R}^3\to\mathbb{H}$ defined by


and the imaginary projection $\iota:\mathbb{H}\to\mathbb{R}^3$ given by


Then, the cross product of two vectors $x,y\in\mathbb{R}^3$ can be given by

$x\times y=\iota(f(x)f(y))$.

A similar procedure also works for the seven-dimensional cross product and the octonions, with the same sort of maps $f':\mathbb{R}^7\to\mathbb{O}$ and $\iota':\mathbb{O}\to\mathbb{R}^7$

But as was pointed out by fretty, one needs to be careful about commutativity in $\mathbb{H}$ (and associativity for that matter in the case of $\mathbb{O}$).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.