math.atan2
Defined in module
"math"from "math" import atan2Returns the arctangent of y/x using the signs to determine the quadrant
Parameters
y | number | numerator; the sign tells which half-plane the angle is in |
x | number | denominator; 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
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) = 0See also
atan | Returns the arctangent of x |
sin | Returns the sine of x (in radians) |
cos | Returns the cosine of x (in radians) |
PI | The ratio of a circle's circumference to its diameter, for converting between radians and degrees and for angle math in general. |
| math | module index |