美文网首页
旋转矩阵和欧拉角之间的相互转换代码

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

作者: 小黄不头秃 | 来源:发表于2024-04-06 15:50 被阅读0次
    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
    

    相关文章

      网友评论

          本文标题:旋转矩阵和欧拉角之间的相互转换代码

          本文链接:https://www.haomeiwen.com/subject/ahnatjtx.html