quat2rotation

Calculate rotation matrix based on quaternions.

If B is a FoR obtained rotating a FoR A by an angle \(\phi\) about an axis \(\mathbf{n}\) (recall \(\mathbf{n}\) will be invariant during the rotation), and \(\mathbf{q}\) is the related quaternion, \(\mathbf{q}(\phi,\mathbf{n})\), the function will return the matrix \(C^{AB}\) such that:

  • \(C^{AB}\) rotates FoR A onto FoR B.

  • \(C^{AB}\) transforms the coordinates of a vector defined in B component to A components i.e. \(\mathbf{v}^A = C^{AB}(\mathbf{q})\mathbf{v}^B\).

\[\begin{split}C^{AB}(\mathbf{q}) = \begin{pmatrix} q_0^2 + q_1^2 - q_2^2 -q_3^2 & 2(q_1 q_2 - q_0 q_3) & 2(q_1 q_3 + q_0 q_2) \\ 2(q_1 q_2 + q_0 q_3) & q_0^2 - q_1^2 + q_2^2 - q_3^2 & 2(q_2 q_3 - q_0 q_1) \\ 2(q_1 q_3 - q_0 q_2) & 2(q_2 q_3 + q_0 q_1) & q_0^2 -q_1^2 -q_2^2 +q_3^2 \end{pmatrix}\end{split}\]

Notes

The inverse rotation is defined as the transpose of the matrix \(C^{BA} = C^{{AB}^T}\).

In typical SHARPy applications, the quaternion relation between the A and G frames is expressed as \(C^{GA}(\mathbf{q})\), and in the context of this function it corresponds to:

>>> C_ga = quat2rotation(q1)
>>> C_ag = quat2rotation.T(q1)
param q:

Quaternion \(\mathbf{q}(\phi, \mathbf{n})\).

type q:

np.ndarray

returns:

\(C^{AB}\) rotation matrix from FoR B to FoR A.

rtype:

np.ndarray

References

Stevens, L. Aircraft Control and Simulation. 1985. pg 41