Skip to content
Search

Atan2

lastmod 2023-01-09created 2022-12-217 edits

Why Arctangent is used to find angles

Every programming language provides the atan(y / x) and atan2(y, x) functions in its Math module for computing the arctangent.

The arctangent, also called the inverse tangent, is the inverse function of the tangent.

Atan2_-trigonometry-_explain.png

Using the arctangent, you can find the angle θ in the image above.

A more detailed explanation

Since \(tan(θ) = a / b\), letting \(a / b = x\),

Return Range

Atan2_-_return_range.png

atan2 takes the relative coordinates (x, y) between two points and returns the absolute angle as a radian value from -π to π. (-180 to 180 degrees)

For reference, atan takes the tangent value between two points and returns the absolute angle as a radian value from -π/2 to π/2. (-90 to 90 degrees)

Why use atan2 instead of atan when computing angles

Atan2_-_cartesian_coordinate_system.png

It is useful in Cartesian coordinate systems where + and - poles are marked.

The atan2 function takes as parameters where point B is located relative to point A, and since it is a relative position, the parameter x or y can be negative.

However, if you use the atan function, the parameter is the slope of a line, so the result becomes the angle between two points with the notion of direction lost.

See also

Favorite site

author Zer0 sitemap