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

JavaScript
JS数学对象参考
JS字符串对象参考
JS函数参考
JS事件参考
Javascript 常用正则表达式
FF和IE下的js兼容性问题
jQuery 简单介绍
jQuery / 核心 / $(expression, [context] ) 函数
jQuery / 核心 / $(html) 函数
如何使用JS来判断浏览器类型(ie、firefox,等等)
Javascript在IE和FireFox中的不同表现
3个js字符编码函数区别
javascript 中的 XMLDOM 对象

JavaScript atan()和atan2()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 341 ::
收藏到网摘: 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

登陆 | 还没注册?