1
$\begingroup$

I'm trying to come up with a good conversion formula to go from one definition of angles in a circle to another.

In the origin system, zero is up, 90 is right, 180 is down, 270 is left.

In the target system, zero is right, -90 is down, +/- 180 is left, 90 is up.

Going backwards is easy: y=(-x+90)%360. Can anyone figure out how to go forwards in a single equation?

$\endgroup$
5
  • $\begingroup$ The exact same equation should work $\endgroup$
    – Mohit
    Jul 22, 2017 at 4:17
  • $\begingroup$ @Mohit Nope, it won't. It won't ever result in a negative number, thanks to the mod. $\endgroup$ Jul 22, 2017 at 4:26
  • $\begingroup$ y = -x + 90 should work without the mod 360 $\endgroup$
    – Mohit
    Jul 22, 2017 at 15:19
  • $\begingroup$ @Mohit It works for the first three quadrants, but for origin angles > 270, 90-x results in numbers smaller than -180. $\endgroup$ Jul 23, 2017 at 1:35
  • $\begingroup$ Oh, sorry you are right. I only tried 0,90,180,270. $\endgroup$
    – Mohit
    Jul 23, 2017 at 3:50

1 Answer 1

0
$\begingroup$

In the origin system, zero is up, 90 is right, 180 is down, 270 is left.

Let $\,\alpha \in [0, 360)\,$ be this angle.

In the target system, zero is right, -90 is down, +/- 180 is left, 90 is up.

Let $\,\beta\,$ be this angle, but the +/- 180 part makes it ambiguous whether you mean the target angle to be $\beta \in (-270,90]$ vs. $\beta \in (-180,180]\,$:

  • if you mean $\,\beta \in (-270,90]\,$, then just use $\,\beta = 90 - \alpha\,$;

  • if you mean $\,\beta \in (-180,180]\,$, then use $\,\beta = 180 - (\alpha + 90) \;\%\; 360\,$.

$\endgroup$
3
  • $\begingroup$ That's the conclusion I came to. I'm hoping there's a single equation solution, though. $\endgroup$ Jul 23, 2017 at 1:36
  • $\begingroup$ @BenEtherington It is a single equation solution, once you clarify which one of the two you want the target range of $\beta$ to be. For example, if you want $\beta$ to be in $(-180,180]$ then the only equation you need to use is the one listed under the second case: $\,\beta = 180 - (\alpha + 90) \;\%\; 360\,$. $\endgroup$
    – dxiv
    Jul 23, 2017 at 1:38
  • 1
    $\begingroup$ Oh, sorry, I read too quickly. I see what you mean, yes, you nailed it! Thank you! $\endgroup$ Jul 23, 2017 at 1:45

You must log in to answer this question.

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