Skip to content

Clarify the conventions for rotations in left and right handed coordinate system#1563

Merged
PeterC-DLS merged 9 commits into
nexusformat:mainfrom
FAIRmat-NFDI:rotation-convention
May 16, 2025
Merged

Clarify the conventions for rotations in left and right handed coordinate system#1563
PeterC-DLS merged 9 commits into
nexusformat:mainfrom
FAIRmat-NFDI:rotation-convention

Conversation

@lukaspie

@lukaspie lukaspie commented May 9, 2025

Copy link
Copy Markdown
Contributor

There was a long-ish discussion in #1415 about which rotation convention to apply for left- and right-handed coordinate systems. Initially, it was agreed that if the NXtransformation depends on a coordinate system (i.e., its depends_on attribute points to an instance NXcoordinate_system), the rotation is always right handed in that coordinate system, even if the the coordinate system itself is left-handed (as defined by the determinant of its base vectors.

@PeterC-DLS suggested that this should not be the case. Rather, the rotation conventions should follow the handedness of the coordinate system because then the matrices don't have to be changed. So:

  • Rotations in left-handed coordinate systems are left-handed (i.e., they follow the left-hand rule). In a left-handed coordinate system, positive rotation about an axis is clockwise when looking from the end of the positive axis in the direction of the origin (from infinity towards the origin).

  • Rotations in right-handed coordinate systems are right-handed (i.e., the follow the right-hand rule). In a right-handed coordinate system, positive rotation about an axis is counter-clockwise when looking from the end of the positive axis in the direction of the origin (from infinity towards the origin).

Most importantly, the matrix transformation does not depend on handness and the same matrices can be used for left- and right-handed coordinate system (same Rodrigues' formula). Only the interpretation (“positive” direction of rotation) is different because the coordinate systems are mirror images! This will it also easier for most existing tools around NXtransformations to work with left-handed coordinate systems.

This is also the convention that most graphic packages and math/physics textbooks follow, from what I could gather.

I am not sure if a vote is needed for these documentation changes, but they should definitely be discussed.

@lukaspie lukaspie changed the title Rotation convention Clarify the conventions for rotations in left and right handed coordinate system May 9, 2025
@PeterC-DLS

Copy link
Copy Markdown
Contributor

I think your comment has the clockwise/anticlockwise mixed up for when viewing from the origin: RH CS has positive as clockwise and LH has that as anticlockwise.

@lukaspie lukaspie force-pushed the rotation-convention branch from b99c055 to 29d23e9 Compare May 9, 2025 11:00
Comment thread base_classes/NXtransformations.nxdl.xml Outdated
Comment thread base_classes/NXtransformations.nxdl.xml Outdated
Comment thread base_classes/NXtransformations.nxdl.xml Outdated
Comment thread base_classes/NXtransformations.nxdl.xml Outdated
@lukaspie

lukaspie commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

I think your comment has the clockwise/anticlockwise mixed up for when viewing from the origin: RH CS has positive as clockwise and LH has that as anticlockwise.

Are you sure? https://en.wikipedia.org/wiki/Right-hand_rule#Coordinates says that for right-handed systems, positive == counter-clockwise when looking along an axis in the positive direction.

EDIT: Sorry, you are right. It says "When viewed at a position along the positive z-axis", which basically means you are looking towards the origin. But we are looking from the origin towards inf.

lukaspie and others added 4 commits May 9, 2025 13:48
Co-authored-by: Peter Chang <peter.chang@diamond.ac.uk>
Co-authored-by: Peter Chang <peter.chang@diamond.ac.uk>
@lukaspie lukaspie marked this pull request as ready for review May 9, 2025 12:01
@lukaspie

lukaspie commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

@PeterC-DLS thanks for the suggestions, I think this is much cleaner now. I have decided now to change the viewing direction from the positive end of the axis towards the origin. This is much easier to visualize and also the common convention (see the wiki article linked above). The conclusion stays the same.

I also double-checked the additional documentation around transformations (specifically here), I don't think that there is anything there that is in contrast to the rotation conventions we define here.

Comment thread base_classes/NXtransformations.nxdl.xml Outdated
Comment thread base_classes/NXtransformations.nxdl.xml Outdated
Comment thread base_classes/NXtransformations.nxdl.xml Outdated
lukaspie and others added 2 commits May 14, 2025 16:56
Co-authored-by: Peter Chang <peter.chang@diamond.ac.uk>

@PeterC-DLS PeterC-DLS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@phyy-nx

phyy-nx commented May 16, 2025

Copy link
Copy Markdown
Contributor

From Telco: this doesn't need a vote as it's more of a bugfix. Thanks for the contribution and discussion.

@PeterC-DLS PeterC-DLS merged commit c12b47e into nexusformat:main May 16, 2025
2 checks passed
@lukaspie lukaspie deleted the rotation-convention branch May 16, 2025 16:39
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

Successfully merging this pull request may close these issues.

3 participants