from_quaternion#

DCM.from_quaternion(q: ndarray) ndarray#

DCM from given quaternion

The quaternion \(\mathbf{q}\) has the form \(\mathbf{q} = (q_w, q_x, q_y, q_z)\), where \(\mathbf{q}_v = (q_x, q_y, q_z)\) is the vector part, and \(q_w\) is the scalar part.

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

\[\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 \(\mathbf{q} = \begin{pmatrix}1 & 0 & 0 & 0\end{pmatrix}\), produces a \(3 \times 3\) Identity matrix \(\mathbf{I}_3\).

Parameters:

q (numpy.ndarray) – Quaternion

Returns:

R – 3-by-3 direction cosine matrix

Return type:

numpy.ndarray

Examples

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

Non-normalized quaternions will be normalized and transformed too.

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

A list (or a Numpy array) with N quaternions will return an N-by-3-by-3 array with the corresponding DCMs.

>>> 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]],

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