Distance Formula Calculator
Coordinate geometry, not map distance — compute the straight-line distance, midpoint, and slope (2D) or direction vector (3D) between two coordinate points.
Two Points
Answer
Show your work
- P₁ = (1, 2), P₂ = (4, 6)mode = 2D
- Distance — √(sum of squared deltas)d = √((3)² + (4)²)= √25 = 5
- Midpoint — average each coordinateM = ((1 + 4)/2, (2 + 6)/2)= (2.5, 4)
- Slope — Δy / Δxm = 4 / 3= 1.3333
The distance and midpoint formulas
For any two points in the plane:
Distance: d = √((x₂ − x₁)² + (y₂ − y₁)²)
Midpoint: M = ((x₁ + x₂)/2, (y₁ + y₂)/2)
Slope: m = (y₂ − y₁) / (x₂ − x₁)
In 3D, add the z-term to distance and midpoint:d = √((Δx)² + (Δy)² + (Δz)²), M = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2). Slope isn't defined in 3D — use direction vectors instead.
Where the distance formula comes from
The 2D distance formula is the Pythagorean theorem applied to a right triangle whose legs are Δx and Δy. Think of a right triangle with one leg horizontal (Δx long) and one vertical (Δy long) — the hypotenuse is the straight line from P₁ to P₂, and by a² + b² = c²: d² = (Δx)² + (Δy)², so d = √((Δx)² + (Δy)²). The 3D formula extends this to three dimensions by including Δz.
When slope is undefined
If x₁ = x₂ (a vertical line), the slope formula divides by zero. Geometrically, a vertical line has infinite slope, and mathematically slope is simply undefined. This calculator reports “undefined (vertical line)” instead of returning an error or NaN — so you can distinguish it from zero-slope (horizontal) lines.
Practical uses
- Map distance — “as the crow flies” between any two map points. Convert lat/long to flat xy first (at city scale this is accurate; for continental distances use great-circle distance instead).
- Line of a segment — given two endpoints, the midpoint is the centerpoint of the line segment. Used in computer graphics, game dev, and architecture.
- Slope of a roof / ramp — the slope formula gives rise / run. A 1:12 ramp (rise 1 / run 12 = slope ≈ 0.083) is ADA-accessible.
- 3D CAD / gaming — 3D distance computes magnitudes of vectors between positions in 3-space.
Common mistakes to avoid
- Swapping P₁ and P₂ for slope. The signs flip, but the ratio is the same: (y₂ − y₁) / (x₂ − x₁) = (y₁ − y₂) / (x₁ − x₂). The calculator handles this automatically.
- Forgetting absolute-value thinking for distance. Distance is always non-negative. Even if Δx or Δy are negative, their squares are positive, and the √ result is positive. You don't need to take absolute values separately.
- Using 2D distance on 3D points. If points have non-zero z values, switch to 3D mode — otherwise you'll get the projection onto the xy-plane, not the true straight-line distance.