aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/global_objects/math/atan2/index.md
blob: c95dd9050b2ed36898588e06590ee1d1adb73064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
title: Math.atan2()
slug: Web/JavaScript/Reference/Global_Objects/Math/atan2
tags:
  - JavaScript
  - Math
  - Méthode
  - Reference
translation_of: Web/JavaScript/Reference/Global_Objects/Math/atan2
original_slug: Web/JavaScript/Reference/Objets_globaux/Math/atan2
---
{{JSRef}}

La fonction **`Math.atan2()`** renvoie l'arc tangente du quotient de ses arguments.

{{EmbedInteractiveExample("pages/js/math-atan2.html")}}

## Syntaxe

    Math.atan2(y, x)

### Paramètres

- `x`
  - : La coordonnée en abscisse du point.
- `y`
  - : La coordonnée en ordonnée du point.

### Valeur de retour

L'arc tangente du quotient formé par les deux arguments, c'est-à-dire l'angle, exprimé en radians entre l'axe des abscisses et la droite passant par l'origin (0,0) et le point de coordonnées (x,y).

## Description

La méthode `Math.atan2()` renvoie une valeur numérique comprise entre -Pi et Pi qui représente l'angle theta d'un point de coordonnées (x,y). Cela correspond à l'angle (dans le sens trigonométrique) entre l'axe des abscisses et le point de coordonnées (`x,y`). Attention, le premier argument de la fonction est l'ordonnée (y) et le second est l'abscisse (x).

![Graphique explicitant l'angle donné par un point de coordonnées X/Y](https://mdn.mozillademos.org/files/11565/atan2.png)

`Math.atan2()` utilise deux arguments `x` et `y`, alors que la méthode `Math.atan()` utilise le ratio de deux nombres comme un seul argument.

`atan2()` est une méthode statique de l'objet `Math`, elle doit toujours être utilisée avec la syntaxe `Math.atan2()`, elle ne doit pas être utilisée comme la méthode d'un autre objet qui aurait été créé (`Math` n'est pas un constructeur).

## Exemples

### Utiliser `Math.atan2()`

```js
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 pour x > 0.
Math.atan2( ±0, x );                // ±0 pour x > 0.
Math.atan2( -y, ±0 );               // -PI/2 pour y > 0.
Math.atan2( y, ±0 );                // PI/2 pour y > 0.
Math.atan2( ±y, -Infinity );        // ±PI pour y qui est un nombre fini > 0.
Math.atan2( ±y, +Infinity );        // ±0 pour y qui est un nombre fini > 0.
Math.atan2( ±Infinity, x );         // ±PI/2 pour x qui est un nombre fini.
Math.atan2( ±Infinity, -Infinity ); // ±3*PI/4.
Math.atan2( ±Infinity, +Infinity ); // ±PI/4.
```

## Spécifications

| Spécification                                                                | État                         | Commentaires                                          |
| ---------------------------------------------------------------------------- | ---------------------------- | ----------------------------------------------------- |
| {{SpecName('ES1')}}                                                     | {{Spec2('ES1')}}         | Définition initiale. Implémentée avec 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')}} |                                                       |

## Compatibilité des navigateurs

{{Compat("javascript.builtins.Math.atan2")}}

## Voir aussi

- {{jsxref("Math.acos()")}}
- {{jsxref("Math.asin()")}}
- {{jsxref("Math.atan()")}}
- {{jsxref("Math.cos()")}}
- {{jsxref("Math.sin()")}}
- {{jsxref("Math.tan()")}}