标签:
精度比acos , asin 什么的高些。
If both arguments passed are zero, a domain error occurs.
所以使用前只需排除x=y=0的情况
例子:
/* atan2 example */ #include <stdio.h> /* printf */ #include <math.h> /* atan2 */ #define PI 3.14159265 int main () { double x, y, result; x = -10.0; y = 10.0; result = atan2 (y,x) * 180 / PI; printf ("The arc tangent for (x=%f, y=%f) is %f degrees\n", x, y, result ); return 0; }
结果:
The arc tangent for (x=-10.000000, y=10.000000) is 135.000000 degrees.
返回值为(-PI,PI]的例子
printf("%lf",atan2(0,-1)*180/PI); 输出:180.000000
计算点与x轴正半轴夹角atan2(double y,double x),返回弧度制(-PI,PI]
标签:
原文地址:http://www.cnblogs.com/chenhuan001/p/5087574.html