JavaScript atan2() method
- Forrige side atan()
- Næste side atanh()
- Gå tilbage til niveau JavaScript Math Referencehåndbog
Definition and usage
atan2()
The method can return the angle between the X-axis and the point (x,y).
atan2()
The method returns the arctangent of the quotient of its parameters, returning a value between -PI and PI.
The returned number represents the counterclockwise angle in radians (not degrees) between the positive X-axis and the point (x,y).
Note:Note the order of the function's parameters, the Y coordinate is passed before the X coordinate.
Example - atan2(y,x)
Assuming you have a point (x,y) with coordinates (4,8), you can calculate the angle between the point and the positive X-axis as follows:
Math.atan2(8, 4);
Syntax
Math.atan2(y, x)
Parameters | Description |
---|---|
y | Required. Number. Represents the y coordinate. |
x | Required. Number. Represents the x coordinate. |
Technical details
Return value: | Numbers, from PI to -PI, or NaN if the value is empty. |
---|---|
JavaScript version: | ECMAScript 1 |
Browserv understøttelse
Math.atan2()
Er ES1 funktion (JavaScript 1999). Alle browsere understøtter det fuldt ud:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Support | Support | Support | Support | Support | Support |
Relaterede sider
Læringskursus:JavaScript matematik
- Forrige side atan()
- Næste side atanh()
- Gå tilbage til niveau JavaScript Math Referencehåndbog