JavaScript atan2

JavaScript atan2 函数是 Math 函数之一,用于返回从 X 轴到指定点 (y, x) 的角度(以弧度为单位)。atan2 函数的基本语法如下所示:

Math.atan2(y, x);

X:代表笛卡尔 X 坐标,Y 代表笛卡尔 Y 坐标。如果其中一个参数是 Null 值,它将把 Null 值转换为零。如果任何参数不是数字,它将返回 NaN。

JavaScript atan2 函数示例

在此 atan2 示例中,我们使用不同的数据类型查找角度(以弧度为单位)并显示输出。请参考 JavaScript 中的 TAN 以了解正切函数。

<!DOCTYPE html>
<html>
<head>
    <title> JavaScriptATAN2Function </title>
</head>
<body>
  <h1> JavaScriptATAN2Function </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Str1"></p>
  <p id = "Null"></p>
  <p id = "Multi"></p>
 <script>
    document.getElementById("Pos").innerHTML = Math.atan2(2, 4);
    document.getElementById("Neg").innerHTML = Math.atan2(-1, 6);
    document.getElementById("Dec").innerHTML = Math.atan2(2.45, 0.45);
    document.getElementById("Neg_Dec").innerHTML = Math.atan2(-4.75, -0.75);
    document.getElementById("Str").innerHTML = Math.atan2("5", "11");
    document.getElementById("Str1").innerHTML = Math.atan2("Js", "JavaScript");
    document.getElementById("Null").innerHTML = Math.atan2(null, 4);
    document.getElementById("Multi").innerHTML = Math.atan2(2 + 7 - 4, 9-5);
  </script>
</body>
</html>
ATAN2 Function Example