# Quaternion differentiation

I wanted to point someone to a short explanation of this today and noticed, with some surprise, that I couldn’t find something concise within 5 minutes of googling. So it seems worth writing up. I’m assuming you know what quaternions are and what they’re used for.

First, though, it seems important to point one thing out: Actually, there’s nothing special at all about either integration or differentiation of quaternion-valued functions. If you have a quaternion-valued function of one variable q(t), then

same as for any real- or complex-valued function.

So what, then, is this post about? Simple: unit quaternions are commonly used to represent rotations (or orientation of rigid bodies), and rigid-body dynamics require integration of orientation over time. Almost all sources I could find just magically pull a solution out of thin air, and those that give a derivation tend to make it way more complicated than necessary. So let’s just do this from first principles. I’m assuming you know that multiplying two unit quaternions quaternions q_{1}q_{0} gives a unit quaternion representing the composition of the two rotations. Now say we want to describe the orientation q(t) of a rigid body rotating at constant angular velocity. Then we can write

where describes the rotation the body undergoes in one time step. Since we have constant angular velocity, we will have , and more generally for all nonnegative integer k by induction. So for even more general t we’d expect something like

.

Now, q_{ω} is a unit quaternion, which means it can be written in *polar form*

where θ is some angle and n is a unit vector denoting the axis of rotation. That part is usually mentioned in every quaternion tutorial. Embedding real 3-vectors as the corresponding pure imaginary quaternion, i.e. writing just for the quaternion , is usually also mentioned somewhere. What usually isn’t mentioned is the crucial piece of information that the polar form of a quaternion, in fact, just the quaternion version of Euler’s formula: Any unit complex number can be written as the complex exponential of a pure imaginary number , and similarly any unit-length quaternion (and q_{ω} in particular) can be written as the exponential of a pure imaginary quaternion

which gives us a natural definition for

.

Now, what if we want to write a differential equation for the behavior of q(t) over time? Just compute the derivative of q(t) as you would for any other function of t. Using the chain and product rules we get:

The vector θ**n** is in fact just the angular velocity ω, which yields the oft-cited but seldom-derived equation:

This is usually quoted completely without context. In particular, it’s not usually mentioned that q(t) describes the orientation of a body with constant angular velocity, and similar for the crucial link to the exponential function.

Hi,

It was with great satisfaction I found your deduction of the quarternion time derivate. I’ve been searching for this myself, but until now in vain.

However, I don’t understand when you say: “The vector θn is in fact just the angular velocity ω,..”

The angular velocity ω have the units radians/s, but the quantity θn have the unit radians as n is dimensionless.

Or have I missed something…

Regards,

Göran

In my derivation, t is just a real number; I’m not bothering with units throughout the post, which is what muddles things a bit.

If you want to patch it up and use dimensional quantities, you need to do it throughout:

The initial definition q(t) = q_omega^t * q_0 doesn’t work as-is; you need a fudge factor k [1/s] so you can use a power function here (we need to nail down after what amount of time we’ve turned by “one omega”). So you get

q(t) = q_omega^(k*t) * q_0

and for the differential equation, that gives us

q’(t) = k*(theta/2)*n * exp(k*t*(theta/2)*n) * q_0 = k*(theta/2)*n * q(t) = 1/2 * omega * q(t)

where omega = k*theta*n. k is still [1/s], theta is [rad] and n is a dimensionless vector.

Hope that helps. Sorry for the confusion.

Hello! When checking the derivation of partial derivatives of a function of a quaternion for another mathematician at work, I found a fairly obscure flaw, this is not mentioned in your article above. Since the complex part is a unit vector, the obvious differentiation does not work, because it effectivily wiggles the individual parts without considering that wiggling one part would change all the other parts to keep the sum 1. Mathematically speaking, the individuial terms are not independent. To get the right result you must differentiate the imaginary parts of quaternion divided by the length of the unit vector i.e. R + Im/sqrt(x^2 + y^2 + z^2), this breaks the dependency between the terms.

I’m not sure what you mean. The imaginary part of the quaternions involved is *not* a unit vector.

A unit quaternion is one such that conj(q)*q = R^2 + x^2 + y^2 + z^2 (in your notation) = 1. I don’t see why you would normalize just the imaginary part of a quaternion, or what it’s intended to accomplish.

I’m simply talking about the quaternion-valued function q(t) = q_omega^t * q_0 here, which has the derivative (by time!) given above. Furthermore, for unit quaternions (which represent rotations), we have |q(t)| = |q_omega^t| * |q_0| = |q_omega|^t * |q_0| = 1^t * 1 = 1; so if q_omega and q_0 are both unit quaternions, the same will hold for any quaternion returned by q(t), without ever enforcing that constraint explicitly.

“Wiggling the individual parts” doesn’t make sense in this context; both q_omega and q_0 are constants, and while I’m looking at a quaternion-valued function, it’s a function of one real variable, t, which is the one I’m differentiating by. I don’t get to “wiggle” my quaternions off the curve described by q(t), which as I’ve described above is entirely made up of unit quaternions.