Arc Tangent 2 Function

Arc Tangent 2 Function

Summary

Given the and coordinates of a point, returns the angle associated with the point in radians. If the point’s -coordinate is negative, meaning that the point is in quadrant or , the function returns a negative angle.

Syntax

atan2(y,x)

Arguments

Name Description
y A number representing the vertical component of a point in the Cartesian Plane
x A number representing the horizontal component of a point in the Cartesian Plane

Usage

The improved arctangent function, which takes in a and coordinate as input, returns the angle associated with the point . For example, given the point as input the function returns the angle of as illustrated by figure below..

Arc Tangent of the Point (1,1).
= atan2(1,1) = 0.785... // (1/8)*TAU

ATAN2 vs. ATAN

Many programming languages provide both the ATAN2 function and the ATAN 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 reason why both functions exist has to do with the complex number system. When using complex number input with ATAN the function returns angles in all coordinates. The difference is that ATAN2 expects the horizontal and vertical components as separate values and ATAN expects complex number input which has the two different components stored within one number.

So if you are not using the complex number system, this is the function to use in most cases. Otherwise, the other arc functions will work well with the complex number system.