Type Function Library math.* Return value Number Revision 2017.3060 Keywords atan2, arc tangent See also math.atan()
math.tan()
Returns the arc tangent of y/x
(in radians), but uses the signs of both parameters to find the quadrant of the result. It also correctly handles the case of x
being 0
.
The result will be in the interval [-pi,+pi]
radians.
This function is useful when converting rectangular coordinates to polar coordinates. math.atan2()
uses the sign of both arguments to place the result into the correct quadrant, and also produces correct values when one of its arguments is 0
or very close to 0
.
math.atan2( y, x )
Number. A number representing the y coordinate.
Number. A number representing the x coordinate.
print(math.atan2(1, 0)) --> pi/2 print(math.atan2(-1, 0)) --> -pi/2 print(math.atan2(0, 1)) --> 0 print(math.atan2(0, -1)) --> pi