Méthode JavaScript atan2()Method
Exemple
Exemple 1 - atan2(y,x)
Spécifiez une coordonnée (x, y) avec les valeurs (4,8), utilisez la méthode atan2() pour calculer l'angle en radians entre la coordonnée et l'axe X, comme dans l'exemple suivant :
Math.atan2(8,4);
L'exemple ci-dessus produit :
1.1071487177940904
Définition et utilisation
atan2() renvoie l'angle plan (en radians) entre le segment de droite allant de l'origine (0,0) au point (x,y) et la direction positive de l'axe des x, c'est-à-dire,Math.atan2(y,x)。
Remarque :atan2() a deux paramètres, la coordonnée y est passée comme premier paramètre, et la coordonnée x est passée comme second paramètre.
Prise en charge des navigateurs
![]()
![]()
![]()
![]()
![]()
Tous les principaux navigateurs prennent en charge la méthode atan2().
Syntaxe
Math.atan2(y,x)
| Parameters | Description |
|---|---|
| y | Obligatoire. Un nombre représentant la coordonnée Y. |
| x | Obligatoire. Un nombre représentant la coordonnée x. |
Valeur de retour
| Type | Description |
|---|---|
| Number | La valeur d'arctangente de x. Renvoie une valeur numérique entre -PI et PI. Représente l'angle de décalage correspondant au point (x, y). Il s'agit d'un angle dans le sens antihoraire, en radians, entre l'axe X positif et la droite reliant le point (x, y) à l'origine. Notez que cette fonction accepte des paramètres : passez d'abord la coordonnée y, puis la coordonnée x. |
Détails techniques
| Version JavaScript : | 1.0 |
|---|
Plus d’exemples
Exemple
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 fini > 0.
Math.atan2( ±y, +Infinity ) // ±0 pour y fini > 0.
Math.atan2( ±Infinity, x ) // ±PI/2 pour x fini.
Math.atan2( ±Infinity, -Infinity ) // ±3*PI/4.
Math.atan2( ±Infinity, +Infinity ) // ±PI/4.
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 fini > 0.
Math.atan2( ±y, +Infinity ) // ±0 pour y fini > 0.
Math.atan2( ±Infinity, x ) // ±PI/2 pour x fini.
Math.atan2( ±Infinity, -Infinity ) // ±3*PI/4.
Math.atan2( ±Infinity, +Infinity ) // ±PI/4.
Autres extensions
Objet Math JavaScript