Finding the shortest path between two points on the surface of a cube

A cube with vertices $$(0,0,0),(0,0,1),(0,1,0),(0,1,1),(1,0,0),(1,0,1),(1,1,0),$$ and $$(1,1,1)$$ has the point $$P_{1}$$ with vertices $$(\frac{1}{2},0,\frac{1}{4})$$ and the point $$P_{2}$$ with vertices $$(0,\frac{3}{4},\frac{3}{4})$$. What is the length of the shortest path between $$P_{1}$$ and $$P_{2}$$ such that the path lies on the surface of the cube?

Note: $$\sqrt{(\frac{1}{2}-0)^2+(0-\frac{3}{4})^2+(\frac{1}{4}-\frac{3}{4})^2}=\frac{\sqrt{17}}{4}\approx1.03078$$ is the shortest distance between the two points. However, it is not the correct answer since this path does not lie on the surface of the cube.

For the same cube, can we generalize and give an expression to find the length of the shortest path between $$P_{1}(x_{1},y_{1},z_{1})$$ and $$P_{2}(x_{2},y_{2},z_{2})$$, where, clearly, $$0\leq x_{i},y_{i},z_{i}\leq1$$?

• My guess would be yes, but it will definitely be a piece wise defined function. You'd want to break it down into a sum of distances across faces. Not sure if that helps or not, nice question though! – DanielOnMSE Dec 3 '18 at 6:49
• @DanielOnMSE thanks :) , Yes, we have to find the sum of the lengths of two straight lines. But I do not know how to find the two lines :( – Hussain-Alqatari Dec 3 '18 at 6:52
• For your specific example yes, 2 lines, but the general case could involve at most 3 lines. Using Coffee Math's approach and drawing the example provided looks like the line doesn't pass through the corner... $y = -\frac{4}{5} x + \frac{3}{20}$ – DanielOnMSE Dec 3 '18 at 6:59
• I hope someone posts the general solution! I'm sure it will involve a piece wise function with minimums. I wonder if you could use the 3-D taxi cab metric to determine a "shortest path" and then cut out the straight lines where possible, so if you're on a face you can go diagonal onto the same face, otherwise you are bound by the laws of the 3D taxi cab metric? – DanielOnMSE Dec 3 '18 at 7:22

Here's the box: Clearly the only unfolding that matters is with the two adjacent point-bearing sides adjacent. Then it is clear the distance is $$d = \sqrt{(5/4)^2 + (1/2)^2}$$

There are only three cases:

1. Same face (easy)
2. Adjacent faces (unfold with separating edge uncut)
3. Opposite faces (depends on positions)
• So the fold is made at the edge that the two faces share in common! But what about the case where the points are on opposite faces? Nice diagrams btw! – DanielOnMSE Dec 3 '18 at 7:00
• There is not always one path either, certain cases like points in the very center of opposite faces will have 4 symmetric paths of shortest distance between each other. – DanielOnMSE Dec 3 '18 at 7:07
• @DanielOnMSE True, the number of lines can be 1 (when the two points lie on the same face), can be 2 (when the two points lie on adjacent faces), and can be 3 (when the two points lie on opposite faces). You can assume them to be 4 (when you consider the mid-point of the longest straight line). – Hussain-Alqatari Dec 3 '18 at 7:13
• @David Do you think it is possible to use the taxi-cab metric to find which "direction" to go? Obviously the distance used by this metric is not the correct answer, the path used by the shortest distance can then be simplified where diagonal movements are allowed? I feel like the general solution might involve something like this, hopefully someone can express the idea with math instead of words :P – DanielOnMSE Dec 3 '18 at 7:29
• you're wrong about something. points on adjacent faces don't always have the shortest path crossing their seperating edge. imagine one point being near the top right corner of the front face and one near the top left corner of the left face. the shortest path then clearly traverses the top face – Ivo Beckers Dec 3 '18 at 14:14

Possible method: Make an unfolded version of the cube so that there is a straight line segment on the unfolded cube going from one of your points to the other, while staying in your unfolded cube. If there's a gap, unfold a different way.

• There are 11 ways to unfold a cube. Must I check one by one until I find the way in which the straight line always lies inside the unfolded cube?! – Hussain-Alqatari Dec 3 '18 at 6:55
• @Hussain-Alqatari There may be a shortcut to eliminate some that don't work. But I don't know of one off-hand. See other answer--- no need to check any but the one, since the two points on adjacent sides of cube. – coffeemath Dec 3 '18 at 7:27
• This does not work in general. For example if I unfold the cube to a ✞ structure (one (square) face in the middle in the upper row, three adjacent faces in the second row, one face in the middle in each of rows 3 and 4), and if it so happens that the two points are in the first (upper) and last (lower) rows, then a straight line segment exists without leaving the ✞ unfolding, but that segment does not minimize the distance! – Jeppe Stig Nielsen Dec 3 '18 at 14:18
• @JeppeStigNielsen I see. There may be several unfoldings each giving a segment not going out of the unfolding, and the4n one needs to pick minimum length of those. – coffeemath Dec 4 '18 at 2:55

If the two points belong to adjacent faces, you have to check three different possible unfoldings to find the shortest path. In diagram below I represented the first point (red) and the second point (black) in three possible relative positions: middle position occurs when the path goes through the common edge, in the other cases the path traverses one of the faces adjacent to both faces. The other possible positions are clearly longer than these. If the two points belong to opposite faces, then 12 different possible positions have to be checked: see diagram below. 