The ATN2() function in SQL Server calculates the angle (in radians) whose tangent is the ratio of two specified numbers, y and x. This is known as the two-argument arctangent function.
Syntax
ATN2 ( float_expression_y, float_expression_x )
float_expression_y: The y-coordinate of the point.float_expression_x: The x-coordinate of the point.
Functionality
The ATN2(y, x) function calculates the arctangent of the angle between the positive x-axis and the ray from the origin to the point (x, y) in a Cartesian plane. The function:
- Returns values in the range
-πtoπradians. - Takes into account the signs of
xandyto determine the correct quadrant of the angle.
Example
Here are some usage examples of the ATN2() function:
Basic Example
SELECT ATN2(1.0, 1.0) AS Result;
Output: Approximately 0.785398 (which is π/4 radians).
When x and y are in different quadrants
SELECT ATN2(-1.0, 1.0) AS Result;
Output: Approximately -0.785398 (negative π/4 radians).
Using zero values
SELECT ATN2(0.0, 1.0) AS Result;
Output: 0.0 (angle is zero when y is 0).
SELECT ATN2(1.0, 0.0) AS Result;
Output: 1.570796 (which is π/2 radians, representing a vertical angle).
Practical Applications
- Geographic Calculations: Compute bearings or angles based on coordinates.
- Vector Calculations: Determine the direction of a vector in 2D space.
- Graphics: Calculate angles for rotations or projections.
Let me know if you need more details or further examples!
No comments:
Post a Comment