How to change the angle origin of a circle?

348 Views Asked by At

I am using a Math library to get the Atan2 value between two points. The issue is that this library (Javascript) returns Atan2 as a value between $\pi$ and $-\pi$ .

Additionally, it calculates the angle getting larger when going counterclockwise (until $\pi$ is reached). See picture:

enter image description here

How can I change the "Angle origin" (or whatever the correct name for the 0 / 360 position is) so that instead of being at "3:00" (positive X), it is at "6:00", (negative Y)?

Additionally, what is the best way to change the $\pi$ /$-\pi$ to go from $0$ to $2\pi$?

So far, what I am doing is:

  • Calculate my angle using Atan2

  • Checking to see if the angle is less than zero, adding $2\pi$ if it is

  • Make the angle equal to $3\pi/2$

  • Checking to see if the angle is less than zero, adding $2\pi$ if it is

This works but seems like a roundabout way to do this. Specifically the two checks if the angle is negative. Is there a simpler way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

If you want the new angle measured clockwise from the negative $y$-axis then take $\frac32\pi - \theta$ which will be in the interval $\left[\frac{\pi}2 , \frac{5\pi}2\right)$, and if this is $2\pi$ or more then subtract $2\pi$.

Some computer languages might allow something like mod( pi*3/2 - theta, 2*pi ) to do this without a conditional statement