The distance between two points is the length of the straight segment joining them. Coordinates let us calculate that length without measuring a drawing. The key is to use the horizontal and vertical changes as the legs of a right triangle.
This page uses ordinary Euclidean distance in a rectangular coordinate system with perpendicular axes and compatible length units. A road route, a grid-constrained route and a straight-line separation need not have the same length.
On this page
Deriving the distance formula
Let and . Their horizontal separation has length and their vertical separation has length . By the Pythagorean theorem,
Distance is non-negative, so take the principal square root:
The absolute-value signs are unnecessary inside the squares because a number and its negative have the same square. The derivation, rather than the appearance of the diagram, is what justifies the formula. See the OpenStax distance-formula treatment.
A diagonal and its perpendicular components
Diagram explanation and exact data
The coordinate differences are 6 and 8. The Pythagorean calculation is d² = 6² + 8² = 100. Equal unit scales keep the triangle proportional.
| Object | Exact coordinates or length |
|---|---|
| A | |
| B | |
| Right-angle corner | |
| Horizontal leg | |
| Vertical leg | |
| Diagonal |
Worked example: a 6–8–10 triangle
Find the distance from to .
Calculate both differences
Apply the formula
The distance is 10 coordinate units. If each unit represents a metre, it is 10 m. It is not units: that is the length of a route following the horizontal and vertical legs.
The answer is reasonable because the diagonal must be longer than either leg, but shorter than travelling both legs consecutively when both legs are non-zero.
An exact answer need not be an integer
For and ,
The exact distance is units. The decimal is an approximation to three decimal places. Keep the radical during later algebra if an exact answer is needed; early rounding can change subsequent results.
The negative vertical change does not make the distance negative. It records direction before squaring, whereas distance records length.
Horizontal, vertical and identical points
If the points have the same -coordinate, the vertical difference is zero, so the formula reduces to . The distance from to is therefore 8 units.
If the points have the same -coordinate, use . For identical points, both differences are zero and the distance is zero. No special exception to the formula is needed.
Changing the endpoint order leaves the result unchanged:
Both coordinate differences reverse sign together, but their squares do not change. This also provides a useful check on a calculation involving negative coordinates.
Units and scale
Suppose a rectangular site plan uses 2 m per horizontal coordinate unit and 3 m per vertical coordinate unit. A change of in the drawing represents physical changes of 6 m and 12 m. The physical separation is
Calculating first and multiplying by a single scale factor would be wrong because no single scale factor applies to both directions.
Likewise, coordinates such as “seconds” and “degrees Celsius” should not be combined under this formula to claim a physical length. The coordinate axes must describe compatible spatial quantities.
Use squared distance when only a comparison is needed
Square roots preserve order for non-negative inputs. To decide which of two points is closer to the origin, compare their squared distances.
For and ,
Since , is closer. There is no need to approximate either square root. This same idea makes circle membership tests efficient: compare the squared distance from the centre with .
Avoid mixing directions and lengths
Subtract corresponding coordinates: an -coordinate from an -coordinate, and a -coordinate from a -coordinate. Write parentheses around negative values. In particular, , not 2.
Square each complete difference before adding. The expression is not generally . Finally, take one square root of the sum; adding the two separate square roots computes a different length.
Practice questions
- Find the exact distance between and .
- Find the distance between and .
- A plan uses m per unit on both axes. How far apart physically are and ?
Check your answers
- units.
- The points are on one horizontal line. Their separation is units.
- Their coordinate distance is 10 units, so the physical distance is m. A single scale factor is valid here because both axes use the same scale.
Related topics
Midpoint Formula locates the centre of a segment. Circles in Coordinate Geometry uses a fixed distance to define an entire curve.
