6

I need to rotate an object in a circle around a central point. All I know is the rotation of the centre point in degrees, the centre point location (Which will always be 0,0), and the object location (Well actually the object distance to the centre, but because the centre is 0,0 it is the same thing).

Why I want to do this is because I have a ship in the world and I can check for collisions for it, however when checking for if the CannonBall is colliding with the ship I cannot rotate the ship, meaning that to check for collisions I must instead rotate the CannonBall around the ship depending on the ship’s rotation.

(As you can see on my trailer (https://www.youtube.com/watch?v=2YU7oEUnwlw), I already attempted to implement this however have been unable to do it. Also I uploaded that video april 30, which means I have actually been having the issue for over a month.)

Seanny123
  • 169
  • It is rather difficult to tell what you want from your phraseology. I suggest that you give a very, very explicit example of the calculation that you are asking for. Among other things you say "I have got the rotation", but we do not know the format of your rotation, and without knowing that we will find it hard to give an answer in a format you can read. – Lee Mosher May 30 '14 at 14:55
  • @LeeMosher What is this "form of rotation" that you are asking about? :/ – user2722083 May 30 '14 at 14:56
  • You tell me. You wrote "I have got the rotation". Give it to us, explicitly. – Lee Mosher May 30 '14 at 14:57
  • @LeeMosher I am coding a game. It could be anything from 0 to 5000. I have no limitations on what the max/min rotation is. – user2722083 May 30 '14 at 14:58

1 Answers1

15

If your central point is $(c_x,c_y)$ and you want to rotate counter-clockwise about this point by an angle of $\theta$ (in radians) you would shift the center to the origin (and the rest of the points of the plane with it), then rotate, then shift back. You can use:

$x_{\text{rot}}=\cos(\theta)\cdot(x-c_x)-\sin(\theta)\cdot(y-c_y)+c_x$

$y_{\text{rot}}=\sin(\theta)\cdot(x-c_x)+\cos(\theta)\cdot(y-c_y)+c_y$

$(x,y)$ are your initial coordinates and $(x_\text{rot},y_{\text{rot}})$ are the new coordinates after rotation by $\theta$ about $(c_x,c_y)$

Example: If you want to rotate the point $(3,0)$ by $90^{\circ}$=$\frac{\pi}{2}$ radians about the point $(3,2)$ the formula should give $(5,2)$. Computing to check:

$x_{\text{rot}}=\cos(\frac{\pi}{2})\cdot(3-3)-\sin(\frac{\pi}{2})\cdot(0-2)+3=5$

$y_{\text{rot}}=\sin(\frac{\pi}{2})\cdot(3-3)+\cos(\frac{\pi}{2})\cdot(0-2)+2=2$

Ryan Vitale
  • 1,890