JS Math.atan2()
概述
Math.atan2()
返回其参数比值的反正切值。
语法
Math.atan2(y, x)
参数
y, x
数值
描述
atan2
方法返回一个 -pi 到 pi 之间的数值,表示点 (x, y) 对应的偏移角度。这是一个逆时针角度,以弧度为单位,正X轴和点 (x, y) 与原点连线 之间。注意此函数接受的参数:先传递 y 坐标,然后是 x 坐标。
atan2
接受单独的 x 和 y 参数,而 atan
接受两个参数的比值。
由于 atan2
是 Math
的静态方法,所以应该像这样使用:Math.atan2()
,而不是作为你创建的 Math
实例的方法。
示例
例子:使用 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 1st Edition. Implemented in JavaScript 1.0 | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262) Math.atan2 | Standard | |
ECMAScript 2015 (6th Edition, ECMA-262)Math.atan2 | Standard |
相关链接
- The
Math
object it belongs to. Math.acos()
Math.asin()
Math.atan()
Math.cos()
Math.sin()
Math.tan()