Quick Answer: The distance between (1, 2) and (4, 6) is 5: the differences are 3 and 4, and √(3² + 4²) = √25 = 5. The midpoint is (2.5, 4).
What does this calculator do?
This distance formula calculator finds the straight-line distance between two points in a plane or in space, gives it in exact radical form when it is not a whole number, and also returns the midpoint of the segment and the Manhattan (taxicab) distance.
The distance formula is the Pythagorean theorem in coordinates. The horizontal and vertical differences between two points are the two legs of a right triangle, and the straight line between the points is its hypotenuse. In three dimensions a third squared difference is added under the root. The midpoint is simply the average of the two points, coordinate by coordinate.
The squared distance is computed as an exact fraction before the square root is taken, so a distance like √72 can be reported exactly as 6√2 as well as in decimal form.
Using the Distance Formula Calculator
- Choose two or three dimensions.
- Enter the coordinates of both points. The z boxes only appear in three dimensions.
- Read the distance at the top. The cards give the exact form, the midpoint, the distance squared, the coordinate differences and the Manhattan distance.
How is this calculated?
- Differences. Each coordinate of the first point is subtracted from the matching coordinate of the second, exactly.
- Distance squared. The differences are squared and added. This is the number under the square root.
- Distance. The square root of that sum, to 34 significant digits, shown to 15.
d = √((x₂ − x₁)² + (y₂ − y₁)²); d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)
- Exact form. When the distance squared is a whole number up to 10¹², it is factored into primes, and each pair of a prime comes out of the square root. √72 = √(36 × 2) = 6√2. A perfect square gives a whole number, marked exact.
- Midpoint. The average of each coordinate.
M = ((x₁ + x₂)/2, (y₁ + y₂)/2)
- Manhattan distance. The sum of the absolute differences, |x₂ - x₁| + |y₂ - y₁| (plus |z₂ - z₁| in 3D), which is the distance travelled along a grid of streets instead of in a straight line.
Worked Example
Using the defaults, (1, 2) and (4, 6):
- Differences: Δx = 3, Δy = 4.
- Distance squared: 3² + 4² = 9 + 16 = 25.
- Distance: √25 = 5, a whole number, so the exact form is 5 (exact).
- Midpoint: ((1 + 4)/2, (2 + 6)/2) = (2.5, 4).
- Manhattan distance: 3 + 4 = 7, longer than the straight line, as it always is unless the points share a coordinate.
A distance with a root left in it, from the (0, 0) to (6, 6) preset: 6² + 6² = 72, and √72 = 6√2, or 8.48528137423857.
What Is the Distance Formula?
d = √((x₂ - x₁)² + (y₂ - y₁)²). It measures the length of the straight segment joining two points, and it comes straight from the Pythagorean theorem: the segment is the hypotenuse of a right triangle whose legs are the horizontal and vertical gaps. Because the differences are squared, it does not matter which point you call the first.
The (-3, 5) to (2, -7) preset spans two quadrants: the gaps are 5 and -12, and the distance is 13.
How Do You Calculate the Midpoint?
Add the two x coordinates and halve, then do the same with the y coordinates (and z, in 3D). The midpoint of (-3, 5) and (2, -7) is (-0.5, -1). The midpoint is the same distance from both ends, half the full distance from each.
What Is Manhattan Distance?
The distance between two points if you can only move along the axes, like a taxi on a street grid. NIST's Dictionary of Algorithms and Data Structures defines it as the sum of the absolute differences of the coordinates. For the (1, 2, 3) to (4, 6, 15) preset, the straight-line distance is 13 but the Manhattan distance is 19.
It is used in grid path-finding, in comparing data points in machine learning, and in city planning.
When Should You Use Manhattan Distance Instead?
Use the straight-line distance when movement is free in every direction: a drone, a cable run across open ground, the length of a brace. Use the Manhattan distance when movement is confined to a grid: walking city blocks laid out north to south and east to west, a forklift moving along warehouse aisles, or a chess rook.
The Manhattan figure is always at least as large as the straight-line one, and the two are equal only when the points lie on the same horizontal or vertical line.
Distance from the Origin to Common Points
The reference table gives the distance from (0, 0) to familiar points. Several rows, (3, 4), (5, 12), (8, 15) and (7, 24), are Pythagorean triples, where the distance comes out as a whole number. The others show their exact radical form.
What does this calculator not account for?
- Distance on the Earth. Latitude and longitude are angles on a sphere, not flat coordinates. The distance between two places needs a great-circle formula, not this one.
- Units. Both points must use the same unit; the distance comes out in that unit.
- Distance from a point to a line. Only point-to-point distances are computed.
- More than three dimensions. The formula extends naturally, but the calculator stops at three.
What mistakes do people make with this?
- Forgetting to square the differences. Adding the plain differences gives the Manhattan distance, not the straight-line one.
- Sign errors in the differences. Squaring removes the sign, but subtract matching coordinates: x from x, y from y.
- Taking the square root of each term. √(9 + 16) is 5, not 3 + 4.
- Averaging the wrong way for the midpoint. The midpoint averages the coordinates; it is not half of the differences.
- Rounding before the root. Keep the sum of squares exact, then take the root.
Frequently Asked Questions
What is the distance between (1, 2) and (4, 6)?
How do I find the distance in 3D?
Can a distance be negative?
How is the distance formula related to the Pythagorean theorem?
What if the coordinates are decimals?
Sources
- NIST Dictionary of Algorithms and Data Structures, Euclidean distance: the straight-line distance between two points. xlinux.nist.gov/dads/HTML/euclidndstnc.html
- NIST Dictionary of Algorithms and Data Structures, Manhattan distance: the sum of the absolute differences along axes at right angles. xlinux.nist.gov/dads/HTML/manhattanDistance.html

