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

2023-09-06 09:44:30 作者:我于荒野驰骋

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);

CAD角度标注,提示两条线互相平行

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.