to_DCM#
- Quaternion.to_DCM() ndarray #
Return a Direction Cosine matrix \(\mathbf{R} \in SO(3)\) from a given unit quaternion \(\mathbf{q}\).
The given unit quaternion must have the form \(\mathbf{q} = \begin{pmatrix}q_w & q_x & q_y & q_z\end{pmatrix}\), where \(\mathbf{q}_v = \begin{bmatrix}q_x & q_y & q_z\end{bmatrix}\) is the vector part, and \(q_w\) is the scalar part.
The resulting matrix \(\mathbf{R}\) [WikiConversions] 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\).
- Returns:
DCM – 3-by-3 Direction Cosine Matrix
- Return type:
numpy.ndarray
Examples
>>> q = Quaternion() >>> q.view() Quaternion([1., 0., 0., 0.]) >>> q.to_DCM() array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) >>> q = Quaternion([1., -2., 3., -4.]) >>> q.view() Quaternion([ 0.18257419, -0.36514837, 0.54772256, -0.73029674]) >>> q.to_DCM() array([[-0.66666667, -0.13333333, 0.73333333], [-0.66666667, -0.33333333, -0.66666667], [ 0.33333333, -0.93333333, 0.13333333]]) >>> q = Quaternion([0., -4., 3., -2.]) >>> q.view() Quaternion([ 0. , -0.74278135, 0.55708601, -0.37139068]) >>> q.to_DCM() array([[ 0.10344828, -0.82758621, 0.55172414], [-0.82758621, -0.37931034, -0.4137931 ], [ 0.55172414, -0.4137931 , -0.72413793]])