Skip to content
Formulaxis

Toolbox

Analytic geometry: calculate distance, midpoint and line

Calculate the distance and midpoint of a segment, or determine the line through two points in the plane. Choose y = mx + p mode if the x-coordinates differ, and x=k for a vertical line.

Created on , Revised on v2.0

Method and validation

Analytic geometry: calculate distance, midpoint and line

dimensionless

Horizontal coordinate of the first point A, in the same coordinate system as the second point.

dimensionless

Vertical coordinate of the first point A; use the same scale as for the other coordinates.

dimensionless

Horizontal coordinate of the second point B; it must differ from x₁ in nonvertical line mode.

dimensionless

Vertical coordinate of the second point B, in the same unit as y₁.

Initial values are examples.

Results

Distance AB d
10dimensionless
Midpoint x-coordinate xₘ
1dimensionless
Midpoint y-coordinate yₘ
-1dimensionless

Substitution in SI units

d=(4−(−2))2+((−5)−3)2=10

Only in 2D.

A segment and its midpoint

Analytic geometry: calculate distance, midpoint and line · Distance and midpointPoints are plotted from the entered coordinates, with the same scale on x and y.xyABMA (-2 ; 3) · B (4 ; -5)Midpoint M (1 ; -1)

Points are plotted from the entered coordinates, with the same scale on x and y.

Illustrative diagram, not to scale.

Estimated reading time : 4 min · 634 words

Calculation details

In line mode, outputs m and p form the equation y = mx + p. In vertical mode, output k directly gives x=k; no slope is defined.

01 · Distance AB

FORMULA

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

NUMERICAL SUBSTITUTION

d=(4−(−2))2+((−5)−3)2

RESULT

d=10

02 · Midpoint x-coordinate

FORMULA

xm=x1+x22

NUMERICAL SUBSTITUTION

xm=(−2)+42

RESULT

xm=1

03 · Midpoint y-coordinate

FORMULA

ym=y1+y22

NUMERICAL SUBSTITUTION

ym=3+(−5)2

RESULT

ym=−1

Two points in a coordinate system: segment or line

The coordinates describe points A(x₁ ; y₁) and B(x₂ ; y₂) in the same coordinate system. Euclidean distance assumes an orthonormal Cartesian coordinate system and the same unit on both axes. A nonvertical line is written y = mx + p. A vertical line is written x=k. Two coincident points have zero distance and a midpoint equal to that point, but do not determine a unique line.

Formulas and symbols

The following relationships use the symbols defined below.

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

xm=x1+x22(midpoint x-coordinate)

ym=y1+y22(midpoint y-coordinate)

m=y2−y1x2−x1(line slope)

p=y1−x1×(y2−y1)x2−x1(y-intercept)

k=vx(constant x-coordinate of the vertical line)

  • x₁, y₁, x₂, y₂: numerical coordinates in the same unit, without automatic conversion.
  • d: distance in that unit.
  • xₘ, yₘ: midpoint coordinates.
  • m: slope, dimensionless if the axes use the same unit.
  • p: y-intercept.
  • k: constant x-coordinate of a vertical line. In vertical mode, vx is the common x-coordinate and vy1, vy2 are the two distinct y-coordinates.

Identify the point configuration

ConfigurationDistance / midpointLine
Different x-coordinatesDefinedy = mx + p
Equal x-coordinates, different y-coordinatesDefinedx=k
Coincident pointsZero distance; same midpointNo unique line
Equal y, distinct xDefined; distance=|x2−x1|y=y1 ; m=0
Opposite distinct points A=−BMidpoint at originPasses through origin

OpenStax — coordinates, distance and midpoint ; Wolfram MathWorld — 2-Dimensional Point-Point Distance.

Worked examples

Example 1: Segment from A(−2 ; 3) to B(4 ; −5)

The differences are 6 and −8, so the distance is 10. The midpoint is (1 ; −1).

Example 2: Line through (1 ; 3) and (4 ; 9)

The slope is 2 and the y-intercept is 1. The equation is y=2x + 1.

Example 3: Two points with x-coordinate 3

A(3 ; 1) and B(3 ; 7) define the vertical line x=3. Its slope is undefined.

Example 4: Two coincident points

A and B at (2 ; −1) give zero distance and the same point as midpoint; they do not determine a unique line.

Assumptions and limitations

Only in 2D. Distance mode accepts coincident points. Nonvertical line mode requires distinct x-coordinates. Vertical mode requires a common x-coordinate and two distinct y-coordinates. These conditions are checked; selecting a mode does not transform an incompatible pair of points.

Common mistakes

Keep coordinates in x then y order. A vertical line has no finite real slope. A horizontal line has zero slope. Do not read the axes in different units when applying Euclidean distance.

Frequently asked questions

What is the slope of a vertical line?

It is undefined: the change in x-coordinate is zero. Use its equation x=k in vertical mode.

Do two identical points define a line?

No, infinitely many lines pass through that point. Distance and midpoint can still be calculated.

How can point membership be checked?

For a nonvertical line, insert the x coordinate and compare the resulting y coordinate. For a vertical line, check the constant x.

Does slope depend on axis scaling?

Its numerical value depends on coordinate units. Changing one unit changes the quotient; a drawing’s apparent angle also depends on graphical scaling.