昨天跟 Claude 搏斗了好久,原来是我想错了,速速认错。


一个点 P(x,y)P(x,y)C(x0,y0)C(x_0,y_0)逆时针旋转 θ\theta,结果得到 P(x,y)P'(x',y') 满足:

P=C+R(PC)P'=C+R(P-C)

其中 RR 是二维旋转矩阵:

[cosθsinθsinθcosθ]\begin{bmatrix} \cos\theta && -\sin\theta \\ \sin\theta && \cos\theta \end{bmatrix}

或者直接展开得:

x=x0+(xx0)cosθ(yy0)sinθy=y0+(xx0)sinθ+(yy0)cosθx'=x_0 + (x-x_0)\cos\theta - (y-y_0)\sin\theta \\ y'=y_0 + (x-x_0)\sin\theta + (y-y_0)\cos\theta

我被“坑”的地方是对旋转矩阵的定义,或者说使用场景没有建立正确的认知,旋转矩阵作用的坐标,一定要是相对旋转中心的
在这个 case 中,旋转中心是 CC,所以要先通过 (PC)(P-C)PP 转换到旋转中心(点 CC)的坐标系下,计算完之后,重新恢复到原来的世界坐标系下。