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:yorxisNaN. - The following yield
+0:yis+0andxis positiveyis positive and finite andxis+Infinity
- The following yield
-0:yis-0andxis positiveyis negative and finite andxis+Infinity
- The following yield
pi:yis+0andxis negativeyis positive and finite andxis-Infinity
- The following yield
-pi:yis-0andxis negativeyis negative and finite andxis-Infinity
- The following yield
pi/2:yis positive andxis0yis+Infinityandxis finite
- The following yield
-pi/2:yis negative andxis0yis-Infinityandxis finite
- The following yields
pi/4:yandxare+Infinity. - The following yields
3*pi/4:yis+Infinityandxis-Infinity. - The following yields
-pi/4:yis-Infinityandxis+Infinity. - The following yields
-3*pi/4:yandxare-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))