Post · 2 min read· pp. 86–87

DCM.from_quaternion

classmethod DCM.from_quaternion(q: ndarray) → ndarray : DCM from given quaternion

code
The quaternion q\mathbf{q} has the form q=(qw,qx,qy,qz)\mathbf{q} = (q_w, q_x, q_y, q_z),
where qv=(qx,qy,qz)\mathbf{q}_v = (q_x, q_y, q_z) is the vector part, and
qwq_w is the scalar part.

The resulting matrix R\mathbf{R} has the form:

R(q)=[1−2(qy2+qz2)2(qxqy−qwqz)2(qxqz+qwqy)2(qxqy+qwqz)1−2(qx2+qz2)2(qyqz−qwqx)2(qxqz−qwqy)2(qwqx+qyqz)1−2(qx2+qy2)]\begin{split}\mathbf{R}(\mathbf{q}) = \begin{bmatrix} 1 - 2(q_y^2 + q_z^2) & 2(q_xq_y - q_wq_z) & 2(q_xq_z + q_wq_y) \\ 2(q_xq_y + q_wq_z) & 1 - 2(q_x^2 + q_z^2) & 2(q_yq_z - q_wq_x) \\ 2(q_xq_z - q_wq_y) & 2(q_wq_x + q_yq_z) & 1 - 2(q_x^2 + q_y^2) \end{bmatrix}\end{split}
The identity Quaternion q=(1000)\mathbf{q} = \begin{pmatrix}1 & 0 & 0 & 0\end{pmatrix}, produces a 3×33 \times 3 Identity matrix I3\mathbf{I}_3. Parameters: : **q** (*numpy.ndarray*) – Quaternion Returns: : **R** – 3-by-3 direction cosine matrix Return type: : numpy.ndarray Examples ```default

R = DCM() R.from_quaternion([0.70710678, 0.0, 0.70710678, 0.0]) array([[-2.22044605e-16, 0.00000000e+00, 1.00000000e+00], [ 0.00000000e+00, 1.00000000e+00, 0.00000000e+00], [-1.00000000e+00, 0.00000000e+00, -2.22044605e-16]])

code

    Non-normalized quaternions will be normalized and transformed too.

    ```default
>>> R.from_quaternion([1, 0.0, 1, 0.0])
array([[ 2.22044605e-16,  0.00000000e+00,  1.00000000e+00],
       [ 0.00000000e+00,  1.00000000e+00,  0.00000000e+00],
       [-1.00000000e+00,  0.00000000e+00,  2.22044605e-16]])
code
A list (or a Numpy array) with N quaternions will return an N-by-3-by-3
array with the corresponding DCMs.

```default

R.from_quaternion([[1, 0.0, 1, 0.0], [1.0, -1.0, 0.0, 1.0], [0.0, 0.0, -1.0, 1.0]]) array([[[ 2.22044605e-16, 0.00000000e+00, 1.00000000e+00], [ 0.00000000e+00, 1.00000000e+00, 0.00000000e+00], [-1.00000000e+00, 0.00000000e+00, 2.22044605e-16]],

code
   [[ 3.33333333e-01, -6.66666667e-01, -6.66666667e-01],
    [ 6.66666667e-01, -3.33333333e-01,  6.66666667e-01],
    [-6.66666667e-01, -6.66666667e-01,  3.33333333e-01]],

   [[-1.00000000e+00, -0.00000000e+00,  0.00000000e+00],
    [ 0.00000000e+00,  2.22044605e-16, -1.00000000e+00],
    [ 0.00000000e+00, -1.00000000e+00,  2.22044605e-16]]])
code