quaternion_to_rotmat

giant.rotations:

giant.rotations.quaternion_to_rotmat(quaternion)[source]

This function converts an attitude quaternion into its equivalent rotation matrix of the form discussed in Rotation Representations.

Rotation quaternions are converted to rotation matrices by using:

\[\begin{split}\mathbf{q}=\left[\begin{array}{c}\mathbf{q}_v \\ q_s\end{array}\right] \\ \mathbf{T} = (q_s^2-\mathbf{q}_v^T\mathbf{q}_v)\mathbf{I}_{3\times 3}+2\mathbf{q}_v\mathbf{q}_v^T+2q_s \left[\mathbf{q}_v\times\right]\end{split}\]

where \(\mathbf{q}_v\) is the vector portion of the quaternion, \(q_s\) is the scalar portion of the quaternion, \(\left[\bullet\times\right]\) is the skew symmetric cross product matrix (see skew()), and \(\mathbf{I}_{3\times 3}\) is a \(3\times 3\) identity matrix.

This function is vectorized, meaning that you can specify multiple rotation quaternions to be converted to matrices by specifying each quaternion as a column. Regardless of whether you are converting 1 or many quaternions the first axis must have a length of 4. When converting multiple quaternions, each rotation matrix is stacked along the first axis such that the rotation matrix for the rotation quaternion in the first column is the 0th index of the first axis, the rotation matrix for the rotation quaternion in the second column is the 1st index of the first axis, and so on. For example:

>>> from giant.rotations import quaternion_to_rotmat
>>> from numpy import sqrt
>>> quaternion_to_rotmat([[0, 0], [1, 1/sqrt(3)], [0, 1/sqrt(3)], [0, 1/sqrt(3)]])
array([[[-1.        ,  0.        ,  0.        ],
        [ 0.        ,  1.        ,  0.        ],
        [ 0.        ,  0.        , -1.        ]],
       [[-0.33333333, -0.66666667,  0.66666667],
        [ 0.66666667,  0.33333333,  0.66666667],
        [-0.66666667,  0.66666667,  0.33333333]]])
Parameters:

quaternion (Sequence | ndarray | Rotation) – The rotation quaternion(s) to be converted to the rotation matrix(ces)

Returns:

a numpy array containing the rotation matrix(ces) corresponding to the input quaternion(s)

Return type:

ndarray