We can get the angle between $x$ and $y$ (or $\cos{\theta}$ and $\sin{\theta}$ respectively) from $$ \theta =\tan^{-1}{\frac{y}{x}} $$ but only if $ -\frac{\pi}{2} < \theta < \frac{\pi}{2} $ since the cases with negative $x$ and/or $y$ exist where $$ \tan^{-1}{\frac{-y}{-x}} = \tan^{-1}{\frac{y}{x}} $$ and $$ \tan^{-1}{\frac{-y}{x}}=\tan^{-1}{\frac{y}{-x}}. $$ Let's also not ignore division by zero at $|\theta| = \pi/2$.

When coding, I can often (in many coding languages) do something like

theta = (y>=0)*arccos(x) + (y<0)*(2*pi - arccos(x))

where y>=0 and y<0 are boolean expressions that evaluate to $1$ or $0$ if the statements $y\geq 0$ and $y<0$ are true or false respectively, but this is not an expression I find easy to work with in pure math.

What is a good mathematical way to express the angle for all four quadrants as an expression/function of $x$ and $y$? Sometimes I might want a function that is differentiable, and then I don't think I want to involve boolean statements in the mathematics since I am not very experienced with that kind of math, but I am open-minded. It must be differentiable at least.


1 Answer 1


Many programming languages provide an atan2 function for this purpose.

It is, alas, not possible to have a single-valued function $\mathbb{R}^2\rightarrow \mathbb{R}$ which gives the angle and is differentiable everywhere: there is always a line (typically the negative $x$-axis, or the negative real axis if we're talking about arguments of complex numbers) where is is not differentiable.

  • $\begingroup$ You say that "it is not possible" to do this. Is there a proof or convincing example for this? $\endgroup$
    – dekuShrub
    May 2, 2018 at 12:11
  • 1
    $\begingroup$ Consider moving $360^{\circ}$ counterclockwise along a circle around the origin. Your hypothetical differentiable function is strictly increasing along this path (so you cannot end up at the same value you started with), but you end up where you started (so you must end up with the same value you started with): a contradiction. $\endgroup$
    – Wouter
    May 2, 2018 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.