Exponential and Logarithm in SO(3), SE(3), Quaternion Space

Oct 14, 2023 | Tech Robotics

Motivation

$SO(3)$, $SE(3)$, and quaternion logarithm and exponential are mathematical operations that can facilitate the computation and representation of rigid body motion. Post Rigid Body Motion, Concepts and Terminologies discussed matrix exponential in $SO(3)$ and $SE(3)$. In addition to that,

  • $SO(3)$ matrix logarithm $\text{log}(R)$ allows one to get $(\hat{\omega}, \theta)$ from a given rotation matrix,
  • $SE(3)$ matrix logarithm $\text{log}(T)$ allows one to get $(\mathcal{S}, \theta)$ from a given homogeneous transformation,
  • unit quaternion logarithm $\text{log}(q) = \mathcal{Q} \in \mathbb{H}$ for $q \in \mathbb{H}_1$ allows one to get from a unit quaternion a pure quaternion $\mathcal{Q}$,
  • pure quaternion exponential $\text{exp}(\mathcal{Q})$ for $\mathcal{Q} = log(q) \in \mathbb{H}$ inverts the log function and recovers the original unit quaternion $q\in \mathbb{H}_1$,
    • a pure quaternion is defined as $\mathcal{Q} = \begin{bmatrix} 0, \mathbf{\omega} \end{bmatrix}$, where $\mathbf{\omega}\in \mathbb{R}^3$ and $||\mathbf{\omega}||$ not necessarily equals to unity.

This post summarizes formulas for computing $SO(3)$ and $SE(3)$ matrix logarithm, and unit quaternion logarithm and pure quaternion logarithm. For further details, please refer to 2017@Lynch , 1998@Dam , Wikipedia@Quat , and Wikipedia@QuatAndRot .

$SO(3)$ Matrix Logarithm, $\text{log}(R)$

As discussed in Orientation section of post Rigid Body Motion, Concepts and Terminologies, $[\hat{\omega}]\theta \in so(3) \rightleftharpoons e^{[\hat{\omega}] \theta} \in SO(3)$ are the matrix logarithm and exponential of each other. And the section provided the formula to compute $e^{[\hat{\omega}]\theta} \in SO(3)$ from $[\hat{\omega}]\theta$.

Another common application is to get $(\hat{\omega}, \theta)$ for a given $R\in SO(3)$, where $||\hat{\omega}||=1$ and $\theta \in [0, \pi]$. That is, given a rotation matrix, one wants to find a unit axis and an angle such that rotating about the unit axis by the angle will result in the given rotation matrix.

With that said, given $R\in SO(3)$, to get $(\hat{\omega}, \theta)$, there are 3 cases to consider.

  • The 0° rotation case: $R = I$, corresponding to $\theta = 0$.

$$ \hat{\omega} \rightarrow \text{undefined} \rightarrow \text{any unit vector} $$ $$ \theta = 0 $$

  • The common case: $R \neq I$, $\text{tr}R \neq -1$, corresponding to $\theta \in (0, \pi)$.

$$ \begin{align} \hat{\omega} &= \frac{R - R^T}{2 \, \text{sin}\theta} \\ \theta &= \text{arccos} \frac{\text{tr}R - 1}{2} \end{align} $$

  • The 180° rotation case: $R \neq I$, $\text{tr}R = -1$, corresponding to $\theta = \pi$.

$$ \hat{\omega} = \begin{cases} \pm \frac{1}{\sqrt{2(1+r_{33})}} \begin{bmatrix} r_{13}, & r_{23}, & 1 + r_{33} \end{bmatrix}^T \\ \pm \frac{1}{\sqrt{2(1+r_{22})}} \begin{bmatrix} r_{12}, & 1 + r_{22}, & r_{32} \end{bmatrix}^T \\ \pm \frac{1}{\sqrt{2(1+r_{11})}} \begin{bmatrix} 1 + r_{11}, & r_{21}, & r_{31} \end{bmatrix}^T \end{cases} \label{eq:180-axis} $$ $$ \theta = \pi $$

Note that in the 180° rotation case:

  • symbol $r_{ij}$ denotes the entry at the $i$-th row and $j$-th column in the rotation matrix $R$,
  • all of the 3 vectors in \eqref{eq:180-axis} are feasible solutions for $\hat{\omega}$,
  • in addition, rotating a rigid body about a unit axis $\hat{\omega}$ and its opposite $-\hat{\omega}$ by 180° will result in the same orientation, hence the $\pm$ in \eqref{eq:180-axis}, and renders a total of $6$ feasible solutions for the unit rotation axis in the 180° case.

It is then straightforward to compute $SO(3)$ matrix logarithm by $$R \rightarrow (\hat{\omega}, \theta) \rightarrow [\hat{\omega}]\theta = \log(R)$$

In short conclusion, the $SO(3)$ matrix logarithm and $so(3)$ matrix exponential are $$ \log(R) = [\hat{\omega}]\theta $$ $$ e^{[\hat{\omega}]\theta} = R $$

$SE(3)$ Matrix Logarithm, $\text{log}(T)$

Analogous to the application of $SO(3)$ matrix logarithm, another common application is to get $(\mathcal{S}, \theta)$, or equivalently $(\bar{\omega}, \bar{v}, \theta)$, for a given $T(R,p) \in SE(3)$, where there must be either $||\bar{\omega}|| = 1$ or $||\bar{v}|| = 1$, and $\theta \in [0, \pi]$.

For that, there are two cases to consider.

  • The zero rotation case: $R=I$, corresponding to a pure translation along the screw axis.

$$ \bar{\omega} = \mathbf{0} $$ $$ \bar{v} = \frac{p}{||p||} $$ $$ \theta = ||p|| $$

  • The composed motion case: $R \neq I$, corresponding to a rotation and a translation about the screw axis.

$$ \bar{\omega} \leftarrow \text{log}(R) $$ $$ \theta \leftarrow \text{log}(R) $$ $$ \bar{v} = G^{-1}(\bar{\omega}, \theta) \, p $$ where $$\theta \in (0,\pi] \nonumber $$ $$ G^{-1}(\bar{\omega}, \theta) = \frac{1}{\theta} - \frac{1}{2}[\bar{\omega}] + \Big( \frac{1}{\theta} - \frac{1}{2}\text{cot}\frac{\theta}{2} \Big) [\hat{\omega}]^2 $$ and $\text{log}(R)$ follows Section SO(3) Matrix Logarithm, $\text{log}(R)$.

Similarly, it is then straightforward to compute $SE(3)$ matrix logarithm by $$ T \rightarrow (\bar{\omega}, \bar{v}, \theta) \rightarrow [\mathcal{S}]\theta = \begin{bmatrix} \, [\bar{\omega}] & \bar{v} \, \\ \mathbf{0} & 0 \end{bmatrix} \theta = \text{log}(T) $$

In short conclusion, the $SE(3)$ matrix logarithm and $se(3)$ matrix exponential are $$ \log(T) = [\mathcal{S}]\theta $$ $$ e^{[\mathcal{S}]\theta} = T $$

Quaternion Logarithm and Exponential

Notations

A unit quaternion is defined to represent a spatial rotation, and is common denoted as $$ q = \begin{bmatrix} \text{cos}\frac{\theta}{2} & \hat{\omega} \, \text{sin}\frac{\theta}{2} \end{bmatrix} $$ or $$ q = e^{\frac{\theta}{2}(\mathbf{i}\,\hat{\omega}_x + \mathbf{j}\,\hat{\omega}_y + \mathbf{k}\,\hat{\omega}_z)} $$ where $||q|| = 1$ and $\theta \in [0, 2\pi]$. Note that rotations come in pairs, i.e., given a rotation, it can also be obtained by rotating in the opposite direction about the opposite axis. As a result, $q$ and $-q$ correspond to the same rotation.

A general quaternion (unit, pure, or generic) is also commonly denoted as follows. $$ q = \begin{bmatrix} q_0 & q_1 & q_2 & q_3 \end{bmatrix} = \begin{bmatrix} q_w & q_x & q_y & q_z \end{bmatrix} $$ or $$ q = w + x\mathbf{i} + y\mathbf{j} + z\mathbf{k} $$

Rotation Angle-Axis from Unit Quaternions

By the definition of unit quaternions, it is not difficult to extract the rotation angle and axis from a them. However, to include all possibilities, one should consider the following cases for $\theta \in [0, 2\pi]$.

  • When $q_0 = 1$, corresponds to $\theta = 0$,

$$\hat{\omega} \rightarrow \text{undefined} \rightarrow \text{any unit vector} \label{eq:q0-1-case-axis}$$ $$\theta = 0 \label{eq:q0-1-case-angle}$$

  • When $q_0 = -1$, corresponds to $\theta = 2\pi$,

$$\hat{\omega} \rightarrow \text{undefined} \rightarrow \text{any unit vector}$$ $$\theta = 2\pi$$

  • Otherwise, corresponds to $\theta \in (0, 2\pi)$, since $||q|| = 1$ for $q\in\mathbb{H}_1$,

$$ \hat{\omega} = \frac{\begin{bmatrix} q_1 & q_2 & q_3 \end{bmatrix}}{|| \begin{bmatrix} q_1 & q_2 & q_3 \end{bmatrix} ||} = \frac{\begin{bmatrix} q_1 & q_2 & q_3 \end{bmatrix}}{\sqrt{1 - q_0^2}} \label{eq:quat-axis} $$ $$\theta = 2\, \text{arccos}(q_0) \label{eq:quat-angle}$$

As mentioned earlier, since $q$ and $-q$ represent the same rotation by nature, \eqref{eq:q0-1-case-axis} and \eqref{eq:q0-1-case-angle} can be used to represent the rotation axis and angel for both the $q_0 = 1$ and $q_0 = -1$ cases.

Unit Quaternion Logarithm

Given a unit quaternion $ q = \begin{bmatrix} \text{cos}\frac{\theta}{2} & \hat{\omega} \, \text{sin}\frac{\theta}{2} \end{bmatrix} \in \mathbb{H}_1 $, its logarithm is defined as $$ \text{log}(q) \triangleq \begin{bmatrix} 0 & \frac{\theta}{2} \hat{\omega} \end{bmatrix} \in \mathbb{H} $$

For the special case $ q = \begin{bmatrix} 1 & \mathbf{0} \end{bmatrix} \in \mathbb{H}_1$, its logarithm is defined as $$ \text{log}(\begin{bmatrix} 1 & \mathbf{0} \end{bmatrix}) \triangleq \begin{bmatrix} 0 &\mathbf{0} \end{bmatrix} \in \mathbb{H} $$

Pure Quaternion Exponential

Logarithm and exponential are inverse of each other. Given the definition of unit quaternion logarithm, the definition of pure quaternion exponential follows naturally.

Given a pure quaternion $\mathcal{Q} = \begin{bmatrix} 0 & \frac{\theta}{2} \hat{\omega} \end{bmatrix} \in \mathbb{H}$, its exponential is defined as $$ \text{exp}(\mathcal{Q}) \triangleq \begin{bmatrix} \text{cos}\frac{\theta}{2} & \hat{\omega} \, \text{sin}\frac{\theta}{2} \end{bmatrix} \in \mathbb{H}_1 $$

For the special case $\mathcal{Q}=\begin{bmatrix} 0 & \mathbf{0} \end{bmatrix} \in \mathbb{H}$, its exponential is defined as $$ \text{exp}(\begin{bmatrix} 0 & \mathbf{0} \end{bmatrix}) \triangleq \begin{bmatrix} 1 & \mathbf{0} \end{bmatrix} \in \mathbb{H}_1 $$

Concluding Remarks

Practical Implementation

When evaluating matrix logarithms in $SO(3)$ and $SE(3)$, special cases arise when $R = I$ or $\text{tr}R = -1$. In practice, it is numerically more robust to evaluate $$ ||R - I|| < \epsilon $$$$||\text{tr}R + 1|| < \epsilon $$

The same goes for quaternion logarithm and exponential. To check for special cases $q = \begin{bmatrix} 1 & \mathbf{0} \end{bmatrix}$ and $\mathcal{Q} = \begin{bmatrix} 0 & \mathbf{0} \end{bmatrix}$, it is numerically more robust to evaluate $$ ||q_w - 1|| < \epsilon $$$$ \Big|\Big| \begin{bmatrix} q_x & q_y & q_z \end{bmatrix}\, \Big|\Big| < \epsilon $$

As well for extracting the rotation axis and angle from unit quaternions. To check for special cases $q_0 = 1$ or $q_0 = -1$ with better numerical stability, one should use $$\Big|\Big| |q_0| - 1 \Big|\Big| < \epsilon $$where $\epsilon \in R^+$ is a small number that represents a numerical threshold.

"Half-Angle" Correspondence

In addition, one should be aware of the "half-angle" correspondence between $SO(3)$ and $\mathbb{H}_1$ for encoding the angle and axis of a rotation, that is $$ (\hat{\omega}, \theta) \rightarrow R = Rot(\hat{\omega}, \theta) \in SO(3) $$ versus $$ (\hat{\omega}, \frac{\theta}{2}) \rightarrow q = \begin{bmatrix} \text{cos}\frac{\theta}{2} & \hat{\omega} \, \text{sin}\frac{\theta}{2} \end{bmatrix} \in \mathbb{H}_1 $$

More on Quaternion Logarithm and Exponential

Applications of unit quaternion logarithm and pure quaternion exponential can be found in 2020@Huber , further details will be discussed in a separate post.

A convenient 3D rotation converter between different representations can be found at Gaschler@2016 . A great visual illustration of unit quaternions can be found at Sanderson@Quat .