Overview

atan2

atan2 is useful when you have two independent counts or values and want to express their ratio as an angle. For example, you can use atan2 to encode the balance between error count and success count as a direction vector, or to analyze the ratio of two traffic volumes.

Usage#

Syntax#

atan2(y, x)

Parameters#

Name Type Required Description
y real Yes The y-coordinate of the point (numerator).
x real Yes The x-coordinate of the point (denominator).

Returns#

The angle in radians between the positive x-axis and the point (y, x), in the range (-π, π].

Example#

Use atan2 to compute the angle between the positive x-axis and the point (x, y).

Query

print result = atan2(1, 1)

Run in Playground

Output

result
0.7854
  • atan: Returns the arc tangent from a single ratio. Use it when you have a pre-computed ratio instead of separate y and x components.
  • asin: Returns the arc sine. Use it when the input maps to a sine value in [-1, 1].
  • acos: Returns the arc cosine. Use it when the input maps to a cosine value in [-1, 1].
  • tan: Returns the tangent. Use it to apply the forward transformation before using atan2 as the inverse.
  • degrees: Converts radians to degrees. Use it if you prefer the atan2 result in degrees.

Other query languages#

Splunk SPL users

In Splunk SPL, atan2(y, x) is available in the eval command with the same argument order and semantics.

Splunk example

| eval angle = atan2(errors, successes)

APL equivalent

['sample-http-logs']
| extend angle = atan2(todouble(errors), todouble(successes))
ANSI SQL users

In ANSI SQL, the function is typically named ATN2(y, x) in SQL Server or ATAN2(y, x) in PostgreSQL. The argument order (y first, then x) is the same as in APL.

SQL example

SELECT ATN2(errors, successes) AS angle FROM logs

APL equivalent

['sample-http-logs']
| extend angle = atan2(todouble(errors), todouble(successes))

Updated

Was this page helpful?