两线之间的角度错误 [英] Angle between two lines is wrong

查看:93
本文介绍了两线之间的角度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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






  int posX =(ScreenWidth )>> 1; 

int posY =(ScreenHeight)>> 1;

双弧度,度;

弧度= atan2f(y-posY,x-posX);

度= -CC_RADIANS_TO_DEGREES(弧度);

NSLog(@%f%f,度,弧度);






但这不起作用。
日志是:146.309935 -2.553590



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



解决方案

如果您只是使用

  radians = atan2f(y-posY,x-posX); 

您将获得与水平线的角度 y = posY (蓝色角度)。





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


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.

这篇关于两线之间的角度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆