1
$\begingroup$

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?

$\endgroup$
13
  • $\begingroup$ You said it, why bother ? $\endgroup$
    – user65203
    Jul 26, 2018 at 11:50
  • $\begingroup$ Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end $\endgroup$ Jul 26, 2018 at 11:53
  • $\begingroup$ 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. $\endgroup$
    – user65203
    Jul 26, 2018 at 11:55
  • 2
    $\begingroup$ The principal branch has $-\pi < \arctan2(x)\le \pi$. Your definition doesn't satisfy that condition. $\endgroup$
    – Mark Viola
    Jul 26, 2018 at 11:59
  • $\begingroup$ @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? $\endgroup$ Jul 26, 2018 at 12:05

1 Answer 1

3
$\begingroup$

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.

What really matters is that when taking the cosine and sine, the original signs are restored.


Whatever the convention, computing with angles is often tricky.

$\endgroup$

You must log in to answer this question.

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