C ++ atan2 () - C ++ Standardbibliothek

Die Funktion atan2 () in C ++ gibt die inverse Tangente einer Koordinate im Bogenmaß zurück.

Diese Funktion ist in der Header-Datei definiert.

(Mathematik) tan -1 (y / x) = atan2 (y, x) (In C ++ - Programmierung)

atan2 () Prototyp (Stand C ++ 11 Standard)

doppeltes atan2 (doppeltes y, doppeltes x); float atan2 (float y, float x); langes doppeltes atan2 (langes doppeltes y, langes doppeltes x); doppeltes atan2 (Typ1 y, Typ2 x); // Für Kombinationen von arithmetischen Typen.

atan2 () Parameter

Die Funktion atan2 () akzeptiert zwei Argumente: x-Koordinate und y-Koordinate.

  • x - Dieser Wert repräsentiert den Anteil der x-Koordinate.
  • y - Dieser Wert repräsentiert den Anteil der y-Koordinate.

atan2 () Rückgabewert

Die Funktion atan2 () gibt den Wert im Bereich von (-π, π) zurück . Wenn sowohl x als auch y Null sind, gibt die Funktion atan2 () 0 zurück.

Beispiel 1: Wie funktioniert atan2 () mit demselben Typ von x und y?

 #include #include 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 << " degrees" << endl; return 0; )

Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:

 atan2 (y / x) = -0,785398 Bogenmaß atan2 (y / x) = -45 Grad

Beispiel 2: Wie funktioniert atan2 () mit verschiedenen Arten von x und y?

 #include #include #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; // Display result in degrees cout << "atan2(y/x) = " << result*180/PI << " degrees"; return 0; ) 

Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:

 atan2 (y / x) = 3,04694 Radian atan2 (y / x) = 174,577 Grad

Interessante Beiträge...