Why different results for Euler to Rotation Matrix in Matlab and Python

Question:

When I use Matlab and Python to transform from Euler to Rotation Matrix, I get different results, and I can’t figure out why.

Python code

from scipy.spatial.transform import Rotation as R
cam_angle = 45
R.from_euler('xyz', [-90-cam_angle, 0, -90], degrees=True).as_matrix()

gives:

array([[ 0.        , -0.70710678,  0.70710678],
       [-1.        ,  0.        ,  0.        ],
       [ 0.        , -0.70710678, -0.70710678]])

While Matlab code

cam_angle = 45
eul2rotm(deg2rad([-90-cam_angle, 0, -90]),'xyz')

gives:

0.0000    1.0000         0
0.7071   -0.0000    0.7071
0.7071   -0.0000   -0.7071

Anyone have a idea?

Asked By: Fucker3000

||

Answers:

In your Python code, use an uppercase 'XYZ' for the seq argument for from_euler to use intrinsic rotations, which is the convention your MATLAB seems to be using. (This convention will vary among MATLAB functions. See James Tursa’s comment.)

from scipy.spatial.transform import Rotation as R
cam_angle = 45
R.from_euler('XYZ', [-90-cam_angle, 0, -90], degrees=True).as_matrix()

Result:

array([[ 0.        ,  1.        ,  0.        ],
       [ 0.70710678,  0.        ,  0.70710678],
       [ 0.70710678,  0.        , -0.70710678]])

From the scipy docs:

Parameters: seq string
Specifies sequence of axes for rotations. Up to 3
characters belonging to the set {‘X’, ‘Y’, ‘Z’} for intrinsic
rotations, or {‘x’, ‘y’, ‘z’} for extrinsic rotations. Extrinsic and
intrinsic rotations cannot be mixed in one function call.

Answered By: thariqfahry
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.