% rotationMatrix_to_eularAngle.m
clear all;close all;clear;clc;
%欧拉角
roll = pi/2;
pitch = pi/3;
yaw = pi/4;
angle_xyz = [roll pitch yaw];
angle_zyx = [yaw pitch roll];
%欧拉角转旋转矩阵
rMX = [1 0 0;
0 cos(roll) -sin(roll);
0 sin(roll) cos(roll)];
rMY = [cos(pitch) 0 sin(pitch);
0 1 0;
-sin(pitch) 0 cos(pitch)];
rMZ = [cos(yaw) -sin(yaw) 0;
sin(yaw) cos(yaw) 0;
0 0 1];
rotationMatrix_zyx = rMZ*rMY*rMX;
rotationMatrix_xyz = rMX*rMY*rMZ;
%旋转矩阵转欧拉角
roll_1 = atan2(rotationMatrix_zyx(3,2),rotationMatrix_zyx(3,3));
pitch_1 = atan2(-rotationMatrix_zyx(3,1),sqrt(rotationMatrix_zyx(3,2)^2+rotationMatrix_zyx(3,3)^2));
yaw_1 = atan2(rotationMatrix_zyx(2,1),rotationMatrix_zyx(1,1));
angle_1 = [roll_1 pitch_1 yaw_1];
angle_default_1 = rotm2eul(rotationMatrix_zyx);
angle_zyx_1 = rotm2eul(rotationMatrix_zyx,'ZYX');
angle_xyz_1 = rotm2eul(rotationMatrix_xyz,'XYZ');
assert(min(min(angle_xyz==angle_1))==1)
assert(min(min(angle_zyx==angle_default_1))==1)
assert(min(min(angle_default_1==angle_zyx_1))==1)
assert(min(min(angle_xyz==angle_xyz_1))==1)
04-04
9484
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)