4
$\begingroup$

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?

$\endgroup$

2 Answers 2

6
$\begingroup$

In your notation, $\operatorname{mod}(x,360)$ would put it in the range $0$ to $360$, and therefore, we can get what you need by $\operatorname{mod}(x+180,360)-180$, sending $x$ to the range $-180$ to $180$.

$\endgroup$
3
$\begingroup$

It might help to plot the graph of:

  • the function you currently have,
  • the function you'd like to have.

x % 360 and the desired function

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°$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .