Assume 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:
The output of the code above will be:
The atan2() method returns the arctangent of the quotient of its arguments, as a numeric value between PI and -PI radians.
The number returned represents the counterclockwise angle in radians (not degrees) between the positive X axis and the point (x, y).
Note: With atan2(), the y coordinate is passed as the first argument and the x coordinate is passed as the second argument.
The atan2() method is supported in all major browsers.
|y||Required. A number representing the y coordinate|
|x||Required. A number representing the x coordinate|
|Number||A Number, from PI to -PI, or NaN if the value(s) are empty|
Your message has been sent to W3Schools.