哪种围绕另一个点旋转一个点的方法最好?

Which method of rotating a point around a another point is best?

很长一段时间以来,我一直在简单地执行旋转:

setOrigin(screenWidth/2, screenHeight/2)
theta = approach(360)    // cycles from 0 to 360
cP = vec2(0, 0)          // center point
rp = vec2(0, 100)        // rotated point

rP.x = cP.x + cos(theta) * 100 //cos accepts degrees
rP.y = cP.y + sin(theta) * 100 //sin accepts degrees

但是我发现以下方法非常普遍

setOrigin(screenWidth/2, screenHeight/2)
theta = approach(360)    // cycles from 0 to 360
cP = vec2(0, 0)          // center point
rp = vec2(0, 100)        // rotated point

rPx = cP.x + (rP.x * cos(theta) - rP.y * sin(theta)) * 100 //cos accepts degrees
rPy = cP.y + (rP.y * sin(theta) + rP.x * cos(theta)) * 100 //sin accepts degrees
rP = {rPx, rPy}

我理解为什么第二个版本在数学上有效我只是不确定为什么 on 更喜欢它而不是更简单的第一个方法(除了将值放在矩阵中并执行转换的明显情况)

你的第一种方法是第二种方法的简化版本,你只允许差向量(从旋转中心到旋转点)是一条水平线。如果您插入 rp.y 而不是 100,您将看到您得到第二个变体的公式,其中 rp.x 部分被删除。

顺便说一句,第二个公式不太正确。 * 100 是错误的,因为您已经乘以 rp。在第二行中,您必须将 rp.yrp.x 交换为:

rPy = cP.y + (rP.x * sin(theta) + rP.y * cos(theta))