Looking here the definition of the atan2
function is as follows:
$$\operatorname {atan2} (y,x)={ \begin{cases} \arctan(\frac {y}{x}) & \text{if }x>0,\\ \arctan(\frac {y}{x})+\pi & \text{if }x<0\text{ and }y\geq 0,\\ \arctan(\frac {y}{x})-\pi & \text{if }x<0\text{ and }y<0,\\ +\frac {\pi}{2} & \text{if }x=0\text{ and }y>0,\\ -\frac {\pi }{2} & \text{if }x=0\text{ and}y<0,\\ \text{undefined} & \text{if }x=0\text{ and }y=0. \end{cases}}$$
This looks wrong to me. Or at least, not wrong but rather there seems to be a small issue with it.
My Reasoning
I was trying to figure out a function (like $atan2$) that would solve the problem of the $arctan$ function. This is because I am writing a Python function to find the complex argument of a complex number, given real and imaginary part. Here is my reasoning:
Given a non-negative tangent value, this is mapped by the arctan only in the range $\left[0, \frac{\pi}{2}\right)$.
Given a non-positive tangent value, this is mapped by the arctan only in the range $\left[0, -\frac{\pi}{2}\right)$.
However, given a non-negative tangent value, there are two angles that could have that tangent value:
- $\arctan(\tan(\theta))$ which is an angle $\theta \in \left[0, \frac{\pi}{2}\right)$
- $\theta + \pi$ which is a diametrically opposite angle in the third quadrant, that is $\left[\pi, -\frac{3\pi}{2}\right)$
Similarly, given a non-positive tangent value, there are two angles that could have that tangent value:
- $\arctan(\tan(\theta))$ which is a negative angle in $\theta \in\left[0, -\frac{\pi}{2}\right)$
- $\theta + \pi$ which is diametrically opposite angle in the second quadrant, that is $\left(\frac{\pi}{2}, \pi\right]$
Thus, the definition of $atan2$ that I would use, would be:
$ \operatorname {atan2} (y,x)={ \begin{cases} \arctan(\frac {y}{x}) & \text{if }x>0,\\ \arctan(\frac {y}{x})+\pi & \text{if }x<0,\\ +\frac {\pi}{2} & \text{if }x=0\text{ and }y>0,\\ -\frac {\pi }{2} & \text{if }x=0\text{ and }y<0,\\ \text{undefined} & \text{if }x=0\text{ and }y=0. \end{cases} } $
Why does the Wikipedia definition subtract $\pi$ when we are in the third quadrant ($x<0$ and $y<0$)? If we do this, we end up with a negative angle! Yes sure, the negative angle would have the same sine, cosine and tangent of the angle obtained by summing $\pi$, but why bother?