0

I compared the outputs of scipy and MATLAB functions for creating 3D rotation matrices and the two programs showed different results.

First SciPys scipy.spatial.transform.Rotation:

>>> import numpy as np
>>> from scipy.spatial.transform import Rotation as R

>>> R.from_euler('zyz', [np.pi/2, np.pi/2, 0]).as_dcm()
array([[ 0.00000000e+00, -2.22044605e-16,  1.00000000e+00],
       [ 1.00000000e+00,  2.22044605e-16,  0.00000000e+00],
       [-2.22044605e-16,  1.00000000e+00,  2.22044605e-16]])


>>> R.from_euler('zyz', [0, np.pi/2, np.pi/2]).as_dcm()
array([[ 0.00000000e+00, -1.00000000e+00,  2.22044605e-16],
       [ 2.22044605e-16,  2.22044605e-16,  1.00000000e+00],
       [-1.00000000e+00,  0.00000000e+00,  2.22044605e-16]])

Now matlabs eul2rotm function:

>> eul2rotm([pi/2 pi/2 0], 'ZYZ')

ans =

    0.0000   -1.0000    0.0000
    0.0000    0.0000    1.0000
   -1.0000         0    0.0000


>> eul2rotm([0 pi/2 pi/2], 'ZYZ')

ans =

    0.0000   -0.0000    1.0000
    1.0000    0.0000         0
   -0.0000    1.0000    0.0000

So in the end, the order how the rotations are applied seem to differ. But which one is the correct one? I appreciate any help.

Tested with SciPy 1.3.1, NumPy 1.15.4 and Matlab R2018b.

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
JakobJakobson13
  • 135
  • 1
  • 4
  • 13
  • 1
    Same arrays, but switched in order. There's probably a difference in naming or orientation of the axes. The default order for MATLAB is "ZYX". With `scipy` there's a difference between 'xyz' and 'XYZ'. In fact if you use 'ZYZ' the `scipy` arrays matche the MATLAB matrices. – hpaulj Oct 16 '19 at 23:15
  • Thanks for the explanation. I indeed did overlook differentiation between `'xyz'` and `'XYZ'`. – JakobJakobson13 Oct 17 '19 at 08:09

0 Answers0