Maths⏱ 5 min read

How to Calculate the Distance Between Two Points

The distance formula in 2D and 3D comes directly from Pythagoras. Here is how it works, how GPS uses it, and how to calculate great-circle distance on the curved surface of the Earth.

The distance between two points is a fundamental calculation in mathematics with real-world applications from GPS routing to physics simulations. Understanding the derivation makes it unforgettable.

2D Distance Formula

Distance = sqrt((x2-x1)^2 + (y2-y1)^2) This is simply Pythagoras applied to the horizontal and vertical separation between two points. Example: Point A at (2, 3), Point B at (7, 9) Horizontal separation (Δx): 7 - 2 = 5 Vertical separation (Δy): 9 - 3 = 6 Distance = sqrt(5^2 + 6^2) = sqrt(25 + 36) = sqrt(61) = 7.81 units Why this works: draw a right triangle with the two points at opposite corners. Pythagoras gives the hypotenuse.

3D Distance Formula

Distance = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2) Just adds the vertical (z) dimension. Example: Point A at (1, 2, 3), Point B at (4, 6, 3) Δx = 3, Δy = 4, Δz = 0 Distance = sqrt(9 + 16 + 0) = sqrt(25) = 5 units Example with height: Building at (0, 0, 0), drone at (100, 50, 30) Distance = sqrt(10000 + 2500 + 900) = sqrt(13400) = 115.8m

Manhattan Distance (City Block Distance)

In grid-based navigation (like city streets), you cannot travel diagonally — only horizontally and vertically. Manhattan distance = |x2-x1| + |y2-y1| Same example (2,3) to (7,9): Manhattan = |7-2| + |9-3| = 5 + 6 = 11 units vs Euclidean: 7.81 units Manhattan distance is used in: - City navigation routing - Machine learning (k-nearest neighbours) - Some computer vision algorithms

Great-Circle Distance (Earth's Surface)

The Earth is a sphere, so straight-line distance through the Earth isn't useful for navigation. Use the Haversine formula: a = sin^2(Δlat/2) + cos(lat1) x cos(lat2) x sin^2(Δlon/2) c = 2 x atan2(sqrt(a), sqrt(1-a)) d = R x c (R = 6,371 km, Earth's mean radius) Example: London (51.51°N, -0.13°E) to New York (40.71°N, -74.01°E) Δlat = (40.71 - 51.51) x π/180 = -0.1886 rad Δlon = (-74.01 - (-0.13)) x π/180 = -1.289 rad a = sin^2(-0.0943) + cos(0.8993) x cos(0.7104) x sin^2(-0.6445) = 0.00888 + 0.6272 x 0.7536 x 0.36265 = 0.00888 + 0.17148 = 0.18036 c = 2 x atan2(0.4247, 0.8955) = 0.8745 rad d = 6,371 x 0.8745 = 5,571 km
📐
Try it yourself — free
Distance Calculator · no sign-up, instant results
Open Distance Calculator →
← All Articles