Quirrel4.41.0

math.atan2

Defined in module "math"
from "math" import atan2
pure fastcall atan2(y: number, x: number): float

Returns the arctangent of y/x using the signs to determine the quadrant

Parameters

ynumbernumerator; the sign tells which half-plane the angle is in
xnumberdenominator; the sign tells which half-plane the angle is in

Return value

The angle in radians of the point (x, y), in the range [-PI, PI], always as a float.

Notes

Because the two arguments carry separate signs, atan2 places the angle in the correct quadrant, which atan(y/x) alone cannot do. atan2(0, 0) is left undefined by plain mathematics and by some C libraries, but Quirrel's build defines it as 0 rather than nan.

Example

examples/math/atan2.nut
from "math" import atan2, PI

// y comes first, x second - the reverse of a plain division
println("atan2(1, 1) =", atan2(1, 1))
println("atan2(1, 0) =", atan2(1, 0))
println("atan2(0, -1) =", atan2(0, -1))

// atan2(0, 0) is undefined in plain math, but Quirrel defines it as 0
println("atan2(0, 0) =", atan2(0, 0))
Output:
atan2(1, 1) = 0.785398
atan2(1, 0) = 1.5708
atan2(0, -1) = 3.14159
atan2(0, 0) = 0

See also

atanReturns the arctangent of x
sinReturns the sine of x (in radians)
cosReturns the cosine of x (in radians)
PIThe ratio of a circle's circumference to its diameter, for converting between radians and degrees and for angle math in general.
mathmodule index