--- title: Math.atan2() slug: Web/JavaScript/Reference/Global_Objects/Math/atan2 translation_of: Web/JavaScript/Reference/Global_Objects/Math/atan2 original_slug: Web/JavaScript/Referencia/Objectes_globals/Math/atan2 ---
La funció Math.atan2() retorna l'arctangent del quocient dels arguments passats.
Math.atan2(y, x)
yxEl mètode Math.atan2() retorn aun valor numèric entre -π i π que representa l'angle theta d'un punt (x, y). Aquest angle es representa en radiants, en sentit contrari a les agulles del rellotge, entre l'eix positiu X i el punt (x, y). Cal destacar que els arguments d'aquesta funció representen les coordenades del punt, on el primer argument representa la coordenada y i el segon argument representa la coordenada x.
Math.atan2() rep els arguments x i y de forma separada mentre que Math.atan() rep la relació (ratio) entre aquests dos arguments.
Com que que atan2() és un mètode estàtic de Math, sempre s'utilitza com a Math.atan2(), en comptes de com a mètode d'una instància de Math (Math no és un constructor).
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 for x > 0. Math.atan2(±0, x); // ±0 for x > 0. Math.atan2(-y, ±0); // -PI/2 for y > 0. Math.atan2(y, ±0); // PI/2 for y > 0. Math.atan2(±y, -Infinity); // ±PI for finite y > 0. Math.atan2(±y, +Infinity); // ±0 for finite y > 0. Math.atan2(±Infinity, x); // ±PI/2 for finite x. Math.atan2(±Infinity, -Infinity); // ±3*PI/4. Math.atan2(±Infinity, +Infinity); // ±PI/4.
| Especificació | Estat | Comentaris |
|---|---|---|
| {{SpecName('ES1')}} | {{Spec2('ES1')}} | Definició inicial. Implementat a 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')}} |
| Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Suport bàsic | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
| Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Suport bàsic | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |