Math.atan2()
function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y), for
Math.atan2(y,x)
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Math.atan2(y, x)
y
The y coordinate of the point.
x
The x coordinate of the point
The angle in radians (in ) between the positive x-axis and the ray from (0,0) to the point
Math.atan2()
method returns a numeric value between -π and π representing the angle theta of an
(x, y)
point. This is the counterclockwise angle, measured in radians, between the positive X axis, and the point
(x, y)
. Note that the arguments to this function pass the y-coordinate first and the x-coordinate second.
Math.atan2()
is passed separate
x
and
y
arguments, and
Math.atan()
is passed the ratio of those two arguments.
因为
atan2()
is a static method of
Math
, you always use it as
Math.atan2()
, rather than as a method of a
Math
object you created (
Math
is not a 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.
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Math.atan2' in that specification. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
atan2
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持
Math
Math.abs()
Math.acos()
Math.acosh()
Math.asin()
Math.asinh()
Math.atan()
Math.atan2()
Math.atanh()
Math.cbrt()
Math.ceil()
Math.clz32()
Math.cos()
Math.cosh()
Math.exp()
Math.expm1()
Math.floor()
Math.fround()
Math.hypot()
Math.imul()
Math.log()
Math.log10()
Math.log1p()
Math.log2()
Math.max()
Math.min()
Math.pow()
Math.random()
Math.round()
Math.sign()
Math.sin()
Math.sinh()
Math.sqrt()
Math.tan()
Math.tanh()
Math.trunc()
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()