본문 바로가기
프로그래머의 길/C & C++

atan2

by 제이콥케이 2008. 4. 22.
반응형

Name

atan2

Interface

#include <math.h>
double atan2 (double y, double x)
long atan2l (long double y, long double x)
float atan2f (float y, float x)

Description

The atan2 function computes the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value. It produces correct results even when the resulting angle is near \pi/2 or -\pi/2 (x near 0).
Example:
#include <stdio.h>
#include <math.h>
 
int main(void)
{
  double result, x=90.0, y=15.0;
  result = atan2(y, x);
  printf("The arc tangent ratio of %lf is %lf\n", (y/x), result);
  return 0;
}

Special Values

atan2 ( ±0, -0 ) returns ±pi.
atan2 ( ±0, +0 ) returns ±0.
atan2 ( ±0, x ) returns ±pi for x < 0.
atan2 ( ±0, x ) returns ±0 for x > 0.
atan2 ( ±0 ) returns -pi/2 for y > 0.
atan2 ( ±y, -∞ ) returns ±pi for finite y > 0.
atan2 ( ±y, +∞ ) returns ±0 for finite y > 0.
atan2 ( ±∞, +x ) returns ±pi/2 for finite x.
atan2 ( ±∞, -∞ ) returns ±3*pi/4.
atan2 ( ±∞, +∞ ) returns ±pi/4.

Notes

The atan2 function is used mostly to convert from rectangular (x,y) to polar (r, \theta ) coordinates that must satisfy x=r*cos(\theta ) and y=r*sin(\theta ). In general, conversions to polar coordinates should be computed thus:
(1)
\displaystyle r:= hypot(x,y) :=\sqrt{x^2 + y^2}
(2)
\displaystyle \theta := atan2(y,x)

See Also

acos, asin, atan, cos, cosh, sin, sinh, tan, tanh

Standards

The atan2 function conforms to ISO/IEC 9899:1999(E).
반응형

'프로그래머의 길 > C & C++' 카테고리의 다른 글

더 나은 코드 주석을 위한 13가지 팁  (0) 2008.04.22
CreateFile  (0) 2008.04.22
SetBkMode  (0) 2008.04.21
GetTextExtentPoint  (0) 2008.04.21
SetPixel, MoveToEx, LineTo( 그래픽 출력 함수 )  (0) 2008.04.21