Python 代码:欧拉角转换为旋转矩阵
以下是将欧拉角转为旋转矩阵的 Python 代码:
import numpy as np
def euler_to_rotation_matrix(euler_angles):
'Convert Euler angles to rotation matrix.
euler_angles: [roll, pitch, yaw] in radians
'
roll, pitch, yaw = euler_angles
cos_roll = np.cos(roll)
sin_roll = np.sin(roll)
cos_pitch = np.cos(pitch)
sin_pitch = np.sin(pitch)
cos_yaw = np.cos(yaw)
sin_yaw = np.sin(yaw)
rotation_matrix = np.array([
[cos_yaw * cos_pitch, cos_yaw * sin_pitch * sin_roll - sin_yaw * cos_roll,
cos_yaw * sin_pitch * cos_roll + sin_yaw * sin_roll],
[sin_yaw * cos_pitch, sin_yaw * sin_pitch * sin_roll + cos_yaw * cos_roll,
sin_yaw * sin_pitch * cos_roll - cos_yaw * sin_roll],
[-sin_pitch, cos_pitch * sin_roll, cos_pitch * cos_roll]])
return rotation_matrix
其中,欧拉角的定义为:
- Roll:绕x轴旋转,范围为[-π, π]。
- Pitch:绕y轴旋转,范围为[-π/2, π/2]。
- Yaw:绕z轴旋转,范围为[-π, π]。
旋转矩阵的定义为:
$$\begin{bmatrix}\r_{11} & r_{12} & r_{13} \r_{21} & r_{22} & r_{23} \r_{31} & r_{32} & r_{33}\end{bmatrix}$$
其中,$r_{ij}$表示第$i$行第$j$列的元素。
原文地址: https://www.cveoy.top/t/topic/lS73 著作权归作者所有。请勿转载和采集!