Talk:Conversion between quaternions and Euler angles: Difference between revisions

Content deleted Content added
Line 84:
 
2) The page [[Quaternions and spatial rotation]] makes very valid points on why Hamilton quaternions should be favored, so using only Hamilton quaternions here should be preferred. [[User:Ebernardes|Ebernardes]] ([[User talk:Ebernardes|talk]]) 14:31, 18 December 2022 (UTC)
 
== Changed the quaternion to Euler angles conversion formula ==
 
This new one has no numerical problems for the pitch. For anyone interested, I'll leave here a simple Python snippet that test both expressions to show they are equivalent:
 
<syntaxhighlight lang="python">
import numpy as np
from itertools import product
 
for w, x, y, z in product([-1, 0, 1], repeat=4):
n = np.sqrt(w**2 + x**2 + y**2 + z**2)
if n > 10e-7:
w /= n
x /= n
y /= n
z /= n
 
sinp = np.sqrt(1 + 2 * (w * x - y * z));
cosp = np.sqrt(1 - 2 * (w * x - y * z));
pitch1 = 2 * np.arctan2(sinp, cosp) - np.pi / 2;
 
pitch2 = np.arcsin(2 * (w * x - y * z))
 
assert (pitch1 - pitch2) < 10e-7
</syntaxhighlight>[[User:Ebernardes|Ebernardes]] ([[User talk:Ebernardes|talk]]) 16:41, 18 December 2022 (UTC)