Javascript examples for Math:atan2
The atan2() method returns the arctangent of the quotient of its arguments, as a numeric value between PI and -PI radians.
Parameter | Description |
---|---|
y | Required. A number representing the y coordinate |
x | Required. A number representing the x coordinate |
A Number, from PI to -PI, or NaN if the value(s) are empty
you had a point with the (x,y) coordinates of (4,8), you could calculate the angle in radians between that point and the positive X axis as follows:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//w w w . j a v a2 s.c o m document.getElementById("demo").innerHTML = Math.atan2(8, 4); } </script> </body> </html>