0

我正在使用以下内容来获取实体随着时间沿椭圆路径行进时的 x 和 y 位置:

x = Math.cos(time)*width/2
y = Math.sin(time)*height/2

有没有一种简单的方法可以将整个物体旋转一定的度数,例如 45 度或 132 度?

4

3 回答 3

3

您可以使用简单的旋转变换:

x1 = x*cos(a) - y*sin(a)
y1 = x*sin(a) + y*cos(a)

其中a- 是旋转的角度。

这篇维基百科文章详细解释了

于 2012-10-15T04:36:26.237 回答
1

对于您使用上述公式计算的每个点(x,y),您可以通过以下公式将其旋转 theta 度(逆时针)

  • x' = x * cos(theta) - y * sin(theta);
  • y' = x * sin(theta) + y * cos(theta);

其中 x 和 y 是旋转前的原始坐标,x' 和 y' 是旋转后的坐标,theta 是要旋转的角度。

坐标旋转

于 2012-10-15T04:43:01.813 回答
0

是的,只需对结果进行 2D 旋转xy旋转椭圆:

xrot = x * cos(A) - y * sin(A)
yrot = x * sin(A) + y * cos(A)

记住这一点Radians = Degrees * PI / 180

于 2012-10-15T04:37:04.287 回答