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
orx
isNaN
. - The following yield
+0
:y
is+0
andx
is positivey
is positive and finite andx
is+Infinity
- The following yield
-0
:y
is-0
andx
is positivey
is negative and finite andx
is+Infinity
- The following yield
pi
:y
is+0
andx
is negativey
is positive and finite andx
is-Infinity
- The following yield
-pi
:y
is-0
andx
is negativey
is negative and finite andx
is-Infinity
- The following yield
pi/2
:y
is positive andx
is0
y
is+Infinity
andx
is finite
- The following yield
-pi/2
:y
is negative andx
is0
y
is-Infinity
andx
is finite
- The following yields
pi/4
:y
andx
are+Infinity
. - The following yields
3*pi/4
:y
is+Infinity
andx
is-Infinity
. - The following yields
-pi/4
:y
is-Infinity
andx
is+Infinity
. - The following yields
-3*pi/4
:y
andx
are-Infinity
.
The following are equivalent: atan(y/x)
and atan2(y,
x)
.
Examples
This buttononclick
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))