Created
September 20, 2023 08:06
-
-
Save Carreau/53dfaefa0c07aa3a7a0bd90e890810bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vispy.util.quaternion import Quaternion | |
from itertools import permutations | |
from scipy.spatial.transform import Rotation | |
from napari._vispy.utils.quaternion import ( | |
_old_quaterion2euler as quaternion2euler, | |
) | |
import numpy as np | |
print('ok') | |
from random import randrange, choice | |
def test(res, deg=False): | |
q = Quaternion(*res) | |
# print(q.w, q.x, q.y, q.z) | |
a, b, c = quaternion2euler(q, degrees=deg) | |
z, y, x = Rotation.from_quat([q.x, q.y, q.z, q.w]).as_euler( | |
'xyz', degrees=deg | |
) | |
mod = 360 if deg else np.pi * 2 | |
xyz = np.mod(np.array([x, y, z]), np.pi * 2) | |
abc = np.mod(np.array([a, b, c]), np.pi * 2) | |
diff = np.allclose(abc, xyz) | |
if not diff: | |
# print(diff) | |
print() | |
print(res) | |
print(f" old {x:0.3f}, {y:0.3f}, {z:0.3f}") | |
print(f" new {a:0.3f}, {b:0.3f}, {c:0.3f}") | |
print(f" diff {a-x:0.3f}, {y-b:0.3f}, {z-c:0.3f}") | |
for i in range(10000): | |
res = [randrange(-500, 500) / 100 for _ in range(4)] | |
deg = choice([False, True]) | |
test(res, deg) | |
test([0.09, -0.78, 0.09, 0.78]) | |
test([-0.64, -0.58, -0.64, 0.58]) | |
test([0.85, -0.98, -0.85, -0.98]) | |
test([-0.19, 0.15, 0.19, 0.15]) # gimbal lock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment