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]] 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?