以下是将欧拉角转换为旋转矩阵的 Python 代码:

import numpy as np

def euler_to_rotation_matrix(euler_angles):
    # Convert Euler angles to radians
    phi = euler_angles[0] * np.pi / 180
    theta = euler_angles[1] * np.pi / 180
    psi = euler_angles[2] * np.pi / 180

    # Calculate the rotation matrix
    R_x = np.array([[1, 0, 0],
                    [0, np.cos(phi), -np.sin(phi)],
                    [0, np.sin(phi), np.cos(phi)]])

    R_y = np.array([[np.cos(theta), 0, np.sin(theta)],
                    [0, 1, 0],
                    [-np.sin(theta), 0, np.cos(theta)]])

    R_z = np.array([[np.cos(psi), -np.sin(psi), 0],
                    [np.sin(psi), np.cos(psi), 0],
                    [0, 0, 1]])

    R = np.dot(R_z, np.dot(R_y, R_x))

    return R

其中,输入参数euler_angles是一个包含三个欧拉角的列表,分别对应三个旋转轴的旋转角度,单位为度。输出为一个3x3的旋转矩阵。


原文地址: https://www.cveoy.top/t/topic/lS75 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录