0
$\begingroup$

I want to check if I am using the correct functions to transform from euler angles to rotation matrix and viceversa. I am using XY’Z” convention of euler intrinsic angles. As example, I have the following euler angles:

roll = 0, pitch = -90, yaw = 90,

I am using the following python function to transform it to rotation matrix:

  def fromeulertorotationmatrix(theta1, theta2, theta3, order='xyz'):
    """
    input
        theta1, theta2, theta3 = rotation angles in rotation order (degrees)
        oreder = rotation order of x,y,z e.g. XZY rotation -- 'xzy'
    output
        3x3 rotation matrix (numpy array)
    """
    c1 = np.cos(theta1 * np.pi / 180)
    s1 = np.sin(theta1 * np.pi / 180)
    c2 = np.cos(theta2 * np.pi / 180)
    s2 = np.sin(theta2 * np.pi / 180)
    c3 = np.cos(theta3 * np.pi / 180)
    s3 = np.sin(theta3 * np.pi / 180)

    
    if order=='xyz':
        matrix=np.array([[c2*c3, -c2*s3, s2],
                         [c1*s3+c3*s1*s2, c1*c3-s1*s2*s3, -c2*s1],
                         [s1*s3-c1*c3*s2, c3*s1+c1*s2*s3, c1*c2]])
  
    return matrix

The result rotationm atrix is: [![enter image description here][1]][1] that is correct.

Now, I want to go the opposite way. I want to transform that rotation matrix to euler angles, where I am using the following function:

def fromrotationmatrixtoeuler(R):
    

    r =  Rotation.from_matrix(R)
    angles = r.as_euler("xyz",degrees=True)
    return angles

The result that gives is: (-90,0,90) where does not match with the angles I am using.

Any idea of whats is wrong? What function should I use to transform from rotation matrix to XYZ intrinsic euler angles?

$\endgroup$

1 Answer 1

1
$\begingroup$

Assuming that Rotation is scipy.spatial.transform.Rotation, the seq string specifying the rotation convention is case-sensitive and uses capital letters for intrinsic rotations:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.transform.Rotation.as_euler.html

Parameters: seq: string, length 3
3 characters belonging to the set {‘X’, ‘Y’, ‘Z’} for intrinsic rotations, or {‘x’, ‘y’, ‘z’} for extrinsic rotations [1]. Adjacent axes cannot be the same. Extrinsic and intrinsic rotations cannot be mixed in one function call.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.