TITLE: A formula to convert a counter-clockwise angle to clockwise angle with an offset
QUESTION [9 upvotes]: I have an angle in the coordinate system where $0^\circ$ is East, $90^\circ$ is North, $180^\circ$ is West, and $270^\circ$ is South.
I need to convert them to this one, where $0^\circ$ is North, $90^\circ$ is East, $180^\circ$ is South, and $270^\circ$ is West. Is there a determined algorithm to do this sort of transformation?

REPLY [2 votes]: A formula that you are asking:
$E=E_2-E_1$ and $N=N_2-N_1$, and is working for any value of $E$ and $N$.
$$f(E,N)=\pi-\frac{\pi}{2} \left(1+\text{sign }N\right)  (1-\text{sign }E^2)-\frac{\pi}{4} \left(2+\text{sign }N\right) \text{sign }E -\text{sign } (N E) \ \text{atan }\frac{\lvert N\rvert-\lvert E\rvert}{\lvert N\rvert+\lvert E\rvert}$$
The formula gives a clockwise angle from $0$-north to $2\pi$.