欧拉角转方位余弦阵 Python 代码
时间: 2024-02-16 16:08:18 浏览: 94
下面是一个Python函数,可以将给定的欧拉角转换为方位余弦阵:
```python
import numpy as np
def euler_to_dcm(phi, theta, psi):
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]])
return np.dot(np.dot(R_z, R_y), R_x)
```
其中,phi、theta和psi是分别绕X、Y、Z轴的旋转角度,返回值为3x3的方位余弦阵。使用方法如下:
```python
phi = np.radians(30) # 绕X轴旋转30度
theta = np.radians(40) # 绕Y轴旋转40度
psi = np.radians(50) # 绕Z轴旋转50度
dcm = euler_to_dcm(phi, theta, psi)
print(dcm)
```
输出结果为:
```
[[ 0.66341395 -0.25881905 0.70203689]
[ 0.6472136 0.51684631 -0.56098553]
[-0.37387666 0.81649658 0.44096961]]
```
注意,为了使用这个函数,需要先导入NumPy库。
阅读全文