This week’s Riddler Express has interested readers solving for the shortest possible distance between two diagonals in a cube. The solution in this post will involve some higher level mathematics toward the end. You’ve been warned.
I’ve changed the coordinates from the original posed problem with the one below. On this cube, there is a diagonal on one face of the cube connecting the points (1,0,0) and (0,0,1). There is also a diagonal of the cube itself connecting the points (0,0,0) with (1,1,1).
Our goal is to find the points p1 on the first diagonal and p2 on the second diagonal for which the distance between p1 and p2 is at a minimum.
Distance Between Two Points
A general point in three dimensional space is given as . The first two coordinates tell you where along the plane the point is, while the third coordinate tells you your height (positive values) or depth (negative values).
The distance between two points on a plane can be solved using Pythagorean’s Theorem. Let’s begin with the two points and in two-dimensions.
Two find the distance between the two points, we construct a right triangle with the segment connecting the two points behaving as the hypotenuse of a right triangle. If you are familiar with Pythagorean’s Theorem, you know that a right triangle with side lengths a and b and hypotenuse c will satisfy the equation .
Using the figure above, if we label the hypotenuse c and use and , then we know that
or better yet, we know the distance between the two points is the length
For three dimensions, it is very similar. The distance between two points and is given as
We will use this in solving the problem.
The Form of p1 and p2
Looking at our original cube, we notice that p1 is a point on the line connecting points (1,0,0) with (0,0,1). Let’s parametrize this point. We do this by letting a variable t (think of it as time) go from 0 to 1, and as it does so, the point p1 will move from (1,0,0) to (0,0,1).
This point can be represented by . When t=0, we are at (1,0,0), and when t=1, we are at (0,0,1).
Doing the same for p2, but using a variable s instead (you can still think of it as time), a point p2 can be represented as as s ranges from 0 to 1.
So, we have the general form of two points p1 and p2 on the two lines. That is,
and for some .
The distance between these two points, using the equation derived previously is
Our goal is to minimize this distance. It turns out that it is much easier to minimize the square of the distance instead (the value underneath the square root).
WARNING! Calculus is about to occur.
Finding the Minimum Distance
As was stated, we will minimize the square of the distance. Notice that this is a function of two variables t and s, and can be written
To minimize this function, we will need to set both partial derivatives equal to zero and solve the resulting equations. These equations are
Solving the first equation will reveal that . Solving the second provides us with .
So, it is when and where the minimum distance occurs. Noticing that , we can compute the minimum distance as