二维旋转矩阵公式推导

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


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

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

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

 

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

 

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

 

感谢大佬不吝赐教~

### 2D 空间中的旋转矩阵公式及其解释 在二维空间中,旋转可以通过一个简单的线性变换来描述。假设有一个向量 \((x, y)\),它围绕原点逆时针旋转角度 \(\theta\) 后得到新的坐标 \((x', y')\)。这个过程可以用如下矩阵形式表示: \[ \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 (\cos\phi, \sin\phi)\),其中 \(r\) 是向量长度,\(\phi\) 是其与正方向之间的夹角。 - 当该向量绕原点顺时针或逆时针旋转一定角度 \(\theta\) 后,新位置的角度变为 \(\phi+\theta\) 或者 \(\phi-\theta\)(取决于旋转方向)。因此,新的坐标分量可由下述关系得出[^1]: \[ x' = r \cdot \cos(\phi + \theta), \quad y' = r \cdot \sin(\phi + \theta). \] 利用三角恒等式展开并整理得: \[ x' = x \cdot \cos\theta - y \cdot \sin\theta, \] \[ y' = x \cdot \sin\theta + y \cdot \cos\theta. \] 这正是前述矩阵乘法的结果。 以下是 Python 实现的一个简单例子展示如何应用此旋转矩阵计算给定点的新坐标。 ```python import numpy as np def rotate_2d_point(point, theta): """ Rotates a point around origin in 2D space. Parameters: point (tuple): Original coordinates (x, y). theta (float): Angle of rotation in radians. Returns: tuple: New rotated coordinates (x', y'). """ rot_matrix = np.array([ [np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)] ]) original_vector = np.array([[point[0]], [point[1]]]) new_coords = np.dot(rot_matrix, original_vector) return float(new_coords[0]), float(new_coords[1]) # Example usage original_point = (1, 0) # Point at unit distance along positive x-axis angle_degrees = 90 # Rotate by 90 degrees counterclockwise angle_radians = np.radians(angle_degrees) rotated_point = rotate_2d_point(original_point, angle_radians) print(f"Original Point: {original_point}, Rotated Point: {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、付费专栏及课程。

余额充值