FAIRmat-NFDI / nexus_definitions

Definitions of the NeXus Standard File Structure and Contents
https://manual.nexusformat.org/
Other
5 stars 8 forks source link

Implement base change directly in NXtransformations #235

Open lukaspie opened 1 month ago

lukaspie commented 1 month ago

This is an add-on to #144 which essentially incorporates NXcoordinate_system directly within NXtransformations.

There are three changes to NXtransformations: 1) transformation_type may be base_change, in which case a matrix containing n_dim column vectors of n_dim length should be supplied. 2) an attribute matrix is added to AXISNAME which shall contain n_dim column vectors of n_dim length. This is to be used to provide a matrix going from one coordinate system going to the other. 3) an attribute direction is added to AXISNAME that provides a human-readable field which direction the axis points. This is to be used to a define a reference frame (i.e, for axes with no transformation_type). If matrix is filled, then this field shall contain the direction of all n-dim matrix elements.

Examples: 1) There is an example in the NXtransformation docs. 2) You can download an example for the CS change in NXtransformations here.

lukaspie commented 3 days ago

Feedback from today's PR:

lukaspie commented 2 days ago

For reference, also copying here from #249:

The sense of "positive" rotation changes with the handedness of the CO system, i.e. one needs other rotation matrices depending on the handedness of the system.

If you think about a rotation around the z-axis from the perspective of viewing from the origin towards the positive end of the z-axis, you have:

R_z^{\text{left}}(\alpha) = \begin{pmatrix}
\cos\alpha & \sin\alpha & 0 \\
-\sin\alpha & \cos\alpha & 0 \\
0 & 0 & 1
\end{pmatrix}

For any arbitrary rotation around axis $\mathbf{u} = (u_x, u_y, u_z)$ by an angle $\theta$, the rotation matrix is:

NXtransformations/@vector with @transformation_type=rotation explicitly mentions "right-handed rotation with increasing angle". In the future, it would be best if we would allow both left- and right-handed rotations and mention in the docstring what that means in terms of the actual rotations. There, we should probably also state the orientation that we choose. Namely, we are looking from the origin towards positive axis values. This is also in line with what is the current definition of the NeXus coordinate system.

See also this and this link.