Distance and Midpoint Between Two Points

Calculates the distance between two points (x₁, y₁) and (x₂, y₂) as √((x₂−x₁)² + (y₂−y₁)²).

This finds the straight-line distance between two points on the coordinate plane, along with their midpoint. The distance formula is the Pythagorean theorem in disguise: picture a right triangle whose legs are the horizontal gap and the vertical gap, and the distance is its hypotenuse.

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

The midpoint is nothing more than the average of the two coordinates.

M=(x1+x22, y1+y22)M = \left( \dfrac{x_1 + x_2}{2},\ \dfrac{y_1 + y_2}{2} \right)

Example

For (x1,y1)=(0,0)(x_1, y_1) = (0, 0) and (x2,y2)=(3,4)(x_2, y_2) = (3, 4):

d=(30)2+(40)2=9+16=25=5d = \sqrt{(3 - 0)^2 + (4 - 0)^2} = \sqrt{9 + 16} = \sqrt{25} = 5

The distance is 5, and the midpoint is (0+32, 0+42)=(1.5, 2)\left( \dfrac{0 + 3}{2},\ \dfrac{0 + 4}{2} \right) = (1.5,\ 2).

Notes