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

Conversion between euler and quats doesn't seem stable #86

Open
rvanlaar opened this issue May 21, 2024 · 7 comments
Open

Conversion between euler and quats doesn't seem stable #86

rvanlaar opened this issue May 21, 2024 · 7 comments

Comments

@rvanlaar
Copy link

While creating a pygfx Controller I noticed the following:

Moving from euler to quats and back is not stable.
Here's an example:

In [11]: la.quat_to_euler(la.quat_from_euler(np.array([math.pi/2, math.pi/180,0])))
Out[11]: array([1.57079633e+00, 1.73472348e-18, 1.74532925e-02])

Almost as if the last two items of the array are reversed.

In code:

import math
import numpy as np
import pylinalg as la

la.quat_to_euler(la.quat_from_euler(np.array([math.pi/2,math.pi/180,0])))
@rvanlaar
Copy link
Author

Looked at scipy, and that one works:

import numpy as np
import pylinalg as la

from scipy.spatial.transform import Rotation


quat = np.array([0.70707986, 0.00617059, 0.00617059, 0.70707986])

la.quat_to_euler(quat)
Rotation.from_quat(quat).as_euler("XYZ")

@Korijn
Copy link
Contributor

Korijn commented May 21, 2024

Would you mind opening a pull request with a unit test that demonstrates the failure?

rvanlaar added a commit to rvanlaar/pylinalg that referenced this issue May 22, 2024
quats_from_euler are handled differently when using uppercase
vs lowercase order. The default is uppercase which doesn't give the
right angles when converting back to euler.
@rvanlaar
Copy link
Author

Done: #87

It seems the issue has to do with the order. The default uppercase "XYZ" has a different result than lowercase "xyz".

@Korijn
Copy link
Contributor

Korijn commented May 22, 2024

is_extrinsic = [x.isupper() for x in order]

Using uppercase letters apparently makes that axis extrensic. I don't really understand what that means.

@rvanlaar
Copy link
Author

The three rotations can either be in a global frame of reference (extrinsic) or in a 
body centred frame of reference (intrinsic), which is attached to, and moves with, the object under rotation 

https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.transform.Rotation.from_euler.html

My 2cts:

  • Document the behavior
  • give quat_to_euler also an order
  • have quat_to_euler and quat_from_euler use the same default order.

@Korijn
Copy link
Contributor

Korijn commented May 22, 2024

If you want to take a shot at it, you're more than welcome. We're shorthanded at the moment.

@rvanlaar
Copy link
Author

Thanks for the offer. Am very busy, but who knows.

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