Math
is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains the atan2()
function which is used to compute the angle between the positive x-axis and the ray originating from (0,0) to (x,y) points.
Math.atan2(y,x);
x
: It is of type Number
and indicates the x-coordinate of the input point.y
: It is of type Number
and indicates the y-coordinate of the input point.
Number
in JavaScript is a 64-bit double-precision value that is the same asdouble
in C# or Java.
Angle
: It returns the
angle θ between the positive x-axis and the ray starting from point (0,0) to the point (x,y). It is measured in radians. Its range is
-π <= θ <= π (radians)
π is a mathematical constant whose value is equal to 3.14159 approximately.
console.log("atan2(0,0) = " + Math.atan2(0,0));console.log("atan2(-10,-10) = " + Math.atan2(-10,-10));console.log("atan2(10,10) = " + Math.atan2(10,10));console.log("atan2(10,-10) = " + Math.atan2(10,-10));console.log("atan2(-10,10) = " + Math.atan2(-10,10));console.log("atan2(∞,10) = " + Math.atan2(Infinity,10));console.log("atan2(10,-∞) = " + Math.atan2(10,-Infinity));