#include <math.h>
|
double
atan2 (double y, double x); |
float
atan2f (float y, float x); |
long double
atan2 (long double y, long double x); |
atan (y/x, Ta); if x > 0, |
|
sign( y )*(pi - |
atan (\*(Bay/x\*(Ba, ), Ta); if x < 0, |
0 if x = y = 0, or | |
sign( y )*\*(Pi/2 if x = 0 != y. | |
#include <math.h> int main( void ) { double x1 = -862.42, x2 = 78.5149, y; y = atan2( x1, x2 ); printf( "atan2(%f , %f) = %f\n", x1, x2, y ); y = atan2f( x1, x2 ); printf( "atan2f(%f , %f) = %f\n", x1, x2, y ); y = atan2l( x1, x2 ); printf( "atan2l(%f , %f) = %f\n", x1, x2, y ); }
Output
atan2( -862.42, 78.5149 ) = -1.480006 atan2f( -862.42, 78.5149 ) = -1.480006 atan2l( -862.42, 78.5149 ) = -1.480006
(r=0,th=0). In general, conversions to polar coordinates should be computed thus:
r := hypot(x,y); ... := sqrt(x*x+y*y) theta := atan2(y,x). r := hypot(x,y); ... := v/(x20+y20) th := atan2(y,x).
r := sqrt(x*x+y*y); if r = 0 then x := copysign(1,x); r := v/(x*x+y*y); if r = 0 then x := copysign(1,x);
The atan2 function conforms to -isoC.
© 2005-2007 Nokia |