×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2014.2478 | Released: 25 Oct 2014, 1:35am | What's New | Download Now

math.atan2()

Description:

Returns the principal value of the arctangent of the quotient of two specified numbers, expressed in radians.

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.

Syntax:

math.atan2 (y, x)

Example:

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

Parameters:

y
A number representing an y-coordinate.

x
A number representing an x-coordinate.

Returns:

A number in the interval [-pi,+pi] radians.

Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Corona SDK 1.0
  • Windows:
    Corona SDK 2.0
  • iOS:
    Corona SDK 1.0
  • Android:
    Corona SDK 2.0