精度比acos , asin 什么的高些。
Parameters
-
y
- Value representing the proportion of the y-coordinate. x
- Value representing the proportion of the x-coordinate.
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