Given a vector going from a point $(x_0,y_0)$ to $(x_1,y_1)$ in a regular 2D-plane (i.e. an $\hat{x}$-axis pointing right and a $\hat{y}$-axis pointing up), I want to determine the angle between the vector and the $\hat{x}$-axis.
When the vector is in the first and second quadrant, the angle should be between $[0,-\pi]$, and between $[0,\pi]$ when it is in the third and forth quadrant. To clarify, a vector pointing in positive and negative $\hat{y}$-direction should have angle $-\frac{\pi}{2}$ and $\frac{\pi}{2}$, respectively.
What is the expression for the angle?
The angle from the vector to the $x$ axis is equal to minus of the angle between the $x$ axis and the vector. You have for this second angle $$\tan\theta=\frac{y_1-y_0}{x_1-x_0}$$ The first guess would be to use the arctangent. Notice that if you take the ratio, you cannot distinguish between angles in quadrants $2$ and $4$, or between angles in quadrants $1$ and $3$. For many computer programming languages, there is a function called $\rm{atan2}$ or $\rm{arctan2}$. The arguments are $y_1-y_0$ and $x_1-x_0$. You can find a formal description on wikipedia.