English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
La funzione atan2() in C++ restituisce l'arco tangente dei coordinate in radianti.
Questa funzione<cmath>Definito nei file di intestazione.
tan-1(y/x) = atan2(y, x)
double atan2(double y, double x); float atan2(float y, float x); long double atan2(long double y, long double x); double atan2(Type1 y, Type2 x); // Utilizzato per combinazioni di tipi aritmetici.
La funzione atan2() ha due parametri: le coordinate x e y.
x -Questo valore rappresenta la proporzionalità dell'asse x.
y -Questo valore rappresenta la proporzionalità dell'asse y.
La funzione atan2() restituisce[-π, π]Valori nell'intervallo. Se x e y sono entrambi zero, la funzione atan2() restituirà 0.
#include <iostream> #include <cmath> using namespace std; int main() { double x = 10.0, y = -10.0, result; result = atan2(y, x); cout << "atan2(y/x) = " << result << " radians" << endl; cout << "atan2(y/x) = " << result*180/3.141592 << " gradi" << endl; return 0; }
運行該程序時,輸出為:
atan2(y/x) = -0.785398 radiani atan2(y/x) = -45 gradi
#include <iostream> #include <cmath> #define PI 3.141592654 using namespace std; int main() { double result; float x = -31.6; int y = 3; result = atan2(y, x); cout << "atan2(y/x) = " << result << " radians" << endl; //以度數表示的顯示結果 cout << "atan2(y/x) = " << result*180/PI << " degrees"; return 0; }
運行該程序時,輸出為:
atan2(y/x) = 3.04694 radianti atan2(y/x) = 174.577 gradi