旋转矩阵和欧拉角之间的相互转换代码

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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容