旋轉(zhuǎn)矩陣和歐拉角之間的相互轉(zhuǎn)換代碼

import numpy as np
import cv2 
from PIL import Image, ImageDraw 
import copy
from scipy.spatial.transform import Rotation as R

def eulerAnglesToRotationMatrix(theta):
    # 將角度轉(zhuǎn)換為弧度
    theta_rad = np.radians(theta)

    # 構(gòu)造繞 x、y、z 軸的旋轉(zhuǎn)矩陣
    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]])
    # 計算總的旋轉(zhuǎn)矩陣
    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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容