c4dynamics.rotmat.rotmat.quat2dcm#
- c4dynamics.rotmat.rotmat.quat2dcm(quat)[source]#
Returns a Body-from-Reference Direction Cosine Matrix (DCM) of an attitude quaternion.
For a scalar-first unit quaternion \(q = [q_w, q_x, q_y, q_z]\), the DCM is given by:
\[\begin{split}R = \begin{bmatrix} 1 - 2(q_y^2 + q_z^2) & 2(q_x q_y + q_w q_z) & 2(q_x q_z - q_w q_y) \\ 2(q_x q_y - q_w q_z) & 1 - 2(q_x^2 + q_z^2) & 2(q_y q_z + q_w q_x) \\ 2(q_x q_z + q_w q_y) & 2(q_y q_z - q_w q_x) & 1 - 2(q_x^2 + q_y^2) \end{bmatrix}\end{split}\]The result is identical to
dcm321with the Euler angles of the same attitude. The quaternion is normalized before the conversion.- Parameters:
quat (array_like) – A quaternion \([q_w, q_x, q_y, q_z]\).
- Returns:
out (numpy.ndarray) – A 3x3 DCM matrix used to rotate a vector to the body frame from a reference frame of coordinates.
Examples
>>> import c4dynamics as c4d >>> q = c4d.rotmat.euler2quat(theta = 30 * c4d.d2r) >>> c4d.rotmat.quat2dcm(q) @ [1, 0, 0] [0.866 0 0.5]