Distance Between 2 Points

distance by pythagoras

Quick Explanation

When we know the horizontal and vertical distances between two points we can calculate the straight line distance like this:

distance = a2 + b2 

 

graph 2 points

Imagine you know the location of two points (A and B) like here.

What is the distance between them?

 

graph 2 points

We can run lines down from A, and along from B, to make a Right Angled Triangle.

And with a little help from Pythagoras we know that:

a2 + b2 = c2

 

graph 2 points

Now label the coordinates of points A and B.

xA means the x-coordinate of point A
yA means the y-coordinate of point A

The horizontal distance a is (xA − xB)

The vertical distance b is (yA − yB)

 

Now we can solve for c (the distance between the points):

Start with:c2 = a2 + b2
Put in the calculations for a and b:c2 = (xA − xB)2 + (yA − yB)2
Square root of both sides:c = (xA − xB)2 + (yA − yB)2
Done! 

Examples

Example 1

graph 2 points

Fill in the values: c = (9 − 3)2 + (7 − 2)2
Calculate: c = 62 + 52
c = 36 + 25
c = 61
c = 7.8102...

Example 2

It doesn't matter what order the points are in, because squaring removes any negatives:

graph 2 points

Fill in the values: c = (3 − 9)2 + (2 − 7)2
Calculate: c = (−6)2 + (−5)2
c = 36 + 25
c = 61
c = 7.8102...

Example 3

And here is another example with some negative coordinates ... it all still works:

graph 2 points

 

Fill in the values: c = (−3 − 7)2 + (5 − (−1))2
Calculate: c = (−10)2 + 62
c = 100 + 36
c = 136
c = 11.66...

(Note √136 can be further simplified to 2√34 if you want)

Try It Yourself

Drag the points:

images/dist2pts.js

Three or More Dimensions

It works perfectly well in 3 (or more!) dimensions.

Square the difference for each axis, then sum them up and take the square root:

Distance = (xA − xB)2 + (yA − yB)2 + (zA − zB)2

distance between (9,2,7) and (4,8,10) in 3d

Example: the distance between the two points (8,2,6) and (3,5,7) is:

  = (8−3)2 + (2−5)2 + (6−7)2
  = 52 + (−3)2 + (−1)2
  = 25 + 9 + 1
  = 35

Which is about 5.9

Read more at Pythagoras' Theorem in 3D

 

513, 514, 1148, 1149, 2994, 2995, 2996, 2997, 4034, 4035