Direction Between Two Points (atan2)

The angle from one point to another, in the range −180° to 180°.

θ = atan2(y₂ − y₁, x₂ − x₁)

Plain arctan cannot tell left from right, so atan2 looks at the signs of both x and y.

0° points along the positive x-axis; with the y-axis up, counter-clockwise is positive.

Calculator

Change a value and the result and picture update instantly.

Result

Direction θ (°)146.31

Animated picture

The picture follows your values. Some points and shapes can be dragged.

Use in game development

Turn an enemy toward the player, or fire toward the mouse pointer.

Code example (JavaScript)

const angle = Math.atan2(target.y - y, target.x - x);

What the symbols mean

SymbolMeaning
x1From x
y1From y
x2Target x
y2Target y
degDirection θ (°)

More formulas in this category

Frequently asked questions

What is the formula for Direction Between Two Points (atan2)?
The formula for Direction Between Two Points (atan2) is θ = atan2(y₂ − y₁, x₂ − x₁). The angle from one point to another, in the range −180° to 180°.

Math Formula Quiz Coordinate Geometry

Sources

Checked: 2026-11-29