# We have angle=arctan(dy/dx), but what happens when dx=0?

Here is a formula: $\text{angle}=\arctan(dy/dx)$.

I can find an angle with my calculator for any value except $dx=0$.

My question is: is there no angle or, is there something that says when $dx=0$ the angle is found differently?

-
$\arctan(\infty)=\pi/2, \arctan(-\infty)=-\pi/2$ using the standard $\arctan$. (take a look at a graph). – yoyo Mar 15 '11 at 16:44
And the problem is, if you divide by zero, you don't know whether you get $\infty$ or $-\infty$ ... or maybe both, one from each side. ANYWAY, the angle is a right angle. – GEdgar Aug 22 '11 at 14:42

If $dx$ is $0$, if you look in the Cartesian plane, you are standing in the y-axis, so the angle would be $\frac{\pi}{2}$ or $\frac{3\pi}{2}$, depending if $dy > 0$ or $dy < 0$.

-

Since none of the answers have mentioned this, I'm putting this for completeness' sake: advanced calculators and computing environments provide for a "two-argument" arctangent function $\arctan(x,y)$ (denoted as atan2() in some environments, and with the order of the arguments sometimes reversed) that is especially intended for polar coordinate conversions. Briefly, $\arctan(x,y)$ gives the same results as $\arctan\frac{y}{x}$, adjusted when necessary so that the result is within $(-\pi,\pi]$, taking into account which quadrant the point $(x,y)$ is in. When $x=0$ and $y\neq 0$, $\arctan(0,y)=\frac{\pi}{2}\mathrm{sign}\,y$.

-

Actually, the $angle$ that a point in $R^2$ with cartesian coordinates $(x,y)\neq (0,0)$ makes with the positive x-axis is defined as the value $\theta (x,y)$ such that

$\cos \theta (x,y) = \frac{x}{\sqrt{x^2+y^2}}$ and

$\sin \theta (x,y) = \frac{y}{\sqrt{x^2+y^2}}$,

with $\theta\in [0, 2\pi)$. Note that, defined in this way, there is a unique $\theta$ for each point different from $(0,0)$.

If $x>0$ and $y>0$, these formulas combined give $\theta (x,y) = \arctan(y/x)$.

If $x=0$ and $y>0$, it follows from the definition that $\theta=\pi/2$.

You can also consider $\theta \in[-\pi,\pi)$, and in this case the formula $\theta (x,y) = \arctan(y/x)$ is valid for all $y$ provided $x>0$.

-

You are correct in pointing out that $$\theta = \arctan{\frac{y}{x}}$$ is not such a great formula, since it will not work when $x = 0$. In fact, $\arctan$ will always return a value in the interval $(-\pi/2, \pi/2)$, so it will give the wrong answer for the angle when $x < 0$! (Unless you don't care if the angle is pointing in the opposite direction from the vector.)

What you really want the unique angle $\theta$, say on the interval $[0, 2\pi)$, such that \begin{align*} \sin \theta = \frac{y}{\sqrt{x^2 + y^2}} \\ \cos \theta = \frac{x}{\sqrt{x^2 + y^2}}. \end{align*} What is the best way to calculate this? It's maybe not as elegant as you would like, but you can use $$\theta = \begin{cases} \arccos\left( \frac{x}{\sqrt{x^2 + y^2}} \right) &\text{if } y \ge 0 \\ 2\pi - \arccos\left( \frac{x}{\sqrt{x^2 + y^2}} \right) &\text{if } y \le 0. \end{cases}$$

-