Post · 1 min read· pp. 124–125

Quaternion.logarithm

Quaternion.logarithm : Logarithm of Quaternion.

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

log⁡q=[log⁡∥q∥uθ]\begin{split}\log\mathbf{q} = \begin{bmatrix} \log\|\mathbf{q}\| \\ \mathbf{u}\theta \end{bmatrix}\end{split}
with:
u=qv∥qv∥θ=arccos⁡(qw∥q∥)\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** q=(0qv)\mathbf{q}=\begin{pmatrix}0 & \mathbf{q_v}\end{pmatrix}, the logarithm simplifies the computation through θ=arccos⁡(0)=π2\theta=\arccos(0)=\frac{\pi}{2}:
log⁡q=[log⁡∥q∥uπ2]\begin{split}\log\mathbf{q} = \begin{bmatrix}\log\|\mathbf{q}\| \\ \mathbf{u}\frac{\pi}{2}\end{bmatrix}\end{split}
Similarly, for **unitary quaternions** (∥q∥=1\|\mathbf{q}\|=1) the logarithm is:
log⁡q=[0uarccos⁡(qw)]\begin{split}\log\mathbf{q} = \begin{bmatrix} 0 \\ \mathbf{u}\arccos(q_w) \end{bmatrix}\end{split}
which further reduces for **pure unitary quaternions** (qw=0q_w=0 and ∥q∥=1\|\mathbf{q}\|=1) to:
log⁡q=[0uπ2]\begin{split}\log\mathbf{q} = \begin{bmatrix} 0 \\ \mathbf{u}\frac{\pi}{2} \end{bmatrix}\end{split}
And for **real quaternions** (q=(qw000)\mathbf{q}=\begin{pmatrix}q_w & 0 & 0 & 0\end{pmatrix}) the logarithm is:
log⁡q=[0000]\log\mathbf{q} = \begin{bmatrix} 0 & 0 & 0 & 0 \end{bmatrix}
Returns: : **log** – Logarithm of quaternion. Return type: : numpy.ndarray Examples ```default

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]) ```