JavaScript atan2() method
JavaScript atan2() Method
Instance
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p id="demo">单击按钮显示坐标(4,8)与X轴的角度的弧度</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.atan2(8,4); } </script> </body> </html>
Run Example»
Click the "Run Example" button to view the online example
Definition and usage
atan() method can return the arctangent value of a number .
The returned value represents the angle in radians between the coordinates (x, y) and the X-axis.
Note: atan2() has two parameters, the y coordinate is passed as the first parameter, and the X coordinate is passed as the second parameter.
Browser support
All major browsers support the atan2() method
Syntax
Math.atan2(y,x)
Description | |
---|---|
y | Required. A number representing the Y coordinate|
x | is required. A number representing the x coordinate
Description | ## The arctangent of |
---|---|
x. The returned value is a value in radians between -PI/2 and PI/2. |
1.0 |
---|