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?
Best Answer
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)$.