Distance Formula Calculator

Calculate the distance between two points in 2D or 3D coordinate space.
Also finds the midpoint, slope, and Manhattan distance.

Distance

What Is the Distance Formula?

The distance formula calculates the straight-line (Euclidean) distance between two points in a coordinate system. It is a direct application of the Pythagorean theorem extended into two or three dimensions.

2D Distance Formula

For two points (x₁, y₁) and (x₂, y₂):

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

3D Distance Formula

For two points (x₁, y₁, z₁) and (x₂, y₂, z₂):

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

Derivation from the Pythagorean Theorem

In 2D, if you draw a right triangle between two points, the horizontal leg has length |x₂ − x₁|, the vertical leg has length |y₂ − y₁|, and the hypotenuse is the distance d. By Pythagoras: d² = (x₂−x₁)² + (y₂−y₁)² → d = √(…).

The 3D formula is simply the Pythagorean theorem applied twice — first across the horizontal plane, then combined with the vertical difference.

Midpoint Formula

The midpoint between two points is:

Midpoint 2D = ((x₁+x₂)/2, (y₁+y₂)/2)

Midpoint 3D = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2)

Slope (2D only)

The slope of the line connecting two points:

m = (y₂ − y₁) / (x₂ − x₁)

A positive slope means the line goes upward from left to right. A negative slope goes downward. A horizontal line has slope 0. A vertical line has undefined slope.

Euclidean vs. Manhattan Distance

Euclidean distance (the straight-line formula above) is the “as the crow flies” distance — the shortest possible path between two points.

Manhattan distance (also called taxicab or city block distance) is the sum of absolute differences:

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

Manhattan distance is named after Manhattan’s grid street layout — if you can only travel horizontally or vertically (like blocks in a city), this is the actual travel distance.

Real-World Applications

  • GPS navigation: The distance formula calculates straight-line distances between coordinates (latitude/longitude, when simplified)
  • Computer graphics: Collision detection, ray casting, determining if a point is inside a circle
  • Machine learning: The k-nearest neighbor (KNN) algorithm uses Euclidean distance to find the closest data points to a query
  • Game development: Pathfinding algorithms (A* uses distance estimates)
  • Robotics: Motion planning, calculating distances between robot joints

Worked Example

Find the distance between points A(2, 3) and B(7, 11): d = √((7−2)² + (11−3)²) = √(25 + 64) = √89 ≈ 9.434

Midpoint: ((2+7)/2, (3+11)/2) = (4.5, 7)

Slope: (11−3)/(7−2) = 8/5 = 1.6

Don’t use this for latitude and longitude. The distance formula assumes a flat plane. Earth’s surface is curved, so treating lat/lon as Cartesian (x, y) coordinates and plugging them into d = √((Δlat)² + (Δlon)²) produces wrong answers — especially over long distances or at high latitudes where one degree of longitude shrinks toward the poles. For real-world great-circle distance between two GPS points, use the Haversine formula instead: it accounts for the spherical geometry and gives the true “as the crow flies” distance on Earth.


How we build and check this calculator

This calculator runs entirely in your browser, so the numbers you enter stay on your device. The math behind it is written by hand and tested against worked examples and standard references before the page goes live.

SuperGlobalCalculator is independently built and maintained. See how we build and verify our calculators.


Embed This Calculator

Copy the code below and paste it into your website or blog.
The calculator will work directly on your page.