Finding the angle between two points

The atan2 function is an extended version of the trigonometric inverse tangent function. In the figure below, $\tan{\theta}=y/x$, so $\tan^{-1}{y/x}=\theta$. The atan2 function just calculates $\tan^{-1}{y/x}$ with y and x as separate parameters. The reason it does so is to give a more accurate answer: since the tangent function is periodic, there are multiple values of x and y that would appear to have the same angle (but do not). Also, atan2 provides the correct values when y/x is undefined, such as at $\pi/2$.

atan2 diagram

Another way to find the angle you're looking for is to use vectors. Using the x-axis as one of the vectors and $\vec{OP}$ as another one, you could use the formula

$$\cos{\theta}=\frac{u\cdot v}{||u||\times||v||}$$

Note that whichever way you use, you need two lines to measure an angle. You would have to choose a reference line to measure the angle $\theta$ with; most commonly one would use the x-axis.