MathAI Blog

Distance Formula Made Easy: Complete Guide with Examples

Discover how the distance formula works, how it connects to the Pythagorean theorem, and how to use it for 2D and 3D coordinate problems with real-world applications.

Published October 8, 20251 min read

The distance formula is your tool for finding the straight-line distance between any two points in space. Whether you're working with coordinates on a map, points in a graph, or 3D locations, this formula gives you the exact distance. It's beautifully derived from the Pythagorean theorem, and once you understand it, coordinate geometry becomes much clearer. Master the formula with step-by-step examples you can practice using MathAI GPT.

1) The Distance Formula (2D)

For two points in a plane, (x₁, y₁) and (x₂, y₂), the distance formula is:

Distance Formula (2D)

d = √[(x₂ - x₁)² + (y₂ - y₁)²]

Where:

d = distance between the two points

(x₁, y₁) = coordinates of first point

(x₂, y₂) = coordinates of second point

(x₂ - x₁) = horizontal distance (run)

(y₂ - y₁) = vertical distance (rise)

Key insight: This is just the Pythagorean theorem in disguise! The horizontal and vertical distances form the legs of a right triangle, and the distance is the hypotenuse.

2) How It Comes from the Pythagorean Theorem

The distance formula isn't pulled out of thin air—it's derived directly from a²+b²=c²:

The Derivation

Step 1: Plot two points: (x₁, y₁) and (x₂, y₂)

Step 2: Draw a right triangle connecting them:

• Horizontal leg (a) = |x₂ - x₁|

• Vertical leg (b) = |y₂ - y₁|

• Hypotenuse (c) = distance d

Step 3: Apply the Pythagorean theorem:

a² + b² = c²

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

Step 4: Solve for d:

d = √[(x₂ - x₁)² + (y₂ - y₁)²]

Why squaring removes the need for absolute values: Since we're squaring the differences, negative values become positive automatically. That's why we don't need absolute value signs.

3) Step-by-Step Example (2D)

Let's find the distance between two points:

Example: Find the distance between (2, 3) and (8, 11)

Given:

Point 1: (x₁, y₁) = (2, 3)

Point 2: (x₂, y₂) = (8, 11)

Step 1: Identify the coordinates

x₁ = 2, y₁ = 3, x₂ = 8, y₂ = 11

Step 2: Calculate the differences

x₂ - x₁ = 8 - 2 = 6

y₂ - y₁ = 11 - 3 = 8

Step 3: Square the differences

(x₂ - x₁)² = 6² = 36

(y₂ - y₁)² = 8² = 64

Step 4: Add them together

36 + 64 = 100

Step 5: Take the square root

d = √100 = 10

Answer: The distance between (2, 3) and (8, 11) is 10 units.

4) The Distance Formula in 3D

When working with three-dimensional space, we just add a z-coordinate:

Distance Formula (3D)

d = √[(x₂ - x₁)² + (y₂ - y₁)² + (z₂ - z₁)²]

For points: (x₁, y₁, z₁) and (x₂, y₂, z₂)

Example: Distance from (1, 2, 3) to (4, 6, 8)

x: 4 - 1 = 3 → 3² = 9

y: 6 - 2 = 4 → 4² = 16

z: 8 - 3 = 5 → 5² = 25

d = √(9 + 16 + 25) = √50 ≈ 7.07

Think of it as: The 3D formula extends the 2D Pythagorean theorem to three dimensions. You're still finding the hypotenuse, just in 3D space!

5) The Midpoint Formula (Bonus!)

Once you know the distance formula, the midpoint formula is a natural companion—it finds the point exactly halfway between two points:

Midpoint Formula

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

How it works: Average the x-coordinates, average the y-coordinates

Example: Midpoint of (2, 3) and (8, 11)

x: (2 + 8)/2 = 10/2 = 5

y: (3 + 11)/2 = 14/2 = 7

Midpoint: (5, 7)

Use case: Finding the center point of a line segment, the halfway meeting point on a map, or the average location between two coordinates.

6) Real-World Applications

Navigation & GPS

Example: Distance Between Cities

Scenario: You have GPS coordinates (latitude, longitude) for two cities

City A: (40.7128°N, -74.0060°W) — New York

City B: (34.0522°N, -118.2437°W) — Los Angeles

Simplified calculation (treating Earth as flat for short distances):

Use distance formula to get straight-line distance

Convert to miles/kilometers using latitude-longitude scaling

Note: For precise long-distance calculations, use the Haversine formula which accounts for Earth's curvature.

Computer Graphics & Game Development

Example: Collision Detection

Problem: Determine if two game objects are close enough to collide

Solution: Calculate distance between their center points

Player at (50, 100), Enemy at (58, 106)

d = √[(58-50)² + (106-100)²] = √[64 + 36] = √100 = 10

If collision radius = 15, they're touching!

Used constantly in video games, animations, and simulations

Architecture & Engineering

Example: Cable Length Calculation

Scenario: Run electrical cable between two points in 3D space

Point A: (0, 0, 0) — floor corner

Point B: (12, 9, 8) — ceiling outlet (feet)

d = √[12² + 9² + 8²] = √[144 + 81 + 64] = √289 = 17 feet

Essential for material estimation, cost calculation, and space planning

Physics: Motion & Displacement

Example: Net Displacement

Problem: An object starts at (0, 0) and moves to (30, 40) meters

Path distance: May have walked 100m along a winding path

Displacement (straight-line):

d = √[30² + 40²] = √[900 + 1600] = √2500 = 50 meters

Distance vs. displacement is a key concept in physics!

7) Common Mistakes to Avoid

  • Forgetting to square the differences: You need (x₂-x₁)², not just (x₂-x₁)
  • Forgetting the square root at the end: √[(x₂-x₁)² + (y₂-y₁)²], not just the sum
  • Mixing up the coordinates: Make sure x₁ matches y₁ (same point)
  • Order confusion: It doesn't matter which point is #1 or #2—you get the same distance either way
  • Sign errors: Squaring makes negative differences positive, so signs don't matter
  • Units: Make sure both coordinates use the same units (both in feet, meters, etc.)

8) Distance Formula Variations

Related Formulas You Should Know

Manhattan Distance (Taxicab Distance):

d = |x₂ - x₁| + |y₂ - y₁|

Used when you can only move horizontally and vertically (like on a city grid)

Chebyshev Distance (Chessboard Distance):

d = max(|x₂ - x₁|, |y₂ - y₁|)

Used in chess (king can move diagonally), image processing, game AI

Haversine Formula (Spherical Distance):

Complex formula that accounts for Earth's curvature

Use for accurate geographic distances over long ranges

9) Practice Problems

  1. Find the distance between (0, 0) and (3, 4)
  2. Find the distance between (-2, 5) and (4, -3)
  3. Find the distance between (1, 1) and (7, 9) [should be exactly 10]
  4. Find the distance between (5, 2, 1) and (8, 6, 5) in 3D
  5. Find the midpoint between (-3, 7) and (5, -1)
  6. Two points are 13 units apart. One point is (0, 0). If the other is (5, y), what is y?
  7. Is the point (4, 5) closer to (0, 0) or to (8, 8)? Calculate both distances.
  8. A robot moves from (10, 20) to (40, 60). What's the straight-line displacement?
Show answers

1. √[(3-0)² + (4-0)²] = √[9+16] = √25 = 5

2. √[(4-(-2))² + (-3-5)²] = √[36+64] = √100 = 10

3. √[(7-1)² + (9-1)²] = √[36+64] = 10

4. √[(8-5)² + (6-2)² + (5-1)²] = √[9+16+16] = √41 ≈ 6.40

5. ((−3+5)/2, (7+(−1))/2) = (2/2, 6/2) = (1, 3)

6. √[5² + y²] = 13 → 25 + y² = 169 → y² = 144 → y = ±12

7. To (0,0): √41 ≈ 6.40; To (8,8): √25 = 5; Closer to (8,8)

8. √[(40-10)² + (60-20)²] = √[900+1600] = √2500 = 50 units

Quick Reference

2D Distance: d = √[(x₂ - x₁)² + (y₂ - y₁)²]

3D Distance: d = √[(x₂ - x₁)² + (y₂ - y₁)² + (z₂ - z₁)²]

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

Connection: Distance formula = Pythagorean theorem applied to coordinates

Remember: Order doesn't matter—distance from A to B = distance from B to A

For complex coordinate problems or 3D distance calculations, use the distance calculator or the midpoint calculator for quick results. Also check out our Pythagorean theorem calculator to see the connection!

Next Steps

The distance formula is a fundamental tool in coordinate geometry, connecting algebra to visual space. Once you master it, problems involving graphs, maps, and spatial relationships become much more approachable.

Need help with coordinate geometry or distance problems? Visit MathAI GPT and ask about any distance formula, midpoint, or coordinate problem. Get instant step-by-step solutions with visual explanations, plus related practice problems. From homework to real-world applications, we make geometry clear and intuitive!

Distance Formula Made Easy: 2D, 3D & Real Applications | MathAI GPT