Midpoint & Distance Calculator (2D) Formula

Understand the math behind the midpoint & distance calculator (2d). Each variable explained with a worked example.

Formulas Used

Mid X

mid_x = (x1 + x2) / 2

Mid Y

mid_y = (y1 + y2) / 2

Distance

distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))

Slope

slope = (x2 - x1) != 0 ? (y2 - y1) / (x2 - x1) : 0

Variables

VariableDescriptionDefault
x1Point 1 x2
y1Point 1 y3
x2Point 2 x8
y2Point 2 y7

How It Works

Midpoint Formula

Formula

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

The midpoint is the point exactly halfway between two given points.

Distance Formula

d = sqrt((x₂ - x₁)² + (y₂ - y₁)²)

Slope

m = (y₂ - y₁) / (x₂ - x₁)

Worked Example

Find the midpoint between (2, 3) and (8, 7).

x1 = 2y1 = 3x2 = 8y2 = 7
  1. 01Midpoint x = (2+8)/2 = 5
  2. 02Midpoint y = (3+7)/2 = 5
  3. 03Midpoint = (5, 5)
  4. 04Distance = √(36+16) = √52 ≈ 7.2111
  5. 05Slope = 4/6 ≈ 0.6667