C-standard-library-c-function-atan2

提供:Dev Guides
移動先:案内検索

Cライブラリ関数-atan2()

説明

Cライブラリ関数* double atan2(double y、double x)は、正しい値を決定するために、両方の値の符号に基づいて *y/x のラジアンでアークタンジェントを返します。

宣言

以下は、atan2()関数の宣言です。

double atan2(double y, double x)

パラメーター

  • x -これは、x座標を表す浮動小数点値です。
  • y -これは、y座標を表す浮動小数点値です。

戻り値

この関数は、y/xの主アークタンジェントを[-pi、+ pi]ラジアンの間隔で返します。

次の例は、atan2()関数の使用法を示しています。

#include <stdio.h>
#include <math.h>

#define PI 3.14159265

int main () {
   double x, y, ret, val;

   x = -7.0;
   y = 7.0;
   val = 180.0/PI;

   ret = atan2 (y,x) * val;
   printf("The arc tangent of x = %lf, y = %lf ", x, y);
   printf("is %lf degrees\n", ret);

   return(0);
}

次の結果を生成する上記のプログラムをコンパイルして実行しましょう-

The arc tangent of x = -7.000000, y = 7.000000 is 135.000000 degrees