import numpy as np
import cv2
from PIL import Image, ImageDraw
import copy
from scipy.spatial.transform import Rotation as R
def eulerAnglesToRotationMatrix(theta):
# 将角度转换为弧度
theta_rad = np.radians(theta)
# 构造绕 x、y、z 轴的旋转矩阵
R_x = np.array([[1, 0, 0],
[0, np.cos(theta_rad[0]), -np.sin(theta_rad[0])],
[0, np.sin(theta_rad[0]), np.cos(theta_rad[0])]])
R_y = np.array([[np.cos(theta_rad[1]), 0, np.sin(theta_rad[1])],
[0, 1, 0],
[-np.sin(theta_rad[1]), 0, np.cos(theta_rad[1])]])
R_z = np.array([[np.cos(theta_rad[2]), -np.sin(theta_rad[2]), 0],
[np.sin(theta_rad[2]), np.cos(theta_rad[2]), 0],
[0, 0, 1]])
# 计算总的旋转矩阵
R = np.dot(R_z, np.dot(R_y, R_x))
return R
def rotation_matrix_to_euler_angles(rotation_matrix):
r = R.from_matrix(rotation_matrix)
euler_angles = r.as_euler('xyz', degrees=True)
return euler_angles
网友评论