That's about as far as I've gotten too.
The main issue isn't the conversion, but the sin and cos functions, and their opposites asin and acos.
Mainly, I can't tell the difference between angles above 180 from angles below.
My brain's frying out on it, but here's a breakdown of sin and cos:
0 degrees:
sin = 0; cos = 1
90 degrees:
sin = 1; cos = 0
180 degrees:
sin = 0; cos = -1
270 degrees:
sin = -1; cos = 0
360 degrees:
sin = 0; cos = 1
If you'll allow me to think things through while typing...
If the sin is between 0 and 1, and the cos is between 1 and 0, the angle is between 0 and 90.
If the sin is between 1 and -1, and the cos is between 0 and -1, the angle is between 90 and 180.
Currently, this all works fine, due to the asin and acos functions.
However, I rely on those functions for the answer, and might have to do the math myself...
If the sin is between 0 and -1, and the cos is between -1 and 0, the angle is between 180 and 270.
Yet if the sin is between -1 and 0, and the cos is between 0 and 1, the angle is between 270 and 360/0.
In the end, I might just have to do a bunch of manual math based on the difference in sin and cos between 1 degree and 2 degree(the rate of change for a single degree)...
Okay, the rant's over...