Understanding the distance and midpoint calculator — concept and principle
Given two points, this calculator finds the straight-line (Euclidean) distance between them, the midpoint halfway between them and, for points in a plane, the slope of the line through them. It works in two dimensions (leave both z values at 0) or in three. It is used for coordinate geometry homework, map grids, CAD drawings and game programming.
How it is calculated
- Distance: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²).
- Midpoint: M = ((x₁ + x₂)/2, (y₁ + y₂)/2, (z₁ + z₂)/2).
- Slope (2D): m = (y₂ − y₁) ÷ (x₂ − x₁), ignoring z.
The distance is in the coordinate unit; the slope has no unit.
The principle
The distance formula is the Pythagorean theorem on a coordinate grid. The horizontal difference Δx and the vertical difference Δy are the two legs of a right triangle, and the segment between the points is its hypotenuse, so d² = Δx² + Δy². In three dimensions you apply the theorem a second time with the depth difference Δz, which adds a third squared term. Squaring removes the signs, so it does not matter which point you call the first.
The midpoint is the average of the coordinates, because moving half of Δx and half of Δy from the first point lands exactly halfway along the segment. The slope is "rise over run": how much y changes for each unit of x.
Worked example
- Inputs: P₁ = (1, 2, 0), P₂ = (4, 6, 0).
- Differences: Δx = 3, Δy = 4, Δz = 0.
- Distance: √(3² + 4² + 0²) = √25 = 5.
- Midpoint: ((1 + 4)/2, (2 + 6)/2, 0) = (2.5, 4, 0).
- Slope: 4 ÷ 3 ≈ 1.333333333.
| y₂ | Distance |
|---|---|
| 1.5 | 3.041381265 |
| 3 | 3.16227766 |
| 4.5 | 3.905124838 |
| 6 | 5 |
| 7.5 | 6.264982043 |
| 9 | 7.615773106 |
| 12 | 10.44030651 |
How to read the result
A distance of 5 means the segment is 5 units long however it is oriented. The midpoint (2.5, 4) is equally far, 2.5 units, from each end. A slope of 1.33 means y rises 4 units for every 3 units of x; a positive slope rises to the right, a negative slope falls, 0 is horizontal, and a vertical line (x₁ = x₂) has no defined slope. In 3D the slope output only describes the shadow of the segment on the xy-plane.
Common mistakes
- Subtracting x from y, for example computing x₂ − y₁. Keep each coordinate paired with its own axis.
- Taking square roots term by term: √(9 + 16) is 5, not 3 + 4 = 7.
- Using this formula for long distances on the Earth's surface. Latitude and longitude are angles, not grid coordinates, so use a great-circle (haversine) formula.
Frequently asked questions
How do I find the second endpoint if I know one endpoint and the midpoint?
Double the midpoint and subtract the known endpoint: P₂ = 2M − P₁. With M = (2.5, 4) and P₁ = (1, 2), P₂ = (4, 6).
What is the Manhattan distance between the example points?
|Δx| + |Δy| = 3 + 4 = 7, the length of a path that moves only along the grid lines.
Can the distance be negative?
No. It is a square root of a sum of squares, so it is always zero or positive and zero only when the points coincide.
Sources: Euclid, Elements, Book I, Proposition 47 (Pythagorean theorem) · J. Stewart, Calculus: Early Transcendentals, Cengage, section on three-dimensional coordinate systems