CompoundPage

Distance Formula Calculator

The distance formula is the Pythagorean theorem with the triangle left implicit. This distance formula calculator draws it back in.

When finding the other endpoint, the midpoint's x.

When finding the other endpoint, the midpoint's y.

Distance10

Distance sqrt((7 - 1)^2 + (10 - 2)^2) = sqrt(6^2 + 8^2) = sqrt(100)
10
The triangle The two points define a right triangle whose legs are parallel to the axes. The distance formula is the Pythagorean theorem applied to it, which is why the differences are squared. Squaring also disposes of the sign, so the order of the points does not matter.
legs 6 and 8, hypotenuse 10
Exact value A whole-number distance, so these points sit on a Pythagorean triple.
10
Midpoint The average of the coordinates, separately in each axis. Unlike the distance it needs no squaring, because averaging is linear.
(4, 6)
Slope Rise over run. The same two differences that give the distance also give the slope, but divided instead of squared and added.
4/3
Horizontal and vertical change Signed, unlike their contributions to the distance. Direction survives here and is squared away in the distance.
dx = 6, dy = 8
Taxicab distance Distance if you can only travel along the axes, as on a street grid. Always at least the straight-line distance and at most sqrt(2) times it. The gap between the two is why a diagonal shortcut across a park saves up to 29% of the walk.
14

How the Distance Formula Calculator works

The distance formula looks like something to memorize. It is the Pythagorean theorem with the triangle left out of the picture, and once you draw the triangle back in there is nothing left to remember.

Take two points. Draw a horizontal line from the first and a vertical line from the second; they meet at a right angle, and the three points form a right triangle. The horizontal leg is the difference in x, the vertical leg the difference in y, and the distance you want is the hypotenuse. Pythagoras says the hypotenuse squared is the sum of the squares of the legs, so the distance is the square root of (x2 - x1) squared plus (y2 - y1) squared. That is the formula, and it is derived rather than declared.

For the default points, (1, 2) and (7, 10), the legs are 6 and 8, the squares are 36 and 64, they add to 100, and the distance is the square root of 100, which is 10. That is the 6-8-10 triangle, a multiple of 3-4-5.

Two things fall out of that derivation. First, the order of the points does not matter: the differences change sign, and squaring removes the sign, so the distance from A to B equals the distance from B to A. Second, the formula extends to any number of dimensions without changing shape: in three dimensions add a dz squared term under the same root, and in n dimensions add n of them. That generalization is the Euclidean norm, and it is the reason this one piece of school geometry turns up constantly in machine learning, where "distance" between two points of a hundred-dimensional feature space means exactly this.

When the sum of the squares is not a perfect square, the distance is irrational, and this calculator gives it in simplest radical form as well as a decimal: (0, 0) to (4, 6) is the square root of 52, which is 2√13, about 7.2111026.

The midpoint is the easier sibling and is often taught alongside: average the x coordinates, average the y coordinates. No squaring, because averaging is linear and distance is not. For (1, 2) and (7, 10) it is (4, 6). Choose the midpoint mode for the steps and the perpendicular bisector, or the endpoint mode to run it backward.

Slope uses the same two differences and combines them differently (divided rather than squared and summed), which is worth noticing because it explains why slope can be undefined while distance never is. A vertical line has a run of zero, and dividing by it fails; but the distance is the vertical leg and is perfectly ordinary.

Finally, straight-line distance is a choice rather than the only option. Taxicab distance, the sum of the absolute differences, is what you actually travel on a street grid, and it is always at least the straight-line distance and at most about 1.41 times it. The gap between the two is why cutting diagonally across a square park saves you 29% of the walk, and why cities with diagonal avenues feel faster to cross than ones without.

Distance Formula Calculator FAQ

What is the distance formula?

d = sqrt((x2 - x1)^2 + (y2 - y1)^2). It is the Pythagorean theorem applied to the right triangle whose legs are the horizontal and vertical differences between the two points.

Does the order of the points matter?

No. Swapping them flips the sign of both differences, and squaring removes the sign, so the result is identical. That is a useful check: if a calculation gives a different answer in the other order, the squaring went wrong somewhere.

How do I find the distance in three dimensions?

Add another squared term under the root: sqrt(dx^2 + dy^2 + dz^2). The formula keeps its shape in any number of dimensions, which is why the same expression appears in machine learning as the Euclidean distance between feature vectors.

What is the midpoint formula?

Average each coordinate separately: ((x1 + x2)/2, (y1 + y2)/2). No squaring and no root, because averaging is a linear operation while distance is not.

Why is my distance not a whole number?

Because most are not. The distance is a square root, and a square root is only rational when the sum of the squares happens to be a perfect square, which is what a Pythagorean triple is. 3-4-5 and 5-12-13 work; almost nothing else does. The exact answer is the radical, such as 2√13, and the decimal is a rounding of it.

What is taxicab distance?

The sum of the absolute differences, |dx| + |dy|: how far you travel when restricted to a street grid. It is always at least the straight-line distance and at most sqrt(2) times it, so a diagonal shortcut saves up to 29% of the walk.

More Distance Formula Calculator pages

Related calculators

Embed this calculator
<div id="compoundpage-distance-formula-calculator"></div>
<script src="https://compoundpage.com/embed/distance-formula-calculator.js" async></script>

The same calculation as JSON