ATAN2
Updated 2024-03-23 22:17:24.823000
Syntax
SELECT [wct].[ATAN2] (
<@y, float,>
,<@x, float,>)
Description
Use the scalar function ATAN2 to calculate a numeric value between -π and π representing the angle θ of a (x, y) point and positive x-axis.
Arguments
@x
The x coordinate of a point
@y
The y coordinate of a point
Return Type
float
Remarks
If @y is 0 and @x is not negative, θ = 0.
If @y is 0 and @x is negative, θ = π.
If @y is positive and @x is 0, θ = π/2.
If @y is negative and @x is 0, θ = -π/2.
If @y is 0 and @x is 0, θ = 0.
If @y IS NULL or @x IS NULL, θ = NULL.
Note that this implementation is different than the Excel implementation which is ATAN2(x,y)
Examples
Example #1
SELECT wct.ATAN2(-0.9, -0.9) as theta1,
wct.ATAN2(1.2, 1.5) as theta2,
wct.ATAN2(1.2, -1.5) as theta3
This produces the following result.
theta1 theta2 theta3
---------------------- ---------------------- ----------------------
-2.35619449019234 0.674740942223553 2.46685171136624
Example #2
SELECT y,
x,
wct.ATAN2(y, x) as theta
FROM
(
VALUES
(1, 6),
(2, 3),
(3, 7),
(4, 8)
) n (y, x)
This produces the following result.
y x theta
----------- ----------- ----------------------
1 6 0.165148677414627
2 3 0.588002603547568
3 7 0.404891786285083
4 8 0.463647609000806
See Also
ATANH - Calculate the inverse hyperbolic tangent of a number.