The Math.atan()
static method returns the inverse tangent (in radians) of a number, that is
The Math.atan()
static method returns the inverse tangent (in radians) of a number, that is
Math.atan(x)
x
A number.
The inverse tangent (angle in radians between and , inclusive) of x
. If x
is Infinity
, it returns . If x
is -Infinity
, it returns .
Because atan()
is a static method of Math
, you always use it as Math.atan()
, rather than as a method of a Math
object you created (Math
is not a constructor).
Math.atan(-Infinity); // -1.5707963267948966 (-Ο/2) Math.atan(-0); // -0 Math.atan(0); // 0 Math.atan(1); // 0.7853981633974483 (Ο/4) Math.atan(Infinity); // 1.5707963267948966 (Ο/2) // The angle that the line (0,0) -- (x,y) forms with the x-axis in a Cartesian coordinate system const theta = (x, y) => Math.atan(y / x);
Note that you may want to avoid the theta
function and use Math.atan2()
instead, which has a wider range (between -Ο and Ο) and avoids outputting NaN
for cases such as when x
is 0
.
Specification |
---|
ECMAScript Language Specification # sec-math.atan |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
atan |
1 | 12 | 1 | 3 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 | 1.0 | 0.10.0 |
Β© 2005β2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan