Home › Math › Midpoint & Distance Calculator

Midpoint & Distance Calculator

Enter two points and this calculator finds the distance between them, the exact midpoint, the slope of the segment, and the equation of the line through them — in two dimensions, or in three by switching on the z-coordinates.

Distance uses Pythagoras: in 2D, √((x₂ − x₁)² + (y₂ − y₁)²); in 3D the z-difference is added under the root. The slope is undefined for a vertical line (x₁ = x₂) — the calculator says so instead of dividing by zero. Results are exact geometry, rounded to four decimals.

How it works

Distance (2D): d = √((x₂ − x₁)² + (y₂ − y₁)²) — Pythagoras applied to the horizontal and vertical gaps. In 3D the z-gap is added under the root. Midpoint: average each coordinate separately, e.g. midpoint x = (x₁ + x₂) ÷ 2. Slope: m = (y₂ − y₁) ÷ (x₂ − x₁), the rise over the run. Line equation: y = mx + b, where b = y₁ − mx₁. Worked example: points (1, 2) and (4, 6): midpoint = ((1+4)÷2, (2+6)÷2) = (2.5, 4); distance = √(3² + 4²) = √25 = 5; slope = 4÷3 = 1.3333; line: y = 1.3333x + 0.6667.

Frequently asked questions

What is the midpoint used for in real life?

Any time you need the centre of a segment: placing a fence post halfway between two corners, finding the middle of a route between two addresses, or bisecting a line in construction and CAD work.

Why is the slope undefined for a vertical line?

Slope is rise over run, and a vertical line has zero run — dividing by zero has no answer. The calculator reports it as undefined and gives the equation x = constant instead of inventing a number.

What is the difference between distance and displacement?

Here they are the same straight-line length. If you travel a winding road between the two points, your travelled distance is longer; this calculator gives the shortest, straight-line distance.

Do the units matter?

Only that both points use the same units — metres, feet, pixels or grid squares. The distance comes out in those units, and the midpoint coordinates are in the same coordinate system as the inputs.

How does the 3D version work?

It adds the z-difference under the square root: d = √((Δx)² + (Δy)² + (Δz)²), and averages all three coordinates for the midpoint. Slope and a single line equation do not apply in 3D, so they are omitted in that mode.

Related calculators

Triangle Calculator Area Calculator Length Converter