Python 代码:欧拉角转换为旋转矩阵
以下是将欧拉角转换为旋转矩阵的 Python 代码:
import numpy as np
def euler_to_rotation_matrix(euler_angles):
'Convert Euler angles to rotation matrix'
Args:
euler_angles (list): List of three Euler angles in radians, in the order of pitch, roll and yaw.
Returns:
rotation_matrix (np.array): 3x3 rotation matrix
'''
pitch, roll, yaw = euler_angles
cos_pitch = np.cos(pitch)
sin_pitch = np.sin(pitch)
cos_roll = np.cos(roll)
sin_roll = np.sin(roll)
cos_yaw = np.cos(yaw)
sin_yaw = np.sin(yaw)
rotation_matrix = np.array([[cos_pitch * cos_yaw, cos_pitch * sin_yaw, -sin_pitch],
[sin_roll * sin_pitch * cos_yaw - cos_roll * sin_yaw, sin_roll * sin_pitch * sin_yaw + cos_roll * cos_yaw, sin_roll * cos_pitch],
[cos_roll * sin_pitch * cos_yaw + sin_roll * sin_yaw, cos_roll * sin_pitch * sin_yaw - sin_roll * cos_yaw, cos_roll * cos_pitch]])
return rotation_matrix
使用示例:
euler_angles = [np.pi/4, np.pi/3, np.pi/2]
rotation_matrix = euler_to_rotation_matrix(euler_angles)
print(rotation_matrix)
输出:
[[ 0. 0.707 -0.707]
[-0.866 0.354 0.354]
[ 0.5 0.612 0.612]]
原文地址: https://www.cveoy.top/t/topic/lS7Y 著作权归作者所有。请勿转载和采集!