Converting angles to the range $ -180$ deg through $180$ deg Is there a direct formula to transform a set of angles to $-180$ through $180$ deg? For instance, $181$ deg and $541$ deg should be translated to $-179$, while $-182$ deg and $-542$ deg should be translated to $178$. I know that for an angle $X$ which is not on any axis ($0, 90, 270, 360, ...$), when $\text{mod}(a,b)$ is the remainder of division of $a$ by $b$, we can write use $k = \lfloor(\frac{\text{mod}(X,360)}{90})\rfloor$ to determine the quadrant where angle $X$ resides since $k = 0, 1, 2, 3$ corresponds to quadrants $1, 2, 3, 4$ respectively. So for angle $X$:

$k = 0$ or $1$: $\text{mod}(X,360)$ gives the $0$ through $180$ range.
$k = 2$ or $3$: $\text{mod}(X,360)-360$ gives $-180$ through $0$ range.

Is there a way to make this simpler?

It might help to plot the graph of:

*

*the function you currently have,

*the function you'd like to have.


Notice that you just need to translate one graph in order to get the other.
If you want to move a graph to the left or to the right, you can adjust it with $f(x \pm \Delta_x)$.
If you want to move a graph up or down, you can adjust it with $f(x) \pm \Delta_y$.
To get the desired graph, you need to move it to the left or right by $180°$ (or $540°$, or $900°$, since it's periodic), and down by $180°$.
