The Distance Formula

Part 9, Chapter 9: The Coordinate Plane

Learning objectives

  • Derive and apply the distance formula between two points
  • Compute the midpoint of a segment given its endpoints
  • Use the distance formula to verify geometric properties

Now that points have coordinates, distance becomes algebra. The previous section gave us Pythagoras' theorem as a geometric statement about right triangles; this section turns it into an algebraic formula for the distance between any two points in the plane. Once we have the formula, we can compute the length of a fence, the radius of a circle, the side of a quadrilateral, all from coordinate data, without ever drawing the figure.

From Pythagoras to coordinates

Take two points P1=(x1,y_1)P_1 = (x_1, y_1) and P2=(x2,y2)P_2 = (x_2, y_2). The horizontal gap between them has length x2x1|x_2 - x_1| and the vertical gap has length y2y1|y_2 - y_1|. These two gaps are the legs of a right triangle whose hypotenuse is the straight-line distance dd. Pythagoras gives:

d=sqrt(x2x1)2+(y2y1)2.d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}.

Squaring eliminates the need for the absolute values: (x2x1)2=(x1x2)2(x_2 - x_1)^2 = (x_1 - x_2)^2, so the order of the points is irrelevant. The distance is always non-negative, and is zero only when the two points coincide.

Where this shows up
  • GPS: GPS computes your position by solving distance equations: each satellite gives a sphere (xxs)2+(yys)2+(zzs)2=d2(x - x_s)^2 + (y - y_s)^2 + (z - z_s)^2 = d^2s)2+(yys)2+(zzs)2=d2, and your location is the intersection of four such spheres.
  • Machine Learning: The simplest classifier picks the kk training points with smallest Euclidean distance to a query, exactly the distance formula sqrt(x1x2)2+(y1y2)2\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}, repeated for every dimension.
  • Sports Analytics: "Shot distance" in basketball, the metric the NBA uses to evaluate scoring efficiency, is literally sqrt(xshotxrim)2+(yshotyrim)2\sqrt{(x_{shot} - x_{rim})^2 + (y_{shot} - y_{rim})^2} measured in feet.
  • Drag PP and QQ in the widget. The widget shows Deltax\Delta x, Deltay\Delta y, and the live distance PQ|PQ|. Try the 3-4-5 triple: P=(0,0)P = (0, 0), Q=(3,4)Q = (3, 4).

    The midpoint formula

    The midpoint of the segment from P_1P_1 to P2P_2 is simply the average of the two coordinates:

    M=left(fracx1+x22,;fracy1+y22right).M = \left(\frac{x_1 + x_2}{2},\; \frac{y_1 + y_2}{2}\right).

    The midpoint is equidistant from both endpoints and lies exactly halfway along the segment. Geometrically this is the centre of mass of the two endpoints (treating each as a unit mass).

    What the formula buys you

    Once you have the distance and midpoint formulas, a remarkable number of geometric verifications become arithmetic:

    • Is a triangle right-angled? Compute the three side lengths; check whether a2+b2=c2a^2 + b^2 = c^2 for the largest side cc.
    • Is a quadrilateral a parallelogram? Check that opposite sides have equal length.
    • Is a point on a circle? Check that its distance from the centre equals the radius.
    • Where is the midpoint of a segment? Average the coordinates, bisection is a one-line calculation.

    Try it

    • Place P=(P = (, )) and Q=(Q = (, )). Predict first: with P=(1,2)P = (1, 2) and Q=(4,6)Q = (4, 6), what are the distance and midpoint? Place the points and verify the widget shows distance 55 and midpoint (2.5,4)(2.5, 4).
    • Set P=(P = (, )) and Q=(Q = (, )). Before placing: with P=(2,3)P = (-2, 3) and Q=(4,5)Q = (4, -5), what is Deltax\Delta x, Deltay\Delta y, and the distance? Set the points and verify the answer is sqrt36+64=10\sqrt{36 + 64} = 10.
    • Set PP on the xx-axis and QQ on the yy-axis. The distance reduces to sqrtPx2+Qy2\sqrt{P_x^2 + Q_y^2}, the hypotenuse of a right triangle whose right angle sits at the origin.

    Try it in code

    A trap to watch for

    Beginners sometimes confuse the distance formula with sqrtx2x1+y2y1\sqrt{x_2 - x_1 + y_2 - y_1} (forgetting to square) or with (x2x1)+(y2y1)(x_2 - x_1) + (y_2 - y_1) (no squares or root, just adding the legs). Both are wrong. The signature of the right formula is the two squares inside the radical: it is Pythagoras rearranged. The cleanest sanity check is to verify against the 3-4-5 triangle: distance from (0,0)(0,0) to (3,4)(3,4) should be exactly 55, not 77, not sqrt7\sqrt{7}.

    What you now know

    You can compute the distance between any two points in the plane, find their midpoint, and use these tools to test geometric claims with arithmetic alone. The next section uses the distance formula to write down the most famous equation in coordinate geometry: the equation of a circle.

    Quick check

    Mark section complete →

    References

    • Lang, S. (1971). Basic Mathematics. Springer. Chapter 8, §2, the distance and midpoint formulas in coordinates.
    • Stewart, J. (2015). Calculus, 8th ed. Cengage. Appendix B reviews these formulas before calculus proper.
    • Coxeter, H. S. M. (1969). Introduction to Geometry, 2nd ed. Wiley. §1.2 develops the Euclidean metric axiomatically.
    • Hartshorne, R. (2000). Geometry: Euclid and Beyond. Springer. Chapter 1 reconstructs distance from Euclid's axioms.

    This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.