当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript atan()和atan2()方法

JavaScript
JS 字符串
JS Date
JS数组,JS Array
JS Boolean
JS Math
JS HTML DOM
JS Browser
JS Cookies
JS 校验
JS Animation
JS Image Maps
JS Timing
JS 建立对象
JS 摘要
JS 实例
JS 对象实例
JS DOM 实例
JS数组对象参考
JS布尔对象参考
JS日期对象参考

JavaScript atan()和atan2()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 342 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

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 的反正切值

Syntax
语法

Math.atan(x)
Math.atan2(x,y)

Parameter
参数
Description
描述
x Required. A number
必选。数字
y Required. A number
必选。数字


Example 1 - atan()
举例

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 />")
document.write(Math.atan(-0.50) + "<br />")
document.write(Math.atan(5) + "<br />")
document.write(Math.atan(10) + "<br />")
document.write(Math.atan(-5) + "<br />")
document.write(Math.atan(-10))
</script>

The output of the code above will be:
结果为:

0.4636476090008061
-0.4636476090008061
1.373400766945016
1.4711276743037347
-1.373400766945016
-1.4711276743037347


Example 2 - atan2()
举例 2

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 />")
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>

The output of the code above will be:
上述代码将输出下面的结果:

0.7853981633974483
-2.356194490192345
0.7853981633974483
0.4636476090008061
-2.356194490192345
-0.7853981633974483


Try-It-Yourself Demos
尝试与演示

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()方法

评论 (0) All

登陆 | 还没注册?