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.
这篇关于两条线之间的角度是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!