Distance Formula

The straight-line distance between two points follows directly from the Pythagorean theorem.

Formulas

2D: d = √((x₂ − x₁)² + (y₂ − y₁)²)

3D: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

midpoint: ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2)

Manhattan (grid) distance: |x₂ − x₁| + |y₂ − y₁|

Example

From (−1, 2) to (5, 10)

  1. Δx = 6, Δy = 8
  2. d = √(36 + 64) = √100

d = 10; midpoint (2, 6).

Where it is used

Maps and games (distance between positions), statistics (Euclidean distance between data points), and physics (displacement). For travel on city streets laid out in a grid, the Manhattan distance is often more realistic.