Math
Distance and midpoint calculator
Enter two points to get the distance between them, the midpoint, the slope and the equation of the line through them. Distances are given as simplified surds such as 2√13 as well as decimals, and a 3D mode handles points (x, y, z).
Show the working, step by step
Subtract the coordinates of A from those of B.
Δx = 8 − 2 = 6 Δy = 3 − (−1) = 4
Distance formula: d = √((x₂ − x₁)² + (y₂ − y₁)²).
d = √(6² + 4²) = √52 = 2√13 ≈ 7.2111
Midpoint formula: average the x-coordinates and the y-coordinates.
M = ((2 + 8)/2, (−1 + 3)/2) = (5, 1)
Slope m = Δy ÷ Δx.
m = 4 ÷ 6 = 2/3
Equation of the line through A and B.
y + 1 = (2/3)(x − 2) y = (2/3)x − 7/3 2x − 3y − 7 = 0
The formulas
For A(x₁, y₁) and B(x₂, y₂):
Distance: d = √( (x₂ − x₁)² + (y₂ − y₁)² ) Midpoint: M = ( (x₁ + x₂)/2, (y₁ + y₂)/2 ) Slope: m = (y₂ − y₁) / (x₂ − x₁) Line: y − y₁ = m(x − x₁)
In three dimensions each formula gains a z term: d = √(Δx² + Δy² + Δz²) and M = ((x₁ + x₂)/2, (y₁ + y₂)/2, (z₁ + z₂)/2).
A worked example
The calculator starts with A(2, −1) and B(8, 3).
- Differences: Δx = 8 − 2 = 6 and Δy = 3 − (−1) = 4.
- Distance: √(6² + 4²) = √52. Since 52 = 4 × 13, this is 2√13 ≈ 7.2111.
- Midpoint: ((2 + 8)/2, (−1 + 3)/2) = (5, 1).
- Slope: 4 ÷ 6 = 2/3.
- Line: y + 1 = (2/3)(x − 2), which rearranges to y = (2/3)x − 7/3, or 2x − 3y − 7 = 0 with whole-number coefficients.
In 3D mode the default points are (1, 2, 3) and (4, 6, 15). The differences 3, 4, 12 give a distance of √169 = 13 exactly, the midpoint (5/2, 4, 9), and direction cosines 3/13, 4/13 and 12/13.
Where these formulas are used
- Checking the shape of a figure: equal side lengths for a rhombus or an isosceles triangle, or equal diagonals for a rectangle.
- Circles: the radius is the distance from the centre to a point on the circle, and the centre of a circle with a given diameter is the diameter’s midpoint.
- Perpendicular bisectors: they pass through the midpoint with slope −1/m.
- Maps and games: straight-line (Euclidean) distance between two grid positions.
Common mistakes
- Subtracting a negative coordinate wrongly. 3 − (−1) is 4, not 2. Write the brackets in.
- Adding before squaring. √(6² + 4²) is not 6 + 4. The distance is always shorter than the sum of the horizontal and vertical changes.
- Subtracting in the midpoint formula. The midpoint adds the coordinates and halves them; the distance subtracts them.
- Mixing the order in the slope. Use y₂ − y₁ over x₂ − x₁, taking both from the same point first.
Common questions
What is the distance formula?
d = √((x₂ − x₁)² + (y₂ − y₁)²). It is Pythagoras’ theorem: the horizontal
change and the vertical change are the two shorter sides of a right-angled triangle, and the
distance is the hypotenuse. From (2, −1) to (8, 3) the changes are 6 and 4, so
d = √(36 + 16) = √52 = 2√13 ≈ 7.2111.
How do you simplify a square root like √52?
Take out the largest square factor: 52 = 4 × 13, so √52 = √4 × √13 = 2√13. Exam answers usually expect this simplified surd rather than the decimal 7.2111. The calculator shows both.
What is the midpoint formula?
Average the coordinates: M = ((x₁ + x₂)/2, (y₁ + y₂)/2). The midpoint of
(2, −1) and (8, 3) is (10/2, 2/2) = (5, 1). In 3D add a third coordinate, (z₁ + z₂)/2. To
find a missing endpoint from the midpoint, use B = 2M − A.
Does the order of the points matter?
Not for the distance or the midpoint: swapping A and B squares the same differences and averages the same numbers. The slope is also unchanged, because both the rise and the run change sign. Only the direction ratios in 3D reverse sign, which describes the same line pointing the other way.
How do you find the distance between two points in 3D?
Add the third difference under the root: d = √(Δx² + Δy² + Δz²). From
(1, 2, 3) to (4, 6, 15) the differences are 3, 4 and 12, so d = √(9 + 16 + 144) = √169 = 13.
Choose “3D” above for this, along with the direction cosines 3/13, 4/13, 12/13.
What if the two x-coordinates are the same?
The points are on a vertical line, x = constant. The distance is just the difference in y, the slope is undefined (you would divide by zero), and the equation of the line is x = x₁ rather than y = mx + c.
Related calculators
-
Straight line equation
Every form of the line’s equation from points, slope or intercepts.
-
Point calculator
Divide a segment in any ratio; triangle centroid and area.
-
3D geometry
Direction cosines, lines and planes in three dimensions.
-
Vector magnitude and direction
Length and direction angle of a vector.