Pythagorean Theorem in 3D

Portrait of the mathematician Pythagoras
Pythagoras

In 2D

First, let's have a quick refresher in two dimensions:

When a triangle has a right angle (90°) ...

... and squares are made on each of the three sides, ...

... then the biggest square has the exact same area as the other two squares put together!


images/pyth1.js

Right triangle with sides labeled a, b, and hypotenuse c

It is called the Pythagorean Theorem and can be written in one short equation:

a2 + b2 = c2

Visual equation showing squares on sides a and b equal to the square on side c

Note:

And when we want to know the distance "c" we take the square root:

c2 = a2 + b2

c = √(a2 + b2)

You can read more about it at Pythagorean Theorem, but here we see how it can be extended into 3 Dimensions.

In 3D

Let's say we want the distance from the bottom-most left front corner to the top-most right back corner of this cuboid:

Cuboid with a diagonal line connecting opposite corners through the center

First let's just do the triangle on the bottom.

Pythagoras tells us that c = √(x2 + y2)

Cuboid highlighting the diagonal of the base rectangle

Now we make another triangle with its base along the "√(x2 + y2)" side of the previous triangle, and going up to the far corner:

Cuboid showing an internal vertical triangle formed by the base diagonal and the height

We can use Pythagoras again, but this time the two sides are √(x2 + y2) and z, and we get this formula:

Formula: distance equals the square root of x squared plus y squared plus z squared

And the final result is:

pythagoras 3d

Cuboid with a diagonal line connecting opposite corners through the center

Example: What's the distance from one corner of a room to the opposite corner if the room is 3 meters wide, 4 meters deep, and 2.4 meters high?

  1. First, find the diagonal along the floor:
    √(32 + 42) = √(9 + 16) = √25 = 5 m
  2. Now use that 5m length and the 2.4m height to find the main diagonal:
    √(52 + 2.42) = √(25 + 5.76) = √30.76 ≈ 5.546 m

The distance is about 5.546 m.

Or in one go:

√(32 + 42 + 2.42) = √(9 + 16 + 5.76) = √30.76 ≈ 5.546 m

Pattern

It is all part of a pattern that extends onwards:

Dimensions Pythagoras Distance "c"
1 (a line) c2 = x2 √(x2) = x
2 c2 = x2 + y2 √(x2 + y2)
3 c2 = x2 + y2 + z2 √(x2 + y2 + z2)
... ... ...
n c2 = a12 + a22 + ... + an2 √(a12 + a22 + ... + an2)

So we have a formula for calculating distance in any number of dimensions!