绕xyz轴旋转的旋转矩阵
时间: 2024-12-27 09:21:11 浏览: 103
### 绕XYZ轴旋转的三维旋转矩阵
#### 绕X轴旋转的矩阵
当绕着X轴进行旋转时,主要影响的是Y和Z坐标。此时,保持X不变的情况下,可以得到如下形式的旋转矩阵:
\[
R_x(\theta)= \begin{bmatrix}
1 & 0 & 0 \\
0 & \cos{\theta} & -\sin{\theta}\\
0 & \sin{\theta}& \cos{\theta}
\end{bmatrix}
\]
此表达式展示了如何基于给定的角度θ调整其他两个维度的位置[^1]。
#### 绕Y轴旋转的矩阵
对于沿Y轴发生的旋转变换而言,则会影响X与Z坐标的数值变化。相应的旋转矩阵表示为:
\[
R_y(\theta)= \begin{bmatrix}
\cos{\theta} & 0& \sin{\theta}\\
0 & 1 & 0\\
-\sin{\theta} & 0 & \cos{\theta}
\end{bmatrix}
\]
这表明,在固定Y分量的同时,其余两部分按照指定角度发生位移变换[^2]。
#### 绕Z轴旋转的矩阵
最后来看围绕Z轴产生的转动效果,它会改变X和Y的方向而不干扰到自身的定位。对应的旋转矩阵写作:
\[
R_z(\theta)= \begin{bmatrix}
\cos{\theta} & -\sin{\theta} & 0\\
\sin{\theta} & \cos{\theta} & 0\\
0 & 0 & 1
\end{bmatrix}
\]
上述方程组清晰地反映了各元素间的关系以及它们随角度变动的趋势[^3]。
这些公式均可以从二维平面上的基础旋转概念推广而来,并且遵循相似的原则——即保留某一特定方向上的成分不变,而对其余两者应用正弦和余弦函数来进行计算处理[^4]。
```python
import numpy as np
def rotation_matrix(axis, theta):
"""
创建一个绕指定轴旋转的3D旋转矩阵
参数:
axis (str): 'x', 'y' 或者 'z'
theta (float): 以弧度为单位的角度
返回:
ndarray: 形状为(3, 3) 的numpy数组代表旋转矩阵
"""
c = np.cos(theta)
s = np.sin(theta)
if axis.lower() == "x":
R = np.array([[1, 0, 0],
[0, c,-s],
[0, s, c]])
elif axis.lower() == "y":
R = np.array([[c ,0,s ],
[0 ,1,0 ],
[-s,0,c ]])
elif axis.lower() == "z":
R = np.array([[c ,-s,0],
[s , c,0],
[0 , 0,1]])
else:
raise ValueError("Axis must be one of 'x','y' or 'z'")
return R
```
阅读全文
相关推荐


















