c4dynamics.rotmat.rotmat.euler2quat#
- c4dynamics.rotmat.rotmat.euler2quat(phi=0.0, theta=0.0, psi=0.0)[source]#
Converts 3-2-1 Euler angles to an attitude quaternion.
The quaternion is given in a scalar-first (Hamilton) convention, \(q = [q_w, q_x, q_y, q_z]\), and represents the same attitude as the DCM of 3-2-1 order,
dcm321, i.e. first rotation about the z axis (yaw, \(\psi\)), then a rotation about the y axis (pitch, \(\theta\)), and finally a rotation about the x axis (roll, \(\varphi\)):\[ \begin{align}\begin{aligned}q_w = c{\varphi \over 2} c{\theta \over 2} c{\psi \over 2} + s{\varphi \over 2} s{\theta \over 2} s{\psi \over 2}\\q_x = s{\varphi \over 2} c{\theta \over 2} c{\psi \over 2} - c{\varphi \over 2} s{\theta \over 2} s{\psi \over 2}\\q_y = c{\varphi \over 2} s{\theta \over 2} c{\psi \over 2} + s{\varphi \over 2} c{\theta \over 2} s{\psi \over 2}\\q_z = c{\varphi \over 2} c{\theta \over 2} s{\psi \over 2} - s{\varphi \over 2} s{\theta \over 2} c{\psi \over 2}\end{aligned}\end{align} \]where \(c \equiv cos\) and \(s \equiv sin\).
- Parameters:
phi (float or int) – The angle in radian of rotation about x, default \(\varphi = 0\).
theta (float or int) – The angle in radian of rotation about y, default \(\theta = 0\).
psi (float or int) – The angle in radian of rotation about z, default \(\psi = 0\).
- Returns:
out (numpy.ndarray) – A unit quaternion \([q_w, q_x, q_y, q_z]\).
Examples
>>> import c4dynamics as c4d >>> c4d.rotmat.euler2quat(0, 0, 0) [1 0 0 0]
A 90 degrees yaw:
>>> c4d.rotmat.euler2quat(psi = 90 * c4d.d2r) [0.707 0 0 0.707]