help to calculate atan2 properly
atan2
returns results in [-180,180] (or -pi, pi in radians). To get results from 0,360 use:
float radians = atan2(dy, dx);
if (radians < 0) {
radians += M_PI*2.0f;
}
It should be noted that it is typical to express rotations in [-pi,pi] and thusly you can just use the result of atan2
without worrying about the sign.
Remove the fabs
call and simply make it:
CGFloat rads = atan2(dy, dx);