JavaScript Math atan2 ()

Die JavaScript-Funktion Math.atan2 () gibt den Arkustangens des Quotienten seiner Argumente zurück.

Die Syntax der Math.atan2()Funktion lautet:

 Math.atan2(y, x)

atan2()Da es sich um eine statische Methode handelt, wird sie mit dem MathKlassennamen aufgerufen .

Math.atan2 () Parameter

Die Math.atan2()Funktion umfasst:

  • y - Die Y-Koordinate des Punktes
  • x - Die X-Koordinate des Punktes

Rückgabewert von Math.atan2 ()

  • Gibt den Winkel im Bogenmaß zwischen und π zurück , der zwischen der positiven X-Achse und der Verbindungslinie (0, 0) und (x, y) gebildet wird .
  • Rückgabe NaNfür nicht numerische Argumente.

Beispiel: Verwenden von Math.atan2 ()

 var num = Math.atan2(1, 1); console.log(num); // 0.7853981633974483 (PI/4) var num = Math.atan2(4, 3); console.log(num); // 0.9272952180016122 var num = Math.atan2(0, 5); console.log(num); // 0 var num = Math.atan2(Infinity, 0); console.log(num); // 1.5707963267948966 (PI/2) var num = Math.atan2(-Infinity, 0); console.log(num); // -1.5707963267948966 (-PI/2) var num = Math.atan2(Infinity, -Infinity); console.log(num); // 2.356194490192345 (3*PI/4)

Ausgabe

 0,7853981633974483 0,9272952180016122 0 1,5707963267948966 -1,5707963267948966 2,356194490192345

Empfohlene Lektüre:

  • JavaScript Math tan ()
  • JavaScript Math atan ()

Interessante Beiträge...