The three formulas
Distance, midpoint, and slope between two points — each computed component-by-component.
Distance between two points: d = √((x₂ − x₁)² + (y₂ − y₁)²). This is the straight-line length of the segment connecting P₁ and P₂.
Midpoint: M = ((x₁ + x₂)/2, (y₁ + y₂)/2). Literally the average of the two points' coordinates.
Slope (line through the two points): m = (y₂ − y₁) / (x₂ − x₁). Positive slope rises left-to-right; negative slopes fall; zero is horizontal; undefined when x₁ = x₂ (vertical).
- Δx = 4 − 1 = 3, Δy = 6 − 2 = 4
- Distance: √(3² + 4²) = √25 = 5
- Midpoint: ((1+4)/2, (2+6)/2) = (2.5, 4)
- Slope: 4/3 ≈ 1.333
Compute the deltas first — then distance is √(sum of squared deltas), midpoint is the average, and slope is Δy/Δx.
Where the distance formula comes from
The 2D distance formula is the Pythagorean theorem applied to a right triangle with horizontal and vertical legs.
Picture two points P₁ and P₂ in the plane. Draw a horizontal line from P₁ and a vertical line from P₂ so they meet at a right angle. The horizontal leg has length |Δx| and the vertical leg has length |Δy|. The segment P₁P₂ is the hypotenuse of this right triangle.
By the Pythagorean theorem: (P₁P₂)² = (Δx)² + (Δy)². Taking the square root of both sides gives the distance formula. The squares kill the sign, so you don't need absolute values.
This is why the distance calculator is so closely related to the Pythagorean theorem calculator — in 2D they're computing the same thing from different inputs.
The 2D distance formula is just a² + b² = c² in disguise. That connection makes the √(Δx² + Δy²) shape memorable.
Slope edge cases — horizontal and vertical lines
Horizontal lines have slope 0. Vertical lines have slope undefined (division by zero). The calculator reports both explicitly.
Horizontal line (y₁ = y₂): Δy = 0, so slope = 0/Δx = 0. The line rises at zero degrees — perfectly flat.
Vertical line (x₁ = x₂): Δx = 0, so slope = Δy/0 — division by zero, undefined. The calculator shows "undefined (vertical line)" rather than NaN or 0.
Near-vertical lines (x₁ ≈ x₂) yield huge slope values but remain defined. The calculator uses a small tolerance (~1e-12) to distinguish "truly vertical" from "very steep."
- (0,0) → (5,5): slope = 5/5 = 1 (positive)
- (0,5) → (5,5): slope = 0/5 = 0 (horizontal)
- (5,0) → (5,5): slope = 5/0 = undefined (vertical)
Always check Δx before reporting slope. Zero → horizontal (slope 0). x₁ = x₂ → vertical (slope undefined).
3D extension
Distance and midpoint extend naturally to 3D by adding a z-term. Slope doesn't — use direction vectors instead.
3D distance: d = √((Δx)² + (Δy)² + (Δz)²). Same Pythagorean logic, one more term.
3D midpoint: M = ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2). Average each coordinate.
Slope in 3D doesn't work — a line in 3-space isn't described by a single slope number. Instead, use the direction vector (Δx, Δy, Δz), optionally normalized to unit length.
- Δx = 2, Δy = 3, Δz = 6
- Distance: √(4 + 9 + 36) = √49 = 7
- Midpoint: (1, 1.5, 3)
- Direction vector: (2, 3, 6), or normalized: (2/7, 3/7, 6/7)
In 3D, distance gets a z-term, midpoint averages three coordinates, and slope is replaced by a direction vector.
Four common mistakes
Coordinate-formula bugs cluster around sign errors and mode mixing.
1. Forgetting to square the deltas. The formula is √((Δx)² + (Δy)²), not √(Δx + Δy). Always square first, then sum, then √.
2. Swapping subtraction order for slope. (y₂−y₁)/(x₂−x₁) must use the same order top and bottom. Flipping one without the other changes the sign.
3. Using 2D mode on 3D points. If your points have a z coordinate, 2D mode silently ignores it and gives the xy-plane projection — not the true 3D distance.
4. Treating a vertical line as slope zero. Zero and undefined are different. Horizontal (y₁=y₂) → slope 0. Vertical (x₁=x₂) → slope undefined.
Always square before summing, keep the subtraction order consistent, match the mode (2D vs 3D) to your data, and distinguish zero from undefined slope.
Frequently Asked Questions
Is this the same as the distance formula I learned in algebra?
▾
Is this the same as the distance formula I learned in algebra?
▾Yes — the 2D formula √((x₂−x₁)² + (y₂−y₁)²) is the standard "distance formula" from Algebra I / coordinate geometry, and this calculator implements it directly. The 3D mode adds a z-term for 3-space problems.
Why is slope "undefined" for a vertical line?
▾
Why is slope "undefined" for a vertical line?
▾Slope is defined as Δy/Δx. When x₁ = x₂, Δx = 0, and division by zero is undefined in mathematics. Geometrically, a vertical line has "infinite" steepness. The calculator reports this as "undefined" rather than returning a very large number or NaN, so you can tell the difference between a very steep line and a truly vertical one.
Does the calculator handle negative coordinates?
▾
Does the calculator handle negative coordinates?
▾Yes — all coordinate fields accept negative numbers. The deltas (x₂−x₁, etc.) can be negative, but their squares are always positive, so distance is always non-negative. Slope can be negative (downward-sloping lines).
How is this different from the Pythagorean theorem calculator?
▾
How is this different from the Pythagorean theorem calculator?
▾In 2D, the distance formula is literally the Pythagorean theorem applied to the deltas Δx, Δy. The Pythagorean calculator takes two legs and computes the hypotenuse; the distance calculator takes two points and computes the line between them (which is the hypotenuse of the triangle formed by the deltas). Same math, different inputs.
Can I use this for geographic distance (lat/long)?
▾
Can I use this for geographic distance (lat/long)?
▾For small distances (within a city or region), yes — treat lat/long as xy and the result is a close approximation. For continental or global distances, the Earth's curvature matters and you need the haversine formula (great-circle distance) instead. This calculator is straight-line Euclidean distance.
Open the Distance & Midpoint Calculator
Enter two points in 2D or 3D — get the distance, midpoint, slope (2D), and a coordinate-grid visual with every step shown.
Open calculator