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.
Report a calculation error
Help us improve. Describe what is wrong with the calculation.
Result
| Voce | Valore |
|---|
Show full details
Share result
Disclaimer: this calculation is for informational purposes only. For important decisions, consult a qualified professional.
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
- Euclidean 2D: straight-line distance in Cartesian plane
- Euclidean 3D: extension to three dimensions
- Manhattan (taxicab): path along rectangular grid
- Chebyshev: max axis difference (chess king moves)
- 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):
- Non-negativity: d(x, y) ≥ 0
- Identity: d(x, y) = 0 if and only if x = y
- Symmetry: d(x, y) = d(y, x)
- 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
Comments (0)
Login to leave a comment.
No comments yet. Be the first!