Universal formula for direction angle of a vector for any quadrant I was studying how to find the angle between the (positive) $X$-axis and a position vector for a program I'm making. And I came to the conclusion that there is no universal formula for that. If I use the following formula: $$\theta = \tan^{-1}\left(\frac yx\right)$$ I have to add a particular offset depending on the quadrant where the vector is. 
So I was wondering if there was another formula, another way to think about this problem, where the formula wouldn't have to change depending on the quadrant. It would be the universal formula for finding the angle. Google search didn't do any good.
Also is there a universal formula (in the sense mentioned above) for finding the angle between any two position vectors without having to offset the angle in any way?
I'm sorry for my bad English and my poor knowledge in Mathematics.
 A: You are clearly seeking for the two-argument inverse tangent function $\left(x,y\right)\mapsto\arctan\left(x,y\right)$.
Its main difference from the plain old $\tan^{-1}$ is precisely that it takes the quadrant of the point $\left(x,y\right)$ in $\mathbb{R}^2$ into account, which is lost when the usual one-argument arctangent function version is used like you first intended due to the identities $$\frac xy=\frac{-x}{-y}$$ and $$\frac{-x}y=\frac x{-y}$$ which arise when the usual one-argument inverse tangent function is used like follows: $$\arctan\left(x/y\right).$$
To mitigate the problem, instead use the two-argument version $\arctan\left(x,y\right)$, which in most languages is known as arctan2, atan2 or something similar.
A: There are many, but here is one.
If $x=y=0$ then $\theta$ is undefined.
Then 
\begin{equation}
\theta=\begin{cases}
       \frac{y}{|y|}\arccos\left(\frac{x}{\sqrt{x^2+y^2}}\right)\text{ if }y\ne 0\\
       \frac{\pi}{2}\left(\frac{x}{|x|}-1\right)\text{ if }x\ne0\text{ and }y=0
       \end{cases}
\end{equation}
This will give a result $-\pi<\theta\le \pi$.
A: A formula for the angle of a vector from 0 to 2pi.
f(x,y)=pi()-pi()/2*(1+sign(x))*(1-sign(y^2))
     -pi()/4*(2+sign(x))*sign(y)

     -sgn(x*y)*atan((abs(x)-abs(y))/(abs(x)+abs(y)))

The formula gives the angle for any value of x and y.
For x=y=0 the result is undefined.
