atan2 (JavaScript)

Gets the inverse tangent of an angle using two parameters.

Defined in

Math (JavaScript)

Syntax

atan2(y:double, x:double) : double
Parameter Description
y The side of a right triangle adjacent to an angle. See below for special cases.
x The side of a right triangle opposite to the same angle. See below for special cases.
Return value Description
double The inverse tangent of y/x in radians. See rad (JavaScript) to convert degrees to radians.

Usage

Special cases are as follows:
  • The following yields NaN: y or x is NaN.
  • The following yield +0:
    • y is +0 and x is positive
    • y is positive and finite and x is +Infinity
  • The following yield -0:
    • y is -0 and x is positive
    • y is negative and finite and x is +Infinity
  • The following yield pi:
    • y is +0 and x is negative
    • y is positive and finite and x is -Infinity
  • The following yield -pi:
    • y is -0 and x is negative
    • y is negative and finite and x is -Infinity
  • The following yield pi/2:
    • y is positive and x is 0
    • y is +Infinity and x is finite
  • The following yield -pi/2:
    • y is negative and x is 0
    • y is -Infinity and x is finite
  • The following yields pi/4: y and x are +Infinity.
  • The following yields 3*pi/4: y is +Infinity and x is -Infinity.
  • The following yields -pi/4: y is -Infinity and x is +Infinity.
  • The following yields -3*pi/4: y and x are -Infinity.

The following are equivalent: atan(y/x) and atan2(y, x).

Examples

This button onclick event calculates an angle in degrees of a right triangle given the length of the adjacent side and the length of the opposite side.
sessionScope.angleA = 
	Math.deg(Math.atan2(sessionScope.a, sessionScope.b))