Distance Formula Calculator — 2D, 3D, and Earth Distance (Haversine)
Calculate distance between two points in 2D and 3D coordinate space, and on Earth using the Haversine formula. Includes worked examples and connection to Pythagorean theorem.
The distance between two points is one of the most fundamental calculations in geometry. It powers GPS navigation, 3D game engines, collision detection, and anything that needs to measure "how far." Calculate distances in any dimension with the CalcHub Distance Formula Calculator.
2D Distance Formula
For points A(x₁, y₁) and B(x₂, y₂):
$$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$$
This is just the Pythagorean theorem applied to the horizontal and vertical legs of the right triangle formed by the two points.
Example: Distance from A(1, 4) to B(5, 1)d = √((5−1)² + (1−4)²) = √(16 + 9) = √25 = 5
Example with negatives: From (−3, 2) to (4, −6) d = √((4−(−3))² + (−6−2)²) = √(49 + 64) = √113 ≈ 10.633D Distance Formula
For points A(x₁, y₁, z₁) and B(x₂, y₂, z₂):
$$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}$$
Example: From (1, 2, 3) to (4, 6, 8) d = √((3)² + (4)² + (5)²) = √(9 + 16 + 25) = √50 ≈ 7.07Distance Between Cities — The Haversine Formula
For points on Earth's surface (latitude/longitude), the flat 2D formula introduces significant error. The Haversine formula gives the great-circle distance (shortest path on a sphere):
$$d = 2R \arcsin\left(\sqrt{\sin^2\!\left(\frac{\Delta\phi}{2}\right) + \cos\phi_1\cos\phi_2\sin^2\!\left(\frac{\Delta\lambda}{2}\right)}\right)$$
Where:
- φ = latitude in radians
- λ = longitude in radians
- R = Earth's radius ≈ 6,371 km
- Δφ = φ₂ − φ₁
- Δλ = λ₂ − λ₁
Example: Mumbai to Delhi
| City | Latitude | Longitude |
|---|---|---|
| Mumbai | 19.076° N | 72.877° E |
| Delhi | 28.704° N | 77.103° E |
Other Distance Metrics
Different situations call for different definitions of "distance":
| Metric | Formula | Use Case | |||
|---|---|---|---|---|---|
| Euclidean | √(Σ(aᵢ−bᵢ)²) | Physical space, most geometry | |||
| Manhattan | Σ\ | aᵢ−bᵢ\ | Grid-based navigation, city blocks | ||
| Chebyshev | max(\ | aᵢ−bᵢ\ | ) | Chess king moves | |
| Minkowski | (Σ\ | aᵢ−bᵢ\ | ᵖ)^(1/p) | Generalization of all above | |
| Cosine | 1 − (a·b)/( | a | b | ) | Text similarity, vectors |
Worked Problem: Triangle Perimeter
Find the perimeter of triangle with vertices A(0, 0), B(6, 0), C(3, 4).
AB = √((6−0)² + 0²) = 6
BC = √((3−6)² + (4−0)²) = √(9+16) = 5
CA = √((0−3)² + (0−4)²) = √(9+16) = 5
Perimeter = 6 + 5 + 5 = 16 units
This is an isosceles triangle (BC = CA).
Is the distance formula the same as finding the magnitude of a vector?
Yes. The distance from the origin (0,0) to a point (x, y) is √(x²+y²) — which is exactly the magnitude |v| of vector v = (x, y). The distance between two points A and B equals the magnitude of the vector AB = B − A.
When would I use Manhattan distance instead of Euclidean?
When movement is constrained to a grid. A taxi in a city can't travel diagonally through buildings — it must go along streets. The Manhattan distance counts the actual grid steps. It's also used in machine learning when Euclidean distance overweights outliers in high-dimensional data.
Why does the Haversine formula matter for navigation?
For short distances (under ~50 km), the flat 2D formula is close enough. But for intercontinental distances, Earth's curvature makes a big difference. A flight from Mumbai to New York is about 12,500 km — using a flat-Earth formula would give a meaningless result. Haversine correctly computes great-circle distances on the sphere.