I want to get angles between two line. So I used this code.
int posX = (ScreenWidth) >> 1;
int posY = (ScreenHeight) >> 1;
double radians, degrees;
radians = atan2f( y - posY , x - posX);
degrees = -CC_RADIANS_TO_DEGREES(radians);
NSLog(@"%f %f",degrees,radians);
But it doesn't work . The Log is that: 146.309935 -2.553590
What's the matter? I can't know the reason. Please help me.
解决方案If you simply use
radians = atan2f( y - posY , x - posX);
you'll get the angle with the horizontal line y=posY
(blue angle).
You'll need to add M_PI_2
to your radians value to get the correct result.