Computing arctan in the range $-\pi\leq \theta\leq\pi$

Solution 1:

The angles in the polar forms are all wrong.

The point $(-5.9, 2.9)_\text{Cartesian}$ is (1) in the 2nd quadrant, so has $\pi/2 = 1.57{\dots} < \theta < \pi = 3.14{\dots}$ and (2) is close to the point $(-6,3)_\text{Cartesian}$, which has polar angle $5\pi/6 = 2.6189{\dots}$.

If you just compute $\arctan(2.9/-5.9) = -0.45684{\dots}$, you can only get angles in quadrants 1 and 4 (because arctangent only gives angles in $(-\pi/2, \pi/2)$). Since tangent has period $\pi$, there is always another angle in quadrants 2 or 3 having the same arctangent. In this case, we use the signs of the coordinates to discover that the angle we want is in quadrant 2. To get from quadrant 4 to quadrant 2 (remaining in the interval of angles $[-\pi, \pi]$) we must add one copy of the period, $\pi$, obtaining $$ \arctan(2.9/-5.9) + \pi = 2.6847{\dots} \text{.} $$

If you had a point in quadrant 3, i.e., if both Cartesian coordinates are negative: To get to quadrant 3 from quadrant 1, remaining in the interval of angles $[-\pi,\pi]$, subtract $\pi$.

$(-2.9,6.1)_\text{Cartesian}$ should have polar angle $2.0145{\dots}$.

$(5.4,3.3)_\text{Cartesian}$ should have polar angle $0.54854{\dots}$. $(5.4,3.3)_\text{Cartesian}$ is between the $x$-axis and the line $y = x$, so should have a positive polar angle of less than $45^\circ = \pi/4 = 0.78539{\dots}$

$(-6.9,6.1)_\text{Cartesian}$ has polar angle $2.4176{\dots}$.