atan2 方法返回由 X 轴到 (y,x) 点的角度(以弧度为单位)。

基本语法:

Math.atan2(y, x)

参数介绍

参数 描述
x 必需。描述笛卡儿 x 坐标的数值表达式。
y 必需。描述笛卡儿 y 坐标的数值表达式。

返回值

返回值在 -pi 和 pi 之间,表示提供的 (y,x) 点的角度。

注意:

  1. 这个函数的参数顺序,Y 坐标在 X 坐标之前传递。
  2. 函数中如果有一个参数的值为非数字,该函数将返回NaN

 

实例

<  type=\"text/ \">
document.write(Math.atan2(0.50,0.50) + \"<br />\")
document.write(Math.atan2(-0.50,-0.50) + \"<br />\")
document.write(Math.atan2(5,5) + \"<br />\")
document.write(Math.atan2(10,20) + \"<br />\")
document.write(Math.atan2(-5,-5) + \"<br />\")
document.write(Math.atan2(-10,10) + \"<br />\")
document.write(Math.atan2(\"s\",\"y\") + \"<br />\")
</ >

在线运行

运行结果:

0.7853981633974483
-2.356194490192345
0.7853981633974483
0.4636476090008061
-2.356194490192345
-0.7853981633974483
NaN

 

收藏 打印