首页  >  文章  >  数据库  >  atan函数与atan2函数的一点区别

atan函数与atan2函数的一点区别

WBOY
WBOY原创
2016-06-07 15:49:322023浏览

atan 和 atan2 都是求反正切函数,如:有两个点 point(x1,y1), 和 point(x2,y2); 那么这两个点形成的斜率的角度计算方法分别是: floatangle = atan( (y2-y1)/(x2-x1) ); 或 float angle = atan2( y2-y1, x2-x1); atan 和 atan2 区别: 1:参数的填写方式不

 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函数;

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn