Post · 2 min read· pp. 314–315

Hughes’ Method

ahrs.common.orientation.hughes(C: ndarray) → ndarray : Quaternion from a Direction Cosine Matrix with trigonometric Hughes’ method [Hug86].

code
Defining the quaternion (reluctantly called “Euler Parameters” in Hughes’
book) as:

q=[ηϵ]\mathbf{q} = \begin{bmatrix} \eta & \boldsymbol{\epsilon} \end{bmatrix}
where
η=cos⁡(ϕ2)ϵ=sin⁡(ϕ2)a\begin{split}\begin{array}{rcl} \eta &=& \cos \big(\frac{\phi}{2}\big) \\ \boldsymbol{\epsilon} &=& \sin \big(\frac{\phi}{2}\big) \mathbf{a} \end{array}\end{split}
The quaternion is subject to the constraint ϵTϵ+η2=1\boldsymbol{\epsilon}^T\boldsymbol{\epsilon}+\eta^2=1, and ϕ\phi is the rotation about the unitary axis a\mathbf{a}. The rotation matrix associated to the quaternion is:
C=(η2−ϵTϵ)I+2ϵϵT−2ηϵ×\mathbf{C} = (\eta ^2 - \boldsymbol{\epsilon}^T\boldsymbol{\epsilon})\mathbf{I} + 2\boldsymbol{\epsilon}\boldsymbol{\epsilon}^T - 2 \eta\boldsymbol{\epsilon}^\times
where I\mathbf{I} is the 3×33\times 3 identity matrix, and ϵ×\boldsymbol{\epsilon}^\times is the [skew-symmetric matrix](https://en.wikipedia.org/wiki/Skew-symmetric_matrix) of ϵ\boldsymbol{\epsilon}. Given C\mathbf{C}, the quaternion components are obtained as:
η=±12(1+c11+c22+c33)1/2ϵ=14η[c23−c32c31−c13c12−c21]\begin{split}\begin{array}{rcl} \eta &=& \pm\frac{1}{2} \big(1 + c_{11} + c_{22} + c_{33}\big)^{1/2} \\ \boldsymbol{\epsilon} &=& \frac{1}{4\eta} \begin{bmatrix} c_{23} - c_{32} \\ c_{31} - c_{13} \\ c_{12} - c_{21} \end{bmatrix} \end{array}\end{split}
The plus sign is chosen if it is advantageous to have a unique η\eta; corresponding to ϕ∈[0,π]\phi \in [0, \pi]. To ensure uniqueness, the vector part is multiplied by -1 if η>0\eta > 0. If η=0\eta = 0, then it is a pure quaternion, and its vector part is:
ϵ=[1+c1121+c2221+c332]\begin{split}\boldsymbol{\epsilon} = \begin{bmatrix} \sqrt{\frac{1+c_{11}}{2}} \\ \sqrt{\frac{1+c_{22}}{2}} \\ \sqrt{\frac{1+c_{33}}{2}} \end{bmatrix}\end{split}
Finally, we normalize the quaternion to have unitary norm.
q=q∥q∥\mathbf{q} = \frac{\mathbf{q}}{\|\mathbf{q}\|}
Parameters: : **C** (*numpy.ndarray*) – 3-by-3 or N-by-3-by-3 Direction Cosine Matrix (or Matrices). Returns: : **q** – 4-dimensional or N-by-4 Quaternion array. Return type: : numpy.ndarray