Hello chili5

The mathematics required is very simple, but you'll have to look at the logic of the various possible positions of the pairs of points to solve the problem. I suggest you proceed as follows:

Suppose that the line joining the origin to the point $\displaystyle (x_1, y_1)$ makes an angle $\displaystyle \theta_1$ with the positive direction of the $\displaystyle x$-axis, measured clockwise, with $\displaystyle 0\le\theta<360^o$; and similarly for $\displaystyle (x_2, y_2)$ and $\displaystyle \theta_2$. Then the output angle is the difference between these two angles: $\displaystyle \theta_2 - \theta_1$; or, if this is negative, $\displaystyle 360^o +\theta_2 - \theta_1$.

So how do we find the angle $\displaystyle \theta_1$? The first thing to do is to calculate the acute angle that the line joining the origin to $\displaystyle (x_1, y_1)$ makes with the horizontal. If this angle is denoted by $\displaystyle \phi_1$, then $\displaystyle \phi_1=\arctan\left|\frac{y_1}{x_1}\right|$. Note that:You will need to check for $\displaystyle x_1=0$ to avoid a division by zero error.

If $\displaystyle x_1\ne0, 0\le\phi_1<90$.

Then the value of $\displaystyle \theta_1$ will depend upon which quadrant $\displaystyle (x_1, y_1)$ is in; as follows:QI: $\displaystyle x_1>0, y_1>0: \theta_1 = 360-\phi_1$

QII: $\displaystyle x_1<0, y_1>0: \theta_1 = 180+\phi_1$

QIII: $\displaystyle x_1<0, y_1<0: \theta_1 = 180-\phi_1$

QIV: $\displaystyle x_1>0, y_1<0: \theta_1 = \phi_1$

Also, if $\displaystyle x_1 = 0$ then:

If $\displaystyle y_1>0, \theta_1 = 270$

If $\displaystyle y_1<0, \theta_1 = 90$

Clearly you find $\displaystyle \phi_2, \;\theta_2$ in the same way.

I hope that makes sense. (Drawing a diagram should help to clarify things.)

Grandad