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

euler2mat bug? #17

Open
creuzige opened this issue Jan 16, 2018 · 4 comments
Open

euler2mat bug? #17

creuzige opened this issue Jan 16, 2018 · 4 comments

Comments

@creuzige
Copy link

creuzige commented Jan 16, 2018

However, I think I may have found a bug in euler2mat. The code I’ve used is
attached below.

My impression is that the intrinsic and extrinsic rotation matrices are
inverses of each other. And since they are orthogonal tensors, the inverse
is equal to the transpose. However, when I invert the rotation matrix
generated from 3 Euler angles using the rzxz convention, I do not get the
same rotation matrix as if I perform the ‘szxz’ rotation. Nor does the
transpose of the rzxz rotation match the szxz rotation. The values are
correct, but the negative signs are in the wrong position. In addition,
the axis/angle pair calculated from the szxz rotation has a different axis
than the rzxz rotation.

Did I miss something, or are my observations correct?

Thanks!

Code example:

# set rotation of crystal

import math
import transforms3d as t3d
import numpy as np

phi1=(20.0)*(math.pi/180.0)
PHI=(15.0)*(math.pi/180.0)
phi2=(25.0)*(math.pi/180.0)
r=t3d.euler.euler2mat(phi1, PHI, phi2, 'rzxz')
(Raxis, Rangle)=t3d.euler.euler2axangle(phi1, PHI, phi2, 'rzxz')

print "\n RZXZ rotation"
print r
print Raxis
print Rangle

print "\n RZXZ inverse rotation"
print np.linalg.inv(r)
(Raxis, Rangle)=t3d.axangles.mat2axangle(np.linalg.inv(r))
print Raxis
print Rangle


r=t3d.euler.euler2mat(phi1, PHI, phi2, 'szxz')
(Raxis, Rangle)=t3d.euler.euler2axangle(phi1, PHI, phi2, 'szxz')

print "\n SZXZ rotation"
print r
print Raxis
print Rangle

# Doesn't seem quite right, the minus signs are in the same place...

Output:

RZXZ rotation
[[ 0.712032   -0.69654462  0.08852133]
[ 0.69357486  0.67808749 -0.24321035]
[ 0.10938165  0.23456972  0.96592583]]
[ 0.32500232 -0.01418991  0.94560676]
0.82572715704

RZXZ inverse rotation
[[ 0.712032    0.69357486  0.10938165]
[-0.69654462  0.67808749  0.23456972]
[ 0.08852133 -0.24321035  0.96592583]]
[ 0.32500232 -0.01418991  0.94560676]
-0.82572715704

SZXZ rotation
[[ 0.712032   -0.69357486  0.10938165]
[ 0.69654462  0.67808749 -0.23456972]
[ 0.08852133  0.24321035  0.96592583]]
[0.32500232 0.01418991 0.94560676]
0.82572715704
@matthew-brett
Copy link
Owner

@cgohlke - any thoughts here? I haven't modified that part of the code from transformations.py.

@creuzige
Copy link
Author

creuzige commented Jan 17, 2018

I started looking into the code to see if I could be any help. I noticed that in mat2euler the axes sequence specified does not seem to match up with the i,j, and k axes listed for all axes. I've assumed that axis 0 is x, then axis 1 is y, and axis 2 is z. If that doesn't hold, then my observations are probably irrelevant.

I modified the euler.py file to test all of the Euler axis combinations listed (attached as a .txt file) as a standalone program. The output is below.

euler.txt

python euler.py
Input Axes = sxyz
Output Axes: xyz
Axes match
Input Axes = sxyx
Output Axes: xyz
Axes do NOT match
Input Axes = sxzy
Output Axes: xzy
Axes match
Input Axes = sxzx
Output Axes: xzy
Axes do NOT match
Input Axes = syzx
Output Axes: yzx
Axes match
Input Axes = syzy
Output Axes: yzx
Axes do NOT match
Input Axes = syxz
Output Axes: yxz
Axes match
Input Axes = syxy
Output Axes: yxz
Axes do NOT match
Input Axes = szxy
Output Axes: zxy
Axes match
Input Axes = szxz
Output Axes: zxy
Axes do NOT match
Input Axes = szyx
Output Axes: zyx
Axes match
Input Axes = szyz
Output Axes: zyx
Axes do NOT match
Input Axes = rzyx
Output Axes: xyz
Axes do NOT match
Input Axes = rxyx
Output Axes: xyz
Axes do NOT match
Input Axes = ryzx
Output Axes: xzy
Axes do NOT match
Input Axes = rxzx
Output Axes: xzy
Axes do NOT match
Input Axes = rxzy
Output Axes: yzx
Axes do NOT match
Input Axes = ryzy
Output Axes: yzx
Axes do NOT match
Input Axes = rzxy
Output Axes: yxz
Axes do NOT match
Input Axes = ryxy
Output Axes: yxz
Axes do NOT match
Input Axes = ryxz
Output Axes: zxy
Axes do NOT match
Input Axes = rzxz
Output Axes: zxy
Axes do NOT match
Input Axes = rxyz
Output Axes: zyx
Axes do NOT match
Input Axes = rzyz
Output Axes: zyx
Axes do NOT match`

@matthew-brett
Copy link
Owner

Hi - sorry for the flying feedback - but I'm sure you gathered that the angles are in the order specified by the axis labels, so if you have sxyz then the order of the angles is indeed x, y, z, but if you have rzyz then the order is z, y, z.

@creuzige
Copy link
Author

creuzige commented Jan 18, 2018 via email

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