# How can I rotate a coordinate around a circle?

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.)

• 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

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$

• I just saw you made an edit to the post saying the center is the origin, so put c_x=c_y=0 into the formula – rVitale May 30 '14 at 15:00
• also if you need to do rigid motions like this a lot for computer graphics you can learn some linear algebra and use matrix multiplication to do this kind of thing easily. – rVitale May 30 '14 at 15:04
• Thanks! :) Sorry for being stupid, but what are those ⋅ symbols in the middle of your xRot formula? – user2722083 May 30 '14 at 15:04
• oh, it's multiplication. I think it's confusing since I left them out a few places. I'll fix that. – rVitale May 30 '14 at 15:06
• It worked! Thank you so much! I have literally been trying to do this for over a month. – user2722083 May 30 '14 at 17:22