Math Help - using calculus to solve the problem of the ant in a cube-shaped room

1. using calculus to solve the problem of the ant in a cube-shaped room

There's a room in the shape of a cube with a side length of 7m. There's also an ant, located at one corner of the cube (call it point A), that wants to crawl to the opposite corner of the cube (call it point B). Find the length of the shortest path the ant can take from point A to point B. Note that the ant cannot fly: it must crawl along the walls (i.e., along the surface of the cube).

Now, I know this problem can be easily solved by flattening out the cube into a 2-dimensional figure, and using the Pythagorean theorem to find the shortest distance between the two points. However, I have to come up with a solution using calculus, which involves coming up with some distance function, differentiating that distance function, setting that differentiated function equal to 0, which would then give you the shortest distance (since it corresponds to a minimum on the graph of the distance function). However, I need help figuring out the distance function.
Thanks very much!

2. If L is the length of the side of the cube, and x is the distance from the next corner where ant reaches before climbing the vertical face, then the total distance crawled by the ant is

$D = \sqrt{(L^2 + x^2)} + \sqrt{(L-x)^2 + L^2}$

Now find the derivative of D with respect to x and equate it to zero.

3. Thanks, the equation works, but I don't really understand what x represents and how you came up with the equation in the first place.

4. Ah, never mind, I got it. Thanks very much!