EN

Distance Between Two Points and Midpoint Calculator

Given the coordinates of two points on a plane, the Pythagorean theorem gives the distance between them directly, while averaging their coordinates gives the midpoint of the segment joining them.

Enter the (x, y) coordinates of both points: the calculator gives the distance, the midpoint, and the slope of the line through the two points.

Coordinates of the two points

Point A
Point B
A (1, 2)B (7, 10)M (4, 6)
Sample diagram. It redraws with the values entered after the calculation.

Starred names are defined in the glossary that closes the page.

Distance is Pythagoras on the coordinate gaps

Two points in the plane, A(x₁, y₁) and B(x₂, y₂). Draw the rectangle that has AB as its diagonal. One side is |x₂ − x₁|, the other |y₂ − y₁|. The diagonal is AB.

d= (x2−x1)2 + (y2−y1)2

Pythagoras, nothing else. That is the Euclidean* distance. The squares swallow the signs, so the order of the points does not matter: d(A, B) = d(B, A). One of the two differences zero? The points line up horizontally or vertically, and the formula collapses to an absolute value. Both zero? Same point, distance zero.

Distance has no magic unit. If x and y are in metres, d is in metres. A centimetre mixed with a metre, plugged in raw, is a number that does not mean anything. Both coordinates into the same unit before subtracting. Same habit as a volume in solid geometry: convert first, then calculate. The formula assumes an equal-scale pair of perpendicular axes. One axis in metres and the other in centimetres, or an angle that is not a right angle, and the sketch lies.

Midpoint as the average of two points

The midpoint* of AB is the average of the two endpoints, coordinate by coordinate. No square roots. No distances.

M = ( (x₁ + x₂)/2 , (y₁ + y₂)/2 )

M is the unique point on the segment that sits equally far from A and from B. It is also the centre of the circle with diameter AB (Thales: the angle in a semicircle is a right angle). A GCSE midpoint question is this average and nothing more. A third point turns the problem into a centroid*, which is a different animal: the average of three vertices, G = ((x_A+x_B+x_C)/3, (y_A+y_B+y_C)/3). G also sits two-thirds of the way along each median, measuring from the vertex. That is not the midpoint of a side. Call the midpoint of a side “the centre of the triangle” and a different point has been named (the foot of a median, not G).

This page returns the midpoint of a segment. Not G. Two points in, one point halfway out. A third point belongs on a different tool.

Gradient of AB, and when the line is vertical

The gradient* of the line (AB) — slope, if the US word is preferred; GCSE papers say gradient — is the quotient of the same two differences the distance used: m = (y₂ − y₁) / (x₂ − x₁). Distance squares them and takes a root. The gradient divides them. Same ingredients, different dish.

If x₂ = x₁ the division is illegal: vertical line, undefined gradient, equation x = a constant. The calculator flags that instead of printing infinity. For the full equation, y = mx + b in US texts and y = mx + c in UK ones, plus the general form ax + by + c = 0, the line equation calculator takes the same two points and finishes the job. Here the output stops at d, the midpoint, and m — enough for a midpoint question, not enough to write the line.

A gradient of 1 is 45° on an equal-scale grid. A gradient of 4/3, as in the example below, is a 3-4-5 triangle on its side: 3 along, 4 up, for a distance of 5. In the example everything is doubled (6, 8 and 10) and the gradient stays the same. The three numbers lock together. A percentage gradient is not an angle: 10% means m = 0.10, not 10°. The angle is arctan(m).

Three coordinates: one extra square

One extra coordinate, one extra square. That is the whole change.

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

Still Pythagoras, in two sittings. First the distance in the xy-plane, as above. Then a second right triangle whose legs are that planar distance and |z₂ − z₁|. The single formula is those two steps glued together. A GPS fix with altitude, a robot arm, two fittings in a workshop: as soon as there is an up and a down, the third square earns its keep. Positions given in spherical coordinates — radius, colatitude, longitude — convert to (x, y, z) first; the distance formula then runs on the Cartesian triple, not on the angles.

This page stays in 2D, the case people actually type. For a 3D sum, the move is the same: three differences, three squares, one root. The midpoint stretches the same way, an average of each coordinate, z included. Four dimensions would add a fourth square. The pattern does not get more interesting; it just gets longer.

Reconstructing B from A and the midpoint

The midpoint reads backwards. If M is the midpoint of AB, then B is the reflection of A in M: each coordinate of B is twice the midpoint minus the coordinate of A.

xB = 2xM − xA   ;   yB = 2yM − yA

A and a distance d alone will not pin B to the page. The set of points at distance d from A is a circle (a sphere in 3D). A direction, a gradient, or a second constraint is still required. “B is 10 from A, and AB is horizontal” leaves two answers, left and right. “B is 10 from A and 6 from C” is two circles crossing — none, one or two points, depending. The midpoint determines B on its own. The distance does not. This calculator cannot recover B from d alone: the information is not there.

A related inverse: the point that divides AB in the ratio k : 1, the section formula, is a weighted average rather than a plain half. Midpoint is the case k = 1. Internal division stays on the segment; external division does not.

Worked case: (1, 2) to (7, 10)

A(1, 2), B(7, 10). The gaps are sitting there: 6 to the right, 8 up.

  1. Δx = 7 − 1 = 6, Δy = 10 − 2 = 8.
  2. Distance: √(6² + 8²) = √(36 + 64) = √100 = 10.
  3. Midpoint: ((1+7)/2, (2+10)/2) = (4, 6).
  4. Gradient: 8/6 = 4/3 ≈ 1.333.

That is the 6-8-10, cousin of the 3-4-5. When the gaps are a multiple of a well-known right triangle, the root comes out whole. Not the rule — a gift from the question. Midpoint check: A to M is 3 along and 4 up, half of 6 and 8. M to B, the same. Two equal halves, so it really is the midpoint. The inverse: from A(1, 2) and M(4, 6), B = (2×4 − 1, 2×6 − 2) = (7, 10). The arithmetic closes.

Origin, axes, and the detour through zero

A point in the plane is a pair (x, y). x is read along the horizontal axis, y along the vertical. The origin* O(0, 0) is where they cross. Right of O, x is positive; above, y is. A point (−3, 5) sits left and up. That is the whole convention, and already enough to get the sign of Δx wrong.

The distance from A to B does not go via the origin, unless one of the two points is O. Coordinates are subtracted from each other; they are not “measured each from zero and added”. A classic slip: d = √(x₁² + y₁²) + √(x₂² + y₂²), the two distances to O added. That is a detour through the origin, not the segment AB. Pythagoras runs on the differences, not on the raw coordinates — except, precisely, for the distance to O.

Put B = O(0, 0). What remains is d = √(x₁² + y₁²). That is the length of the vector OA, its magnitude (or modulus, in older A-level language). In physics it is the size of a force, a velocity, a displacement, once the components are known. Park one of the two points at (0, 0) and that magnitude is what the calculator reports. Handy for a vector question, or for checking that a point on the circle x² + y² = r² really is a distance r from O.

Euclidean versus taxicab

This page computes the as-the-crow-flies length. In a city the crow is not the usual traveller. Streets often form a grid. The taxicab* (or Manhattan) distance is |x₂ − x₁| + |y₂ − y₁|: add the gaps, do not root a sum of squares.

Between (1, 2) and (7, 10), Euclidean is 10, taxicab is 6 + 8 = 14. The diagonal short-cut does not exist if the roads run strictly north–south and east–west. A warehouse robot in orthogonal aisles, a counter that moves square by square on a board, without diagonals, a pipe network on a grid: taxicab. A stay, a radio range, a tape across a field: Euclidean. The calculator only does the second. The first is mental arithmetic, and it is always larger, unless the two points already share an axis — in which case the two distances coincide, and the formula has already collapsed to an absolute value.

From two points to the equation of the line

Distance, midpoint and gradient are three readings of the same pair of points. The line through those points is a fourth. Slope-intercept form y = mx + b (US) or y = mx + c (UK) needs m and the intercept; the intercept is y₁ − m x₁. A vertical pair never gets that form: the equation is x = the common abscissa. The line-equation page writes both the intercept form and ax + by + c = 0, and treats the vertical as a case rather than as an infinite slope.

Even so, the numbers already on this page go a long way. A(1, 2), B(7, 10): m = 4/3, intercept 2 − (4/3)×1 = 2/3, so y = (4/3)x + 2/3. The same line in general form: 4x − 3y + 2 = 0 after clearing the fraction. Distance 10 never entered that algebra. It answers a different question: how long is the segment, not which line contains it.

Glossary

Euclidean distance
The straight-line length between two points, √((x₂−x₁)² + (y₂−y₁)²) in the plane. The distance this calculator reports. Named for the geometry in which Pythagoras holds.
Midpoint
The point halfway along the segment AB, obtained by averaging the coordinates of A and B. It is the unique point of the segment equidistant from both ends.
Centroid
The mean of three (or more) vertices. For a triangle, G is the average of A, B and C, and also the meeting point of the medians. Not the midpoint of a side.
Gradient (slope)
The steepness of the line AB: m = (y₂ − y₁)/(x₂ − x₁). GCSE papers say gradient; US texts say slope. Undefined when the line is vertical. A gradient of 1 is 45° on an equal-scale grid.
Origin
The point O(0, 0) where the axes cross. Distance from O to A is √(x² + y²). Distance from A to B does not go via O unless one of the two points is O.
Taxicab distance
Also called Manhattan distance: |x₂ − x₁| + |y₂ − y₁|. The length of a path that may move only parallel to the axes. Always at least the Euclidean distance, and equal to it only when the points already share a coordinate.

Related calculators