How can rotate an elliptical animation path by a c

2020-04-02 03:44发布

问题:

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?

回答1:

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



回答2:

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:

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.