Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have coordinates center X, center Y. I also have myX and myY.

I'm writing a 2D game, and I need the second point to revolve around the first.

This involves finding the angle between the revolver and the "positive-x-axis" from the center point.

How can I do this?

share|cite|improve this question
If anyone is feeling charitable, they might want to take into account that the y axis is reversed. Increasing values move downwards on the screen....if this matters. I don't think it does, but if I knew any better, I wouldn't be asking. – Aerovistae Jun 10 '12 at 20:43
I'm not fully sure which angle you are talking about. But I am pretty sure you can solve your problem by applying the law of sines. – M.B. Jun 10 '12 at 20:47
Take a point on a Cartesian coordinate system. Draw a line, starting at this point and going out to the right. Now draw a point somewhere else. I need the angle between the line and the line which connects these two points. I think you are right, but I'm trying to figure out how to apply it so that it takes into account angles larger than 90 degrees, since this could be up to 360. – Aerovistae Jun 10 '12 at 20:51
I feel like there must be a cleverer way than just doing a 4-way conditional that adds 0, 90, 180, or 270 to the angle depending what quadrant the point is in, relative to the original point. – Aerovistae Jun 10 '12 at 20:53

An alternative approach would be to just rotate the 'my' point about the current point by some angle $\theta$ without computing the current angle. This avoids any 'fiddlyness' with $\arctan$. I am using the usual (in mathematics, not screens) axes here.

Let $c=\cos \theta$, $s=\sin \theta$. Let $(x,y)$ be the current point, and let $(x',y')$ be the 'my' point. Then to compute the rotated 'my' point, compute $$\binom{x_{my\_rotated}}{y_{my\_rotated}} = \binom{x}{y} + \begin{bmatrix} c & -s \\ s & c \end{bmatrix} \binom{x'-x}{y'-y}.$$

Or explicitly: $x_{my\_rotated} = x+c(x'-x)-s(y'-y)$, $y_{my\_rotated} = y+s(x'-x)+c(y'-y)$.

share|cite|improve this answer

Following Whocares notation, if the center is $A=(A_x,A_y)$ and the rotating point is $B=(B_x,B_y)$, you can use the atan2 function and ask for atan2$(B_x-A_x,B_y-A_y)$. It normally returns the angle in the range $(-\pi, \pi]$ and is in radians (check the documentation of your language), but it worries about all four quadrants for you. If you want to consider that the $y$ axis is going downward, you may have to reverse the sign

share|cite|improve this answer

I'll call the center point $A$ and the rotating point $B$. So $A=(A_x,A_y)$ and $B=(B_x,B_y)$

The equation you are looking for is $angle=\arctan((B_y-A_y)/(B_x-A_x))$

share|cite|improve this answer
See my comments above...I think this only goes up to 90. – Aerovistae Jun 10 '12 at 20:53
@Aerovistae: and only down to -90. But usually you get back radians. – Ross Millikan Jun 10 '12 at 22:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.