@@ -1107,48 +1107,14 @@ def normalize_quaternions(quaternions):
11071107 return q_w / q_norm , q_x / q_norm , q_y / q_norm , q_z / q_norm
11081108
11091109
1110- def euler321_to_quaternions (psi , theta , phi ):
1111- """Calculates the quaternions (Euler parameters) from the Euler angles in
1112- yaw, pitch, and roll sequence (3-2-1).
1113-
1114- Parameters
1115- ----------
1116- psi : float
1117- Euler angle due to roll in degrees, also known as the spin angle.
1118- theta : float
1119- Euler angle due to pitch in degrees, also known as the nutation angle.
1120- phi : float
1121- Euler angle due to yaw in degrees, also known as the precession angle.
1122-
1123- Returns
1124- -------
1125- tuple[float, float, float, float]
1126- Tuple containing the Euler parameters e0, e1, e2, e3
1127- """
1128- phi = math .radians (phi )
1129- theta = math .radians (theta )
1130- psi = math .radians (psi )
1131- cr = math .cos (phi / 2 )
1132- sr = math .sin (phi / 2 )
1133- cp = math .cos (theta / 2 )
1134- sp = math .sin (theta / 2 )
1135- cy = math .cos (psi / 2 )
1136- sy = math .sin (psi / 2 )
1137- e0 = cr * cp * cy + sr * sp * sy
1138- e1 = sr * cp * cy - cr * sp * sy
1139- e2 = cr * sp * cy + sr * cp * sy
1140- e3 = cr * cp * sy - sr * sp * cy
1141- return e0 , e1 , e2 , e3
1142-
1143-
11441110def euler313_to_quaternions (phi , theta , psi ):
11451111 """Convert 3-1-3 Euler angles to Euler parameters (quaternions).
11461112
11471113 Parameters
11481114 ----------
11491115 phi : float
11501116 Rotation angle around the z-axis (in radians). Represents the precession
1151- angle or the yaw angle.
1117+ angle or the roll angle.
11521118 theta : float
11531119 Rotation angle around the x-axis (in radians). Represents the nutation
11541120 angle or the pitch angle.
@@ -1165,18 +1131,16 @@ def euler313_to_quaternions(phi, theta, psi):
11651131 ----------
11661132 https://www.astro.rug.nl/software/kapteyn-beta/_downloads/attitude.pdf
11671133 """
1168- e0 = np .cos (phi / 2 ) * np .cos (theta / 2 ) * np .cos (psi / 2 ) - np .sin (
1169- phi / 2
1170- ) * np .cos (theta / 2 ) * np .sin (psi / 2 )
1171- e1 = np .cos (phi / 2 ) * np .cos (psi / 2 ) * np .sin (theta / 2 ) + np .sin (
1172- phi / 2
1173- ) * np .sin (theta / 2 ) * np .sin (psi / 2 )
1174- e2 = np .cos (phi / 2 ) * np .sin (theta / 2 ) * np .sin (psi / 2 ) - np .sin (
1175- phi / 2
1176- ) * np .cos (psi / 2 ) * np .sin (theta / 2 )
1177- e3 = np .cos (phi / 2 ) * np .cos (theta / 2 ) * np .sin (psi / 2 ) + np .cos (
1178- theta / 2
1179- ) * np .cos (psi / 2 ) * np .sin (phi / 2 )
1134+ cphi = np .cos (phi / 2 )
1135+ sphi = np .sin (phi / 2 )
1136+ ctheta = np .cos (theta / 2 )
1137+ stheta = np .sin (theta / 2 )
1138+ cpsi = np .cos (psi / 2 )
1139+ spsi = np .sin (psi / 2 )
1140+ e0 = cphi * ctheta * cpsi - sphi * ctheta * spsi
1141+ e1 = cphi * cpsi * stheta + sphi * stheta * spsi
1142+ e2 = cphi * stheta * spsi - sphi * cpsi * stheta
1143+ e3 = cphi * ctheta * spsi + ctheta * cpsi * sphi
11801144 return e0 , e1 , e2 , e3
11811145
11821146
0 commit comments