Python 欧拉角到旋转矩阵转换代码
以下是将欧拉角转换为旋转矩阵的 Python 代码:
import numpy as np
def euler_to_rotation_matrix(euler_angles):
'Converts Euler angles to rotation matrix.'
'param euler_angles: Array of Euler angles in radians.'
'return: Rotation matrix.'
roll, pitch, yaw = euler_angles
c1, s1 = np.cos(roll), np.sin(roll)
c2, s2 = np.cos(pitch), np.sin(pitch)
c3, s3 = np.cos(yaw), np.sin(yaw)
R = np.array([[c2*c3, c3*s1*s2 - c1*s3, s1*s3 + c1*c3*s2],
[c2*s3, c1*c3 + s1*s2*s3, c1*s2*s3 - c3*s1],
[-s2, c2*s1, c1*c2]])
return R
其中,euler_angles 是一个包含三个欧拉角的数组,分别表示绕 $x$、$y$、$z$ 轴的旋转角度。函数返回一个旋转矩阵 $R$,用于将向量旋转到新的坐标系中。
原文地址: https://www.cveoy.top/t/topic/lS72 著作权归作者所有。请勿转载和采集!