Funkcja JavaScript Math.atan2 () zwraca arcus tangens ilorazu swoich argumentów.
Składnia Math.atan2()
funkcji to:
Math.atan2(y, x)
atan2()
jako metoda statyczna jest wywoływana przy użyciu Math
nazwy klasy.
Math.atan2 () Parametry
Math.atan2()
Funkcja przyjmuje się:
- y - współrzędna Y punktu
- x - współrzędna X punktu
Wartość zwracana z Math.atan2 ()
- Zwraca kąt w radianach między -π i π , utworzony między dodatnią osią X a linią łączącą (0, 0) i (x, y) .
- Zwraca
NaN
argumenty nienumeryczne.
Przykład: użycie 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)
Wynik
0,7853981633974483 0,9272952180016122 0 1,5707963267948966 -1,5707963267948966 2,356194490192345
Zalecane lektury:
- JavaScript Math tan ()
- JavaScript Math atan ()