# Quaternion derivative w.r.t. its angle

The following quaternion represents a rotation by $\theta$ around the z-axis:

\begin{align} q &= (\cos(\frac{1}{2}\theta), \vec{u}\cdot\sin(\frac{1}{2}\theta)), \\ \vec{u}&=(0,0,1)^t \end{align} I'd like to take the derivative of this quaternion with respect to its angle $\theta$. In this paper I've read that first the exponential map representation of the quaternion has to be built: that would be \begin{align} q &= e^\vec{w} , \\\vec{w}&=(w_1,w_2,w_3)^t=(0,0,\frac{1}{2}\theta)^t \end{align} Then I have to derive q with respect to $w_1,w_2$ and $w_3$ as follows: \begin{align} \frac{\partial q}{\partial \vec{w}}&=(\frac{\partial q}{\partial w_1},\frac{\partial q}{\partial w_2},\frac{\partial q}{\partial w_3}) \end{align} In my example, for every partial derivation I get a quaternion, which is respectively: which are 3 quaternions. Could this be wrong? I'm wondering because $w_1=w_2=0$. Does anybody have an idea how to deal with this?

Later I'm aiming to compute a jacobian matrix (I've already computed it) with these derivatives, and as $\theta$ is in the denominator, in the jacobian matrix there has to be $\theta\neq0$, which is senseless because $\theta$ has to include the posibility to be $0$.

Could anyone help me with this? Thanks!

• The one thing I didn't cover in my answer below: when you got those three quats, that's $dq/dw$, but to compute $dq/d\theta$, you need $dq/d\theta = (dq/dw) (dw/d\theta)$, i.e, you need to multiply that row vector of three quats by the column vector $(0,0,1/2)^t$; that'll get you the same result I got below. Feb 21, 2014 at 18:44

A quaternion is just a point in $4$-space. You've got a function from, say, $[0, 2\pi]$ to $4$-space defined by

$$\gamma: \theta \mapsto (\cos(\theta/2), 0, 0, \sin(\theta/2)).$$

The derivative of that function is $$\gamma': \theta \mapsto \frac{1}{2}(-\sin(\theta/2), 0, 0, \cos(\theta/2)).$$

Since $\gamma(\theta)$ is a unit quaternion for all $\theta$, its derivative should be a tangent vector to the unit sphere at $\gamma(\theta)$, i.e., the dot product (not quaternion product!) of $\gamma(\theta)$ and $\gamma'(\theta)$ should be zero...and in fact it is.

It's possible that what you want is the body-centered derivative, which is just $\gamma(\theta)^{-1}\gamma'(\theta)$, where the "-1" denotes quaternion inverse, and the multiplication here is quaternion multiplication; that'll get you a unit quaternion in the tangent space to $(1,0,0,0)$, which consists of all pure-vector quaternions...but maybe that's not what you want. If it is, it happens to be easy to compute in this case.

I'm going to just write $\gamma$ for $\gamma(\theta)$ from now on, and "c" and "s" for the cosine and sine of $\theta/2$, OK?

Because $\gamma$ is a unit quaternion, its inverse is its conjugate, so $$\gamma^{-1} = \bar{\gamma} = (c, 0, 0, -s).$$ That makes the body-centered derivative be $$\gamma^{-1} \gamma' = (c, 0, 0, -s) \star (-s, 0, 0, c),$$ where I've used $\star$ to denote quaternion multiplication. The result is \begin{align} \gamma^{-1} \gamma' &= (c, 0, 0, -s) \star \frac{1}{2}(-s, 0, 0, c)\\ &= \frac{1}{2}(-sc + sc; c(0,0,c) -s (0,0,-s) - (0,0,c) \times (0,0,-s)) \\ &= \frac{1}{2}(0; (0,0,c^2 + s^2) \\ &= \frac{1}{2}(0, 0,0,1). \end{align} In other words, your body-centered derivative is, at all times, $\frac{1}{2} {\mathbf k}$.

• Thanks! I'm not sure what you mean with "body centered derivative". Are you saying that $(\frac{\partial q}{\partial w_1},\frac{\partial q}{\partial w_2},\frac{\partial q}{\partial w_3})$ are all the same, namely $\frac{1}{2}(-\sin(\theta/2), 0, 0, \cos(\theta/2))$? I don't understand it, as $w_1,w_2,w_3$ are not all the same. Feb 21, 2014 at 19:56
• As you drive your car, there are two kinds of instructions I can give. One is "turn north"; another is "turn left". The second is "body centered" -- it's a description relative to a frame of reference you carry with you (x points to the front of the car; y points out the driver's door; z points up). The first is "world-centered" -- it's specified with respect to a frame of ref where x points east, y points north, and z points to the sky. I don't think I can explain more in the length of a "comment". As for $dq/dw_1$, etc., see my comment on your original question: you forgot the chain rule. :) Feb 21, 2014 at 20:16
• Please would it be possible for you to write $(\frac{\partial q}{\partial w_1},\frac{\partial q}{\partial w_2},\frac{\partial q}{\partial w_3})$ explicitly? I'm very confused as I've been trying to understand quaternion algebra for several weeks without getting any explicite results. What would be $\frac{\partial q}{\partial w_1}$, as $w_1=0$? Does it exist? Is it $\frac{\partial q}{\partial w_1}=(0,0,0,0)$? Or what would be $\frac{\partial q}{\partial w_3}$? Feb 22, 2014 at 11:17
• Assuming you mean $\partial q/ \partial w_1$ at $w_1 = 0$, that's not a meaningful question: $q$ is a function of 3 variables, and you have to give me values for all 3. At a point $(w_1, w_2, w_3)$ where $w_1 = 0$ and at least one of $w_2$ and $w_3$ is nonzero, your theorem tells you the answer: it's $(\mathbf i - 0)\frac{sin(\|w\|)}{\|w\|} +0 \cdot \text{stuff} = \mathbf i \frac{sin(\|w\|)}{\|w\|}$. Feb 25, 2014 at 21:28

I just came across a paper by T.Barfoot, J.R. Forbes and P.T.Fugale that deals with derivatives of rotation matrices with respect to their angles. Take a look at equation (16)

$$\frac{\partial C(a, \phi)}{\partial \phi}=-a^x C(a, \phi)$$

Note this is useful if you wish to use the rotation matrix instead of the quaternion.