# Why subtract $\pi$ in the definition of atan2?

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?

• You said it, why bother ?
– user65203
Jul 26, 2018 at 11:50
• Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end Jul 26, 2018 at 11:53
• You reconvert the angle because you want to adopt a different convention, you can only blame yourself. The "standard" convention is not worse than another.
– user65203
Jul 26, 2018 at 11:55
• The principal branch has $-\pi < \arctan2(x)\le \pi$. Your definition doesn't satisfy that condition. Jul 26, 2018 at 11:59
• @MarkViola That! That is what explains everything! The principal branch of the complex number is defined within that interval because otherwise we could have multiple ones just by adding $2\pi$ multiples! Could you please write an answer for future reference? Jul 26, 2018 at 12:05

For consistency, the $\text{atan}_2$ values are defined in a range that equals a full period.
The usual choice is $(-\pi,\pi]$, but this is arbitrary and inessential, provided you know it.