Home > Web Front-end > JS Tutorial > body text

javascript atan2() 计算X 轴到某一点的角度

WBOY
Release: 2016-06-01 09:54:43
Original
1835 people have browsed it

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

基本语法:

<code class="language-javascript">Math.atan2(y, x)</code>
Copy after login

参数介绍

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

返回值

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

注意:

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

 

实例

<code class="language-javascript"><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) + "<br />")
document.write(Math.atan2("s","y") + "<br />")
</script></code>
Copy after login

在线运行

运行结果:

<code class="language-javascript">0.7853981633974483
-2.356194490192345
0.7853981633974483
0.4636476090008061
-2.356194490192345
-0.7853981633974483
NaN</code>
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!