坐标旋转矩阵推导

博客围绕自动驾驶展开,虽未给出具体内容,但从标签可知核心为自动驾驶相关信息技术。自动驾驶涉及感知系统、车路协同等多方面技术。

### 三维与二维旋转矩阵的数学推导过程 旋转矩阵是描述空间中物体旋转的一种数学工具,广泛应用于计算机图形学、机器人学以及游戏开发等领域。旋转矩阵推导可以从二维空间开始,再扩展到三维空间。 #### 二维坐标系的旋转 在二维空间中,一个 $ P = (x, y) $ 绕原逆时针旋转角度 $ \theta $ 后的新坐标 $ P' = (x', y') $ 可以通过三角函数关系得出: $$ \begin{aligned} x' &= x\cos\theta - y\sin\theta \\ y' &= x\sin\theta + y\cos\theta \end{aligned} $$ 将上述变换写成矩阵形式,可以得到二维旋转矩阵: $$ P' = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} P $$ 这一矩阵形式便于进行连续旋转操作和与其他变换矩阵的组合[^4]。 #### 三维坐标系的旋转 在三维空间中,旋转可以围绕任意轴进行,但为了简化分析,通常考虑绕坐标轴(X、Y、Z)的旋转。 ##### 绕Z轴旋转 在三维空间中,绕Z轴旋转与二维旋转相同,Z坐标保持不变。设 $ P = (x, y, z) $ 绕Z轴旋转角度 $ \theta $,其变换公式为: $$ \begin{aligned} x' &= x\cos\theta - y\sin\theta \\ y' &= x\sin\theta + y\cos\theta \\ z' &= z \end{aligned} $$ 对应的旋转矩阵为: $$ R_z(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix} $$ ##### 绕X轴旋转(俯仰角 Pitch) 绕X轴旋转时,Y和Z坐标发生变化,X保持不变。设旋转角度为 $ \theta $,则: $$ \begin{aligned} y' &= y\cos\theta - z\sin\theta \\ z' &= y\sin\theta + z\cos\theta \\ x' &= x \end{aligned} $$ 对应的旋转矩阵为: $$ R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta \\ 0 & \sin\theta & \cos\theta \end{bmatrix} $$ ##### 绕Y轴旋转(偏航角 Yaw) 绕Y轴旋转时,X和Z坐标发生变化,Y保持不变。设旋转角度为 $ \theta $,则: $$ \begin{aligned} x' &= x\cos\theta + z\sin\theta \\ z' &= -x\sin\theta + z\cos\theta \\ y' &= y \end{aligned} $$ 对应的旋转矩阵为: $$ R_y(\theta) = \begin{bmatrix} \cos\theta & 0 & \sin\theta \\ 0 & 1 & 0 \\ -\sin\theta & 0 & \cos\theta \end{bmatrix} $$ #### 任意旋转 在实际应用中,旋转中心可能不在原。此时需要先将物体平移到原,执行旋转后再平移回原位置。设旋转中心为 $ (x, y) $,则变换过程为: $$ v' = T(x, y) \cdot R \cdot T(-x, -y) \cdot v $$ 其中 $ T(x, y) $ 为平移矩阵,$ R $ 为旋转矩阵[^3]。 #### 示例代码:二维旋转矩阵计算 ```python import numpy as np def rotation_matrix_2d(theta): theta = np.radians(theta) return np.array([ [np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)] ]) # 示例:绕原旋转30度 R = rotation_matrix_2d(30) print("二维旋转矩阵:") print(R) ``` #### 示例代码:三维绕Z轴旋转矩阵计算 ```python def rotation_matrix_z(theta): theta = np.radians(theta) return np.array([ [np.cos(theta), -np.sin(theta), 0], [np.sin(theta), np.cos(theta), 0], [0, 0, 1] ]) # 示例:绕Z轴旋转45度 R_z = rotation_matrix_z(45) print("绕Z轴旋转矩阵:") print(R_z) ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zack_Liu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值