When finding the direction angle with the formula $\theta = \tan^{-1} \left(\frac{y}{x}\right )$, when do you add $180$ degrees to the answer? Is it whenever the $x$ is negative, when the angle is in the third or fourth quadrant (if this is the case, how would I know the angle is there?), or just in the third quadrant (if this is the case, how would I know the angle is there)? Or something else entirely?
-
1Did you try drawing a picture (one for each case)? In that picture (that you are going to draw), when is the angle $0$? When is it $180$? – megas Mar 10 '15 at 04:14
-
The issue is that ${y \over x} = {-y \over -x}$ so $\arctan$ does not distinguish quadrants $Q_1, Q_3$ or $Q_2, Q_4$. – copper.hat Mar 10 '15 at 04:55
2 Answers
If you look at this table in the Wikipedia article, you will see that in the arctangent row, the "range of usual principal value" is given as $-90^\circ<y<90^\circ$.
This means that if you give a number to the arctangent function, most calculators respond with an answer between $-90^\circ$ and $90^\circ$. This is the half-plane on the right, quadrants I and IV, so $x$ is assumed positive.
If $x$ is negative, the answer you want is $180^\circ$ away.

- 3,672
Andrew Woods' answer is correct, but let me offer another way to compute $\theta$.
As shown in this answer, $$ \begin{align} \tan(\theta/2) &=\frac{\sin(\theta)}{1+\cos(\theta)}\\ &=\frac{\frac yr}{1+\frac xr}\\[3pt] &=\frac{y}{x+r} \end{align} $$ which leads to the formula $$ \bbox[5px,border:2px solid #C0A000]{\theta=2\arctan\left(\vcenter{\frac y{x+\sqrt{x^2+y^2}}}\right)} $$
which is valid as long as $x+\sqrt{x^2+y^2}\ne0$; that is, $y\ne0$ or $x\gt0$.
Verification
Since $\tan(2x)=\frac{2\tan(x)}{1-\tan^2(x)}$, $$ \begin{align} \tan(\theta) &=\frac{2\frac y{x+\sqrt{x^2+y^2}}}{1-\left(\frac y{x+\sqrt{x^2+y^2}}\right)^2}\\ &=\frac{2y\left(x+\sqrt{x^2+y^2}\right)}{2x^2+2x\sqrt{x^2+y^2}}\\[12pt] &=\frac yx \end{align} $$

- 345,667
-
-
You mean when $y=0$ and $x\lt0$? In that case, you can take either $\pi$ or $-\pi$, whichever is your preference. When $x\lt0$, if you take $y\gt0$, but very small, you will get something slightly less than $\pi$; if you take $y\lt0$, but very small, you will get something slightly greater than $-\pi$. – robjohn Mar 20 '22 at 22:28
-
I meant: if I have a point (-1, 1) the result is 1.230959. And if I have a point(1, 1) the result is the same. I'm doing this C formula
angle = 2 * atanl(sY / ( x + sqrtl( (sX*sX) + (sY*sY) )));
. Am I missing something? – Olivier Pons Mar 20 '22 at 23:04 -
For $(-1,1)$, I get $2\tan^{-1}\left(\frac1{-1+\sqrt{2}}\right)=2.35619449$. For $(1,1)$, I get $2\tan^{-1}\left(\frac1{1+\sqrt{2}}\right)=0.7853981634$. – robjohn Mar 20 '22 at 23:36
-
1@OlivierPons: It looks as if your
x
should be ansX
. If I put $0$ in where you havex
, I get the same thing as you got. – robjohn Mar 20 '22 at 23:46