二维旋转矩阵公式推导

这篇博文来推导一下旋转矩阵。


首先来假设 OP1旋转到了OP2,逆时针矩阵推导。当然也有顺时针矩阵推导。

然后有没有什么办法可以不考虑顺时针逆时针?这里我考虑了一下OP1和OP2不相等的情况

因为先求的sin(theta),如果是逆时针,theta就是正值,如果是顺时针,theta就是负值。

 

之前我的想法,求theta,是先根据三角形的边长求夹角的公式求的cos(theta),然后sin(theta)就根据sqrt求。这种情况,必须提前判断逆时针旋转还是顺时针旋转,然后更改旋转矩阵。非常麻烦,也容易出错。

 

现在的想法,因为求的是sin(theta),sin(theta)的值就含有了顺时针还是逆时针的信息了。哈哈哈哈哈哈哈哈。

 

感谢大佬不吝赐教~

### 二维空间中旋转矩阵推导过程 在二维空间中,旋转矩阵是用来描述平面内任意一点绕原点旋转一定角度后的坐标的数学工具。假设平面上有一点 \( P(x, y) \),将其绕原点逆时针旋转角度 \( \theta \) 后得到新的点 \( P'(x', y') \)[^2]。 #### 坐标变换关系 设初始点 \( P(x, y) \) 的极坐标形式为: \[ x = r \cos(\phi), \quad y = r \sin(\phi), \] 其中 \( r \) 是该点到原点的距离,\( \phi \) 是该点与正 x 轴之间的夹角[^4]。 当这个点绕原点逆时针旋转角度 \( \theta \) 后,新点 \( P'(x', y') \) 可以通过更新其极坐标来获得: \[ x' = r \cos(\phi + \theta), \quad y' = r \sin(\phi + \theta). \] 利用三角函数的和差化积公式展开上述表达式: \[ x' = r (\cos(\phi)\cos(\theta) - \sin(\phi)\sin(\theta)), \] \[ y' = r (\sin(\phi)\cos(\theta) + \cos(\phi)\sin(\theta)). \] 代入原始直角坐标的关系 \( x = r \cos(\phi) \) 和 \( y = r \sin(\phi) \),可得: \[ x' = x \cos(\theta) - y \sin(\theta), \] \[ y' = x \sin(\theta) + y \cos(\theta). \] #### 矩阵表示形式 将以上两式的线性组合写成矩阵乘法的形式,则有: \[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}. \] 因此,在二维空间中的旋转可以通过以下旋转矩阵完成: \[ R = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{bmatrix}. \] #### 计算机图形学中的注意事项 需要注意的是,在计算机图形学领域,图像坐标系通常采用不同的定义方式(例如 y 轴向下),这可能导致实际应用中需要调整旋转方向或符号。 ```python import numpy as np def rotate_point_2d(point, theta): """ Rotate a point in 2D space by angle theta. Args: point (list): The original coordinates of the point [x, y]. theta (float): Rotation angle in radians. Returns: list: Rotated coordinates [x', y']. """ rotation_matrix = np.array([ [np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)] ]) rotated_point = np.dot(rotation_matrix, point).tolist() return rotated_point ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

keneyr

老爷~给小的赏点盘缠吧555~

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

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

打赏作者

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

抵扣说明:

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

余额充值