How can rotate an elliptical animation path by a c

2020-04-02 03:51发布

I'm using the following to get the x and y position of an entity as it travels along an elliptical path over time:

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

Is there a simple way to rotate the entire thing by a certain amount of degrees, say 45, or 132 for example?

3条回答
爷的心禁止访问
2楼-- · 2020-04-02 04:12

For each point(x, y) you calculated with above equation, you can rotate it theta degree(counter-clockwise) by the following equation

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

where x and y are the original coordinates before rotation, x' and y' are the coordinates after rotation, theta is the angle to rotate.

coordinate rotation

查看更多
戒情不戒烟
3楼-- · 2020-04-02 04:14

Yes, just do a 2D rotation on the resulting x and y to rotate your ellipse:

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

And remember that Radians = Degrees * PI / 180.

查看更多
Rolldiameter
4楼-- · 2020-04-02 04:22

You may use a simple rotation transformation:

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

Where a - is the angle to rotate.

This Wikipedia article explains that in detail

查看更多
登录 后发表回答