Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentially a bug in quat.py #32

Open
kai-lan opened this issue Sep 22, 2024 · 1 comment
Open

Potentially a bug in quat.py #32

kai-lan opened this issue Sep 22, 2024 · 1 comment

Comments

@kai-lan
Copy link
Contributor

kai-lan commented Sep 22, 2024

There seem to be a bug in quaternion to euler conversion. Here is my test:

e = np.array([0.1*np.pi, 0.2*np.pi, 0.5*np.pi])
q = from_euler(e, order='xyz')
e1 = to_euler(q, order='xyz')
q1 = from_euler(e1, order='xyz')
print(q)
print(q1)

print()
from scipy.spatial.transform import Rotation as R
q = R.from_euler('XYZ', e, degrees=False).as_quat(scalar_first=True)
e1 = R.from_quat(q).as_euler('XYZ', degrees=False)
q1 = R.from_euler('XYZ', e1, degrees=False).as_quat()
print(q)
print(q1)

Expected output:

[0.63003676 0.32101976 0.11061587 0.69840112]
[0.63003676 0.32101976 0.11061587 0.69840112]

[0.63003676 0.32101976 0.11061587 0.69840112]
[0.63003676 0.32101976 0.11061587 0.69840112]

Actual output:

[0.63003676 0.32101976 0.11061587 0.69840112]
[ 0.69840112  0.11061587 -0.32101976  0.63003676]

[0.63003676 0.32101976 0.11061587 0.69840112]
[0.63003676 0.32101976 0.11061587 0.69840112]
@orangeduck
Copy link
Owner

Thanks Kai.

I have a feeling that when I did this I screwed up the to_euler function and it actually takes the order argument the wrong way around compared to from_euler (at least for the xyz case. I'm not sure about the yzx case).

So I believe if you do the following you get the same result (I could be wrong):

e = np.array([0.1*np.pi, 0.2*np.pi, 0.5*np.pi])
q = from_euler(e, order='zyx')
e1 = to_euler(q, order='xyz')
q1 = from_euler(e1, order='zyx')

Perhaps you can check that and if so maybe do a PR that fixes it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants