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

Unnecessary handedness in rotation explanation #78

Closed
emilk opened this issue Sep 11, 2020 · 5 comments
Closed

Unnecessary handedness in rotation explanation #78

emilk opened this issue Sep 11, 2020 · 5 comments

Comments

@emilk
Copy link
Contributor

emilk commented Sep 11, 2020

In the landing page of the documentation at https://docs.rs/glam you can read the following:

Rotations follow left-hand rule. The direction of the axis gives the direction of rotation: with the left thumb pointing in the positive direction of the axis the left fingers curl around the axis in the direction of the rotation.

Then follows his code:

// rotate +x 90 degrees clockwise around y giving -z
let m = Mat3::from_rotation_y(90.0_f32.to_radians());
let v = m * Vec3::unit_x();
assert!(v.abs_diff_eq(-Vec3::unit_z(), core::f32::EPSILON));

The thing is: quarternion rotations are not tied to any frame or handedness. For left-handed coordinate systems it follows left-hand rule, and for right-handed coordinate systems it follows right-hand rule. Consider a right handed X-Y-Z system. 90 deg rotation around Y would bring +X to the -Z direction, just like the example above.

So the above paragraph muddies the waters and may unnecessarily scare away people who use right-handed systems.

SUMMARY: glam is (mostly) handedness agnostic. I think it would help the project to say so up-front, instead of implying the opposite!

@bitshifter
Copy link
Owner

Ah right, handedness has confused me a bit at points. I guess looking at https://www.evl.uic.edu/ralph/508S98/coordinates.html it's more about the convention than what is going on in the math.

@bitshifter
Copy link
Owner

If you felt like rewording it I'd be happy to accept a PR. Otherwise I will get to it sometime.

@aloucks
Copy link
Contributor

aloucks commented Sep 13, 2020

For what it's worth, I found the documentation helpful and hope that it's not removed. Wouldn't the angles need to be negated if the rotations were following the right-hand rule?

@bitshifter
Copy link
Owner

bitshifter commented Sep 13, 2020

Wouldn't the angles need to be negated if the rotations were following the right-hand rule?

I don't think so, only for a function like from_rotation_ypr which bakes in a notion of coordinate systems (see #79). If you look at the images on https://www.evl.uic.edu/ralph/508S98/coordinates.html rotating unit +Z +90 degrees around +Y will result in unit +X. This is true for both left-handed and right-handed systems. While conceptually in the left-handed system positive rotation is clockwise and in the right-handed system positive rotation is counter-clockwise, mathematically they are the same.

I think that is what @emilk was getting at.

Code wise:

use glam::{Mat3, Vec3};
// rotate +z 90 degrees around y giving +x
let m = Mat3::from_rotation_y(90.0_f32.to_radians());
let v = m * Vec3::unit_z();
assert!(v.abs_diff_eq(Vec3::unit_x(), core::f32::EPSILON));

@emilk
Copy link
Contributor Author

emilk commented Sep 17, 2020

Thanks @bitshifter !

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

3 participants