logarithm#

Quaternion.logarithm#

Logarithm of Quaternion.

The logarithm of a general quaternion \(\mathbf{q}=\begin{pmatrix}q_w & \mathbf{q_v}\end{pmatrix}\) is obtained from:

\[\begin{split}\log\mathbf{q} = \begin{bmatrix} \log\|\mathbf{q}\| \\ \mathbf{u}\theta \end{bmatrix}\end{split}\]

with:

\[\begin{split}\begin{array}{rcl} \mathbf{u} &=& \frac{\mathbf{q}_v}{\|\mathbf{q}_v\|} \\ \theta &=& \arccos\Big(\frac{q_w}{\|\mathbf{q}\|}\Big) \end{array}\end{split}\]

It is easy to see, that for a pure quaternion \(\mathbf{q}=\begin{pmatrix}0 & \mathbf{q_v}\end{pmatrix}\), the logarithm simplifies the computation through \(\theta=\arccos(0)=\frac{\pi}{2}\):

\[\begin{split}\log\mathbf{q} = \begin{bmatrix}\log\|\mathbf{q}\| \\ \mathbf{u}\frac{\pi}{2}\end{bmatrix}\end{split}\]

Similarly, for unitary quaternions (\(\|\mathbf{q}\|=1\)) the logarithm is:

\[\begin{split}\log\mathbf{q} = \begin{bmatrix} 0 \\ \mathbf{u}\arccos(q_w) \end{bmatrix}\end{split}\]

which further reduces for pure unitary quaternions (\(q_w=0\) and \(\|\mathbf{q}\|=1\)) to:

\[\begin{split}\log\mathbf{q} = \begin{bmatrix} 0 \\ \mathbf{u}\frac{\pi}{2} \end{bmatrix}\end{split}\]
Returns:

log – Logarithm of quaternion.

Return type:

numpy.ndarray

Examples

>>> q = Quaternion([1.0, -2.0, 3.0, -4.0])
>>> q.view()
Quaternion([ 0.18257419, -0.36514837,  0.54772256, -0.73029674])
>>> q.logarithm
array([ 0.        , -0.51519029,  0.77278544, -1.03038059])
>>> q = Quaternion([0.0, 1.0, -2.0, 3.0])
>>> q.view()
Quaternion([ 0.        ,  0.26726124, -0.53452248,  0.80178373])
>>> q.logarithm
array([ 0.        ,  0.41981298, -0.83962595,  1.25943893])