当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript atan()和atan2()方法
The atan() method returns the arctangent of a number as a numeric value between -PI/2 and PI/2 radians.
atan()方法可以返回数字的反正切值
The atan2() method returns the angle theta of an (x,y) point as a numeric value between -PI and PI radians.
atan2()方法可以计算两个变量x 和y 的反正切值
Math.atan(x) Math.atan2(x,y) |
Parameter 参数 | Description 描述 |
---|---|
x | Required. A number 必选。数字 |
y | Required. A number 必选。数字 |
The following example returns the arctangent of different numbers with the atan() method:
不同数值使用atan()方法后返回的值:
<script type="text/javascript"> document.write(Math.atan(0.50) + "<br />") </script> |
The output of the code above will be:
结果为:
0.4636476090008061 |
The following example returns the angle theta of different (x,y) points with the atan2() method:
使用了atan2()返回不同两变量x,y后的值:
<script type="text/javascript"> document.write(Math.atan2(0.50,0.50) + "<br />") </script> |
The output of the code above will be:
上述代码将输出下面的结果:
0.7853981633974483 |
atan()
How to use atan() to return the arctangent of different numbers.
如何使用atan()方法
atan2()
How to use atan2() to return the angle theta of different (x,y) points.
如何使用atan2()方法