两条线之间的角度是错误的

bTa*_*ger 6 objective-c cocos2d-iphone

我想获得两条线之间的角度.所以我使用了这段代码.


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);
Run Code Online (Sandbox Code Playgroud)

但它不起作用.日志是:146.309935 -2.553590

怎么了?我不知道原因.请帮我.

在此输入图像描述

Man*_*lio 5

如果你只是使用

radians = atan2f( y - posY , x - posX);
Run Code Online (Sandbox Code Playgroud)

你会得到水平线的角度y=posY(蓝色角度).

在此输入图像描述

您需要添加M_PI_2弧度值才能获得正确的结果.