c4dynamics.rotmat.rotmat.quat2euler#
- c4dynamics.rotmat.rotmat.quat2euler(quat)[source]#
Extracts 3-2-1 Euler angles (roll, pitch, yaw) from an attitude quaternion.
For a scalar-first unit quaternion \(q = [q_w, q_x, q_y, q_z]\):
\[ \begin{align}\begin{aligned}\varphi = atan2(2(q_w q_x + q_y q_z), 1 - 2(q_x^2 + q_y^2))\\\theta = asin(2(q_w q_y - q_x q_z))\\\psi = atan2(2(q_w q_z + q_x q_y), 1 - 2(q_y^2 + q_z^2))\end{aligned}\end{align} \]The quaternion is normalized before the conversion.
- Parameters:
quat (array_like) – A quaternion \([q_w, q_x, q_y, q_z]\), or an Nx4 array of N quaternions.
- Returns:
out (numpy.ndarray) – Euler angles \([\varphi, \theta, \psi]\) in radians, or an Nx3 array of Euler angles for an Nx4 input.
Note
The quaternion itself is free of singularities. The extracted Euler angles, however, are singular at \(\theta = \pm 90°\), where \(\varphi\) and \(\psi\) are not uniquely defined (see
dcm321euler).Examples
>>> import c4dynamics as c4d >>> q = c4d.rotmat.euler2quat(10 * c4d.d2r, 20 * c4d.d2r, 30 * c4d.d2r) >>> c4d.rotmat.quat2euler(q) * c4d.r2d [10 20 30]