Given the coordinates of a point, returns the angle associated with the point in radians. If the point’s -coordinate is negative the function returns a negative angle.
Name | Description |
---|---|
y | The vertical coordinate of the point. |
x | The horizontal coordinate of the point. |
The improved arc tangent function takes in a and coordinate as input and returns the angle associated with the point . For example, given the point as input the function returns the angle of . This is illustrated by figure below.
= atan2( 1, 1) = 0.785... // (1/8)*TAU
Many programming languages provide both the function and the function. The difference between the two functions is the range of possible return values for real number input. The range of is while the range of is . In other words, the atan
function returns angles on the right half of the circle and atan2
returns angles on the whole circle.
Input | Behavior |
---|---|
Quadrant 1 | Same |
Quadrant 2 | Different |
Quadrant 3 | Different |
Quadrant 4 | Same |
The different behavior is visualized below in the second quadrant when given the same point as input. The atan2
function returns the corresponding angle that is greater than a perpendicular while the atan
function returns the corresponding angle that is less than a perpendicular angle.
One way to reconcile the difference between the two functions is to extend the input of atan
to accept numbers in the complex number system. In this case, the atan
function will return angles on the full circle.