Distance in 3d

Distance in 2d

We all know the distance formula in plane. It is based on the Pythagorean Theorem. If you draw a rectangle whose opposite corners are the two points \((x_1,y_1)\) and \((x_2,y_2)\) and whose sides are parallel to the coordinate axes, the distance between the two points is the length of the diagonal:

Applying the Pythagorean Theorem on one of the right triangles in the picture will tell us that the distance between \((x_1, y_1)\) and \((x_2,y_2)\) is \[\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\]

A study tip

In order to fully understand a mathematical idea such as a definition, a theorem or a formula, it is often useful to think about special cases. In the distance formula, what would happen if the two points have the same \(x\)-coordinate or \(y\)-coordinate? What would the “rectangle” look like in that case? What would the formula say? What about both coordinates being the same?

“Lifting” this to 3d

Now we have two points in the 3d space inside some rectangular coordinate system, a point \(P_1\) with coordinates \((x_1,y_1,z_1)\) and point \(P_2\) with coordinates \((x_2,y_2,z_2)\). Instead of a rectangle, we will now have a rectangular box with directly opposite corners at \(P_1\) and \(P_2\), and with sides parallel to the three coordinate planes, and edges parallel to the three coordinate axes. (Again, think about special cases when one, two or even all three of the coordinates of the two points are equal. How would the “box” look like then?)

The distance between \(P_1\) and \(P_2\) is then the length of the diagonal connecting the two points in the box. To figure out this length, we can start with a simpler question:

What is the distance between the point \(P_1\) with coordinates \((x_1, y_1, z_1)\) and the point \(Q\) with coordinates \((x_2, y_2, z_1)\), that is the point that is the opposite corner to \(P\) on the “bottom” side of the box?

Now both points are the opposite corners in the same rectangle, so we can use the Pythagorean Theorem to find their distance. We have a right triangle where the hypotenuse is the diagonal \(P_1Q\), and the sides have lengths \(\left\lvert x_2 - x_1\right\rvert\) and \(\left\lvert y_2 - y_1\right\rvert\). From the Pythagorean Theorem we get the length of the diagonal as \[\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}\] (Compare that with the 2d distance formula above! What is going on here?)

Now we have another triangle, with corners \(P_1(x_1, y_1, z_1)\), \(Q(x_2, y_2, z_1)\) and \(P_2(x_2, y_2, z_2)\). This is also a right triangle (can you explain why?). You can rotate the illustration above to see that. The hypotenuse of this triangle is the diagonal between \(P_1\) and \(P_2\) whose length we are trying to find! Applying the Pythagorean Theorem to this triangle will give us the 3d distance formula. Try it yourself and see if you can come up with the following:

\[d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}\]

Example

A bit of a stretch

If you compare the 2d and 3d distance formula, you will probably notice a pattern. In fact, this pattern extends even to the 1d case:

  • In one dimension, we calculate the distance between two points on the number line. In your algebra classes, you have learned that the distance between two points \(x_1\) and \(x_2\) on the number line is the absolute value of their difference, or \(\left\lvert x_2 - x_1\right\rvert\).

    you have probably also learned that the absolute value of a number can be written using square root of a square. For any real number \(a\),

    \[\left\lvert a\right\rvert = \sqrt{a^2}\]

    We can then rewrite the 1d distance formula as

    \[\left\lvert x_2 - x_1\right\rvert = \sqrt{(x_2 - x_1)^2}\]

  • In two dimensions, the distance between two points \((x_1, y_1)\) and \((x_2, y_2)\) is

    \[\sqrt{(x_2 - x_1)^2 + (y_2 - y_2)^2}\]

  • In three dimensions, the distance between two points \((x_1, y_1, z_1)\) and \((x_2, y_2, z_2)\) is

    \[\sqrt{(x_2 - x_1)^2 + (y_2 - y_2)^2 + (z_2 - z_2)^2}\]

Can you make a conjecture how a distance between two points in a four-dimensional space would be calculated? What about in 100 dimensions?

For a real stretch, what about infinitely dimensional space? (Think for example about infinite sequences and series. Things will get tricky, because you will run into issues with convergence. Not every infinite sequence will be useable in that case. This is way beyond the scope of this class, but you can look up \(\ell^2\) spaces, or even \(L^2\) spaces if you are curious about this.)

Try it yourself