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 for a vertical line.
Analytic geometry: calculate distance, midpoint and line
Horizontal coordinate of the first point A, in the same coordinate system as the second point.
Vertical coordinate of the first point A; use the same scale as for the other coordinates.
Horizontal coordinate of the second point B; it must differ from x₁ in nonvertical line mode.
Vertical coordinate of the second point B, in the same unit as y₁.
Initial values are examples.
Results
Substitution in SI units
Only in 2D.
A segment and its midpoint
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 ; no slope is defined.
02 · Midpoint x-coordinate
03 · Midpoint y-coordinate
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 . 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.
(distance ab)
(midpoint x-coordinate)
(midpoint y-coordinate)
(line slope)
(y-intercept)
(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
| Configuration | Distance / midpoint | Line |
|---|---|---|
| Different x-coordinates | Defined | y = mx + p |
| Equal x-coordinates, different y-coordinates | Defined | |
| Coincident points | Zero distance; same midpoint | No unique line |
| Equal y, distinct x | Defined; | ; |
| Opposite distinct points | Midpoint at origin | Passes 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 x + 1.
Example 3: Two points with x-coordinate 3
A(3 ; 1) and B(3 ; 7) define the vertical line . 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 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.