[Math] Quaternion derivative w.r.t. its angle

derivativesquaternions

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:
enter image description here
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$.

To provide more information, I've added the algorithm I'm working with:
enter image description here

Could anyone help me with this? Thanks!

Best Answer

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}$.