Distance Calculator: 2D, 3D, Manhattan, Haversine GPS

Calculate Euclidean distance between two points in 2D/3D, Manhattan (taxicab), Haversine GPS (Earth surface) and midpoint. Pure evergreen formulas.

Calculation parameters
Was this calculator useful?

Distance: a fundamental concept

Distance between two points is one of the oldest and most-used mathematical measures. From shortest-path calculation between cities to pixel proximity in computer vision, from GPS coordinates to 3D video games, distance formulas are fundamental tools.

Types of distance

  1. Euclidean 2D: straight-line distance in Cartesian plane
  2. Euclidean 3D: extension to three dimensions
  3. Manhattan (taxicab): path along rectangular grid
  4. Chebyshev: max axis difference (chess king moves)
  5. Haversine: geodesic distance on Earth surface (GPS)

Euclidean Distance 2D

Direct application of Pythagoras' theorem:

d = √[(x₂ − x₁)² + (y₂ − y₁)²]

Example: points (1,2) and (4,6): d = √[9 + 16] = √25 = 5.

Euclidean Distance 3D

d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]

Applications: 3D graphics, physics simulations, robotics, VR/AR, aerospace.

Manhattan Distance (Taxicab)

d = |x₂ − x₁| + |y₂ − y₁|

Named after Manhattan's grid street layout: a taxi can only go straight or turn 90°, not diagonally.

Example: (0,0) to (3,4), Manhattan = 7 (vs Euclidean 5).

Applications:

  • Urban planning, grid-city routing
  • Machine learning (L1 norm, robust to outliers)
  • Information theory (Hamming distance)
  • Game pathfinding (A*)

Chebyshev Distance

d = max(|x₂ − x₁|, |y₂ − y₁|)

Number of moves chess king makes between squares: 8 directions including diagonal, one at a time.

Example: (0,0) to (3,4), Chebyshev = 4.

Haversine Distance (GPS)

For distance between two Earth-surface points given geographic coordinates:

d = 2R · arcsin(√[sin²(Δφ/2) + cos(φ₁)·cos(φ₂)·sin²(Δλ/2)])

where R = 6371 km (Earth's mean radius), φ = latitude (radians), λ = longitude.

Example: NYC (40.7°N, -74.0°W) to Los Angeles (34.0°N, -118.2°W) ≈ 3,944 km.

Accuracy: ~0.5% (Earth not perfectly spherical; 0.3% flattened at poles). Use Vincenty formula (WGS84 ellipsoid) for maximum precision.

Midpoint

M = ((x₁+x₂)/2, (y₁+y₂)/2)

Equidistant from both endpoints.

Minkowski distance generalization

Euclidean, Manhattan, and Chebyshev are special cases of Minkowski distance of order p:

d = (|Δx|p + |Δy|p)1/p

  • p = 1: Manhattan
  • p = 2: Euclidean
  • p → ∞: Chebyshev

Practical applications

1. GPS navigation

Google Maps, Apple Maps, Waze use Haversine variants (with ellipsoidal corrections) for "as-the-crow-flies" distances. For actual road routes, graph routing algorithms (Dijkstra, A*) are needed.

2. Video games

Collision detection, AI pathfinding, ability ranges. Often squared distance used to avoid expensive √: if d² < 100, then d < 10 without root computation.

3. Machine Learning — K-Nearest Neighbors

Classification based on k nearest points. Distance choice critical:

  • Euclidean: default
  • Manhattan: robust to outliers
  • Cosine similarity: high-dimensional vectors (NLP, text)

4. Astronomy

Parsec (pc): astronomical distance = 3.26 light-years. Nearby stars measured via parallax (trigonometric distance formula).

5. Biology — Genomics

Hamming distance between DNA sequences: number of positions where they differ. Foundation of molecular phylogenetics.

6. Logistics and transportation

Route optimization, Traveling Salesman Problem (TSP) computes distances between thousands of points to find minimum tour.

7. Computer graphics

3D rendering, lighting, shadows, ambient occlusion — all computed via point distances.

Space-time distances (relativity)

In special relativity (Einstein 1905), distance between events is not Euclidean but 4D Minkowski:

ds² = −c²·dt² + dx² + dy² + dz²

Conceptual revolution: time and space aren't independent.

Graph theory: network distance

In complex networks (Facebook friends, scientific citations, internet), distance is minimum number of edges between two nodes.

Six degrees of separation: Stanley Milgram (1967) experimentally showed every American pair is connected by ~6 people on average. Modern online networks reduced to ~3-4.

Distances in physics

Natural scales

  • Proton diameter: ~10⁻¹⁵ m (femtometer)
  • Atom diameter: ~10⁻¹⁰ m (angstrom)
  • Cell: ~10⁻⁵ m (10 μm)
  • Human height: ~1.7 m
  • Earth radius: 6,371 km
  • Earth-Sun distance: 1 AU = 1.496 × 10⁸ km (8 light-minutes)
  • Milky Way diameter: ~100,000 light-years
  • Observable universe: ~46 billion light-years radius

Range: 42 orders of magnitude. Logarithms fundamental here.

Excel / Sheets / Python formulas

Excel / Google Sheets

  • 2D distance: =SQRT((x2-x1)^2 + (y2-y1)^2)
  • 3D distance: add (z2-z1)^2

Python

import math

# 2D Euclidean
p1 = (1, 2)
p2 = (4, 6)
d = math.dist(p1, p2)  # 5.0 (Python 3.8+)

# Manhattan
d_manhattan = sum(abs(a - b) for a, b in zip(p1, p2))

# NumPy vectors
import numpy as np
p1 = np.array([1, 2, 3])
p2 = np.array([4, 6, 10])
d = np.linalg.norm(p2 - p1)

# Scipy
from scipy.spatial.distance import euclidean, cityblock, chebyshev

Mathematical properties

Every mathematical "distance" must satisfy 4 properties (metric space):

  1. Non-negativity: d(x, y) ≥ 0
  2. Identity: d(x, y) = 0 if and only if x = y
  3. Symmetry: d(x, y) = d(y, x)
  4. Triangle inequality: d(x, z) ≤ d(x, y) + d(y, z)

Vector space distances

For vectors x and y in ℝn, norm-induced distance:

d(x, y) = ||x − y||

Common norms:

  • L1 (Manhattan)
  • L2 (Euclidean)
  • L∞ (Chebyshev)
  • Cosine similarity: 1 − (x·y)/(||x||·||y||)

Non-Euclidean geometry

In spherical geometry (Earth surface), distance is great-circle arc — Haversine formula.

In hyperbolic geometry, distance grows exponentially from center. Used in AI for tree-like hierarchies.

History of distance measurement

  • ~2000 BCE Babylonians: Pythagoras' theorem applied before Pythagoras (Plimpton 322)
  • ~300 BCE Euclid: Euclidean distance formally defined
  • ~150 CE Ptolemy: Almagest with trigonometric methods for astronomical distances
  • 1761-1762 John Harrison: marine chronometer solves longitude problem
  • 1838 Friedrich Bessel: first stellar parallax measurement (61 Cygni, 10.3 light-years)
  • 1984 GPS: satellite trilateration, meter accuracy globally
  • 2016 LIGO: gravitational waves detected by measuring distances with 10⁻¹⁹ m precision

Common mistakes

  • Confusing Euclidean and Manhattan: in grid cities use Manhattan; straight-line use Euclidean
  • Using Euclidean on GPS: large error on long distances (Mercator projection distorts)
  • Forgetting √ in Pythagoras: often d² computed to save calculation
  • Negative distance: impossible. Always ≥ 0
  • Degrees vs radians: fundamental to convert to radians for Haversine

FAQ

Which distance to use?

Euclidean default in geometry and physics. Manhattan for grid cities. Haversine for GPS. Chebyshev for chess/pixels. Cosine for high-dim vectors.

Why called Manhattan?

Named after Manhattan's (NYC) grid street layout.

Haversine vs Vincenty?

Haversine assumes perfect sphere (max 0.5% error). Vincenty uses WGS84 ellipsoid for millimeter precision at higher computational cost.

How to reduce computation in games?

Use d² instead of d (avoids √). Check d² < r² instead of d < r.

Negative distances?

Impossible in Euclidean geometry. In relativity ds² can be < 0 for time-like intervals, but |ds| ≥ 0.

Updated July 2026

Frequently Asked Questions

How do you calculate the distance between two points?

On a plane you use the Euclidean distance, which is the Pythagorean theorem: d = √[(x₂−x₁)² + (y₂−y₁)²]. You build a right triangle with legs Δx and Δy, and the distance is the hypotenuse. For example, from (0,0) to (3,4) the distance is √(9+16) = √25 = 5.

What is Manhattan (taxicab) distance?

It is the sum of the absolute differences: d = |x₂−x₁| + |y₂−y₁|. It represents a taxi's route in a grid city, where you move only along horizontal and vertical streets without cutting diagonally. From (0,0) to (3,4) it is 3+4 = 7, more than the Euclidean distance (5).

What is Chebyshev distance?

It is the maximum of the absolute differences: d = max(|x₂−x₁|, |y₂−y₁|). It matches the king's moves in chess, which reaches a diagonal square in a single move. From (0,0) to (3,4) it is max(3,4) = 4. It is used in game theory and grid-based movement.

How do you calculate the GPS distance between two coordinates?

You use the Haversine formula, which accounts for the Earth's curvature: d = 2R·arcsin(√a), with R = 6371 km and a = sin²(Δφ/2) + cos(φ₁)·cos(φ₂)·sin²(Δλ/2), where φ is latitude and λ is longitude in radians. It gives the great-circle distance along the Earth's surface.

How do you calculate distance in 3D?

You extend the Pythagorean theorem to the third dimension: d = √[(x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²]. It is needed in 3D graphics, robotics, physics and chemistry (for example the distance between two atoms in a molecule). From (0,0,0) to (2,3,6) the distance is √(4+9+36) = √49 = 7.

What is the midpoint of a segment?

It is the point halfway between the two endpoints, with coordinates given by the arithmetic mean: M = ((x₁+x₂)/2, (y₁+y₂)/2). In 3D you add (z₁+z₂)/2. The midpoint between (2,4) and (6,8) is (4,6). It is used in geometry for bisections, centroids and constructions.

Which type of distance should I use?

It depends on the context: Euclidean distance for free movement in space, Manhattan for street grids or circuits, Chebyshev for chessboard movement, and Haversine for GPS geographic coordinates. In machine learning the choice of metric strongly affects algorithms such as k-NN and clustering.

Comments (0)

No comments yet. Be the first!