StatGardenREF. DESK
Calculators/Geometry/Distance, midpoint & slope
Geometry

Distance, midpoint & slope calculator

Everything about the line between two points.

What this calculator does

Given two points on a plane, a handful of figures describe everything about the line between them: how far apart they are, the point exactly halfway, how steeply the line rises or falls, and the equation of the line itself. All of it comes from nothing more than the four coordinates.

Distance uses Pythagoras directly: the horizontal and vertical gaps between the points form the two legs of a right triangle, and the distance is its hypotenuse. Slope is the ratio of those same two gaps, rise over run, and is undefined rather than zero when the line is perfectly vertical.

The formula

Formulad = √((x₂−x₁)² + (y₂−y₁)²); m = (y₂−y₁)/(x₂−x₁); midpoint = ((x₁+x₂)/2, (y₁+y₂)/2)

The line equation is built from the slope and one of the two points: y = mx + c, where m is the slope and c is found by substituting a known point back in. When the run (the horizontal gap) is zero, no slope exists: the line is vertical, and its equation is simply x equal to a constant instead.

TermMeaning
(x₁, y₁), (x₂, y₂)The two points.
Distance√((x₂−x₁)² + (y₂−y₁)²): the straight-line gap between the points.
MidpointThe point exactly halfway between them, averaging each coordinate.
Slope (m)Rise over run, (y₂−y₁) ÷ (x₂−x₁): undefined for a vertical line.

The inputs explained

FieldWhat to enter
x₁The x-coordinate of the first point.
y₁The y-coordinate of the first point.
x₂The x-coordinate of the second point.
y₂The y-coordinate of the second point.

When to use it

Finding the straight-line distance on a map or plan

Given two locations by their coordinates, on a site plan, a map grid or a floor layout, the distance figure is the direct line between them, not a route around obstacles.

Working out the grade or slope of a path, road or drain

Slope here is the same rise-over-run figure used for gradients, expressed as a plain ratio rather than a percentage: multiply by 100 to convert.

Finding the centre point between two locations

The midpoint is exactly halfway between the two points on both axes, useful for placing a meeting point, a support, or the centre of a span.

Writing the equation of a line through two known points

Once the slope is known, the line equation lets you find the y-value at any x along that same line, or check whether a third point lies on it.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

Distance and slope from the origin, y fixed at 4

A point moving away from the origin along a fixed height of 4, with the horizontal distance increasing each time.

From (0, 0)
x₂DistanceSlopeAngle from horizontal
14.1234.00075.96°
35.0001.33353.13°
67.2110.666733.69°
99.8490.444423.96°
1212.6490.333318.43°
At x₂ = 3 the distance comes out to exactly 5: a 3-4-5 right triangle, the most familiar Pythagorean triple, formed here by the horizontal gap of 3 and vertical gap of 4. Had x₂ been 0 instead, the line would run straight up with no horizontal run at all, which is the one case where slope is undefined rather than a number.

Distance from the origin with the horizontal gap fixed at 8

The horizontal gap held at 8 while the vertical gap increases, passing through two whole-number distances.

From (0, 0) to (8, y₂)
y₂DistanceMidpointSlope
08.000(4.000, 0)0
38.544(4.000, 1.500)0.3750
610.000(4.000, 3.000)0.7500
912.042(4.000, 4.500)1.125
1517.000(4.000, 7.500)1.875
At y₂ = 6 the distance is exactly 10: an 8-6-10 triangle, the 3-4-5 triple doubled. At y₂ = 15 it lands on exactly 17, the 8-15-17 triple, another of the small handful of Pythagorean triples with whole-number sides.

Questions

How do I find the distance between two points?

Subtract the x-coordinates and the y-coordinates separately, square each difference, add them together, then take the square root: the standard Pythagorean distance formula.

Why is slope sometimes “undefined” rather than a number?

Slope is rise divided by run. When both points share the same x-coordinate, the run is zero, and dividing by zero has no defined result: the line is vertical, described by x equal to a constant instead of y = mx + c.

How do I find the midpoint between two points?

Average the two x-coordinates and average the two y-coordinates separately. The result is the point exactly halfway along the straight line joining them.

What does the angle from horizontal tell me?

It is the slope expressed as an angle instead of a ratio, found with the arctangent of rise over run. A slope of 1 corresponds to exactly 45°; a horizontal line is 0° and a vertical line is 90°.

How do I check if a third point lies on the same line?

Substitute its x-coordinate into the line equation this calculator returns. If the resulting y matches the third point’s actual y-coordinate, it lies on the line; if not, it does not.

For the diagonal of a specific rectangle rather than two arbitrary points, see the rectangle calculator. For a triangle formed by three points, use the triangle calculator.