Reference · Math
math.atan2
math.atan2(num, num) -> floatWhat it does
The angle in radians, between -pi and pi, from the positive x axis to the point
(x, y), as Python's math.atan2. The order is y first, then x. Unlike
math.atan(y / x) it keeps the quadrant, and x may be zero.
Examples
print(math.atan2(1, 1), math.degrees(math.atan2(1, 1)))print(math.degrees(math.atan2(1, -1)), math.degrees(math.atan2(-1, -1)), math.degrees(math.atan2(-1, 1)))0.7853981633974483 45.0135.0 -135.0 -45.0Edge cases
xzero is fine, nothing is divided:(0, 1)is straight up,pi/2.- Both zero give
0.0, not an error. - A zero
ywith a negativexispi, or-piwhen the zero is-0.0. - Infinities give the diagonal angles;
NaNin either givesNaN.
print(math.atan2(1, 0), math.atan2(-1, 0))print(math.atan2(0, 0))print(math.atan2(0, -1), math.atan2(-0.0, -1))print(math.atan2(math.inf, math.inf), math.atan2(1, math.nan))1.5707963267948966 -1.57079632679489660.03.141592653589793 -3.1415926535897930.7853981633974483 NaNErrors
There is no domain error. A missing second argument, or a value that is not a number, is a runtime error, not an error value: it stops the request.
print(math.atan2(1))line 1: `math.atan2` expects a number as argument 2, got nothingprint(math.atan2("1", 2))line 1: `math.atan2` expects a number as argument 1, got strChaining
In a pipeline y comes first, so y | math.atan2(x) works. A point as a list is
taken apart with let [x, y] = p:
let [x, y] = [3, 4]print(y | math.atan2(x) | math.degrees)print([[1, 0], [0, 1], [-1, 0]] | map((p) => math.degrees(math.atan2(p[1], p[0]))))53.13010235415598[0.0, 90.0, 180.0]See also
math.atan, math.hypot, math.degrees, math.sin, math.cos
Thread 0 posts
On math.atan2(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo