atan2() 方法可返回从 x 轴到点 (x,y) 之间的角度。
</>code
- Math.atan2(y,x)
参数 | 描述 |
---|---|
x | 必需。指定点的 X 坐标。 |
y | 必需。指定点的 Y 坐标。 |
-PI 到 PI 之间的值,是从 X 轴正向逆时针旋转到点 (x,y) 时经过的角度。
注释:请注意这个函数的参数顺序,Y 坐标在 X 坐标之前传递。
下面这个例子可通过 atan2() 方法返回不同 (x,y) 点的角度:
</>code
- <script type="text/javascript">
- 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))
- </script>
输出:
</>code
- 0.7853981633974483
- -2.356194490192345
- 0.7853981633974483
- 0.4636476090008061
- -2.356194490192345
- -0.7853981633974483
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛
Powered by 365建站网 RSS地图 HTML地图
copyright © 2013-2024 版权所有 鄂ICP备17013400号