反正切函数atan与atan2的区别

atan 和 atan2 都是求反正切函数,如:有两个点 point(x1,y1), 和 point(x2,y2);

那么这两个点形成的斜率的角度计算方法分别是:

float angle = atan( (y2-y1)/(x2-x1) );

float angle = atan2( y2-y1, x2-x1 );

 

 atan 和 atan2 区别:

1:参数的填写方式不同;

2:atan2 的优点在于 如果 x2-x1等于0 依然可以计算,但是atan函数就会导致程序出错;

 

结论: atan 和 atan2函数,建议用 atan2函数;

参考:https://blog.csdn.net/chinabinlang/article/details/6802686

posted @ 2018-03-29 21:07  feifanren  阅读(14117)  评论(0编辑  收藏  举报