Math

Distance Calculator

The distance between two points is the length of the hypotenuse of the right triangle whose legs are the horizontal and vertical gaps. Give the calculator two (x, y) pairs and it returns the distance, the midpoint of the segment, and the slope of the line joining them.

Result
—
Distance
—
Midpoint
—
Horizontal gap (Δx)
—
Vertical gap (Δy)
—
Slope of the line
—

How the distance formula works

Two points form the hypotenuse of a right triangle, with the horizontal difference Δx = x₂ − x₁ as one leg and the vertical difference Δy = y₂ − y₁ as the other. By the Pythagorean theorem the straight-line distance is:

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

The midpoint of a segment is simply the average of the endpoints, ((x₁+x₂)/2, (y₁+y₂)/2) — the one point on the segment equidistant from both ends. The slope of the joining line is Δy ÷ Δx, and when Δx is zero the line is vertical so the slope is undefined.

Worked example

Distance from (0, 0) to (3, 4): Δx = 3, Δy = 4, so d = √(9 + 16) = √25 = 5 — the classic 3-4-5 right triangle, the exact case Pythagoras used. The midpoint is (1.5, 2) and the slope is 4 ÷ 3 ≈ 1.333. Two points like (2, 5) and (8, 1) give Δx = 6, Δy = −4, so d = √(36 + 16) = √52 ≈ 7.211 and the slope is −0.667, a line falling to the right.

Where this shows up in real work

Screen sizes and aspect ratios (is a 16:9 laptop actually 13.3″ wide?), map and floor-plan measurements, vector graphics and game development, machine-vision part picking, and navigation all reduce to this one formula. In 3D, extend it to a third term: d = √(Δx² + Δy² + Δz²).

Frequently asked questions

1. How do you calculate the distance between two points?

Take the square root of the sum of the squared differences in each coordinate: d = √[(x₂−x₁)² + (y₂−y₁)²]. This is the Pythagorean theorem applied to the horizontal and vertical gaps.

2. What is the midpoint of two points?

Average the coordinates: ((x₁+x₂)/2, (y₁+y₂)/2). The midpoint is the only point on the line segment equidistant from both endpoints.

3. What is the slope of the line between two points?

Slope is Δy ÷ Δx = (y₂−y₁)/(x₂−x₁). If both x values are equal the line is vertical and the slope is undefined rather than infinite in practice.

4. How do I find distance in 3D?

Add a third squared term: d = √(x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)². The same logic extends to any number of dimensions.

Related tools