Python 代码:欧拉角转换为旋转矩阵
以下是将欧拉角转为旋转矩阵的 Python 代码:
import numpy as np
def euler_to_rotation_matrix(theta):
'Convert Euler angles to rotation matrix'
'param theta: Euler angles as a tuple (roll, pitch, yaw)'
'return: Rotation matrix'
roll, pitch, yaw = theta
Rx = np.array([[1, 0, 0],
[0, np.cos(roll), -np.sin(roll)],
[0, np.sin(roll), np.cos(roll)]])
Ry = np.array([[np.cos(pitch), 0, np.sin(pitch)],
[0, 1, 0],
[-np.sin(pitch), 0, np.cos(pitch)]])
Rz = np.array([[np.cos(yaw), -np.sin(yaw), 0],
[np.sin(yaw), np.cos(yaw), 0],
[0, 0, 1]])
R = np.dot(Rz, np.dot(Ry, Rx))
return R
其中,theta 是一个包含三个欧拉角(roll,pitch,yaw)的元组。函数返回一个 3x3 的旋转矩阵 R。欧拉角顺序为 ZYX(即 yaw-pitch-roll 顺序)。
原文地址: https://www.cveoy.top/t/topic/lS71 著作权归作者所有。请勿转载和采集!