--- title: Math.atan2() slug: Web/JavaScript/Reference/Global_Objects/Math/atan2 tags: - Arcotangente - JavaScript - Math - metodo translation_of: Web/JavaScript/Reference/Global_Objects/Math/atan2 ---
La funzione Math.atan2()
restituisce l'arcotangente del quoziente dei suoi argomenti.
Math.atan2(y, x)
y
x
L'arcotangente del quoziente degli argomenti forniti alla funzione, espresso in radianti e compreso tra -π e π.
Il metodo Math.atan2()
restituisce un valore compreso tra -π e π che reppresenta l'angolo teta di un punto (x, y)
. Questo angolo è orientato in senso antiorario, misurato in radianti e compreso tra l'asse positivo delle ascisse, ed il punto (x, y)
. È importante ricordare che il primo argomento da fornire alla funzione è l'ordinata del punto ed il secondo la sua ascissa.
A Math.atan2()
vengono passate x ed y separatamente, mentre a Math.atan()
deve essere passato il loro quoziente.
Poichè atan2()
è un metodo statico di Math
esso viene sempre utilizzato nella forma Math.atan2()
, invece che come metodo di un oggetto Math
che hai personalmente creato (Math
non è un costruttore).
Math.atan2()
Math.atan2(90, 15); // 1.4056476493802699 Math.atan2(15, 90); // 0.16514867741462683 Math.atan2(±0, -0); // ±PI. Math.atan2(±0, +0); // ±0. Math.atan2(±0, -x); // ±PI con x > 0. Math.atan2(±0, x); // ±0 con x > 0. Math.atan2(-y, ±0); // -PI/2 con y > 0. Math.atan2(y, ±0); // PI/2 con y > 0. Math.atan2(±y, -Infinity); // ±PI con y finito e y > 0. Math.atan2(±y, +Infinity); // ±0 con y finito e y > 0. Math.atan2(±Infinity, x); // ±PI/2 con x finito. Math.atan2(±Infinity, -Infinity); // ±3*PI/4. Math.atan2(±Infinity, +Infinity); // ±PI/4.
Specification | Status | Comment |
---|---|---|
{{SpecName('ES1')}} | {{Spec2('ES1')}} | Initial definition. Implemented in JavaScript 1.0. |
{{SpecName('ES5.1', '#sec-15.8.2.5', 'Math.atan2')}} | {{Spec2('ES5.1')}} | |
{{SpecName('ES6', '#sec-math.atan2', 'Math.atan2')}} | {{Spec2('ES6')}} | |
{{SpecName('ESDraft', '#sec-math.atan2', 'Math.atan2')}} | {{Spec2('ESDraft')}} |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |