(I would be appreciative if somebody could give a more formal formulation of this problem.)
The Spider and the Fly Problem is a problem in which the objective is to minimize the distance the spider must travel to reach the fly on the other side of the room.

The spider can only move on the surface of the room. Let S be the point where the spider is, and F be the point where the fly is. One is given the length of YG, GF, PH, and HS, as well as the length, width and height of the rectangular prism. Assume that the fly and spider stay on their respective sides, but aside from that, their points are not necessarily where they are placed on the diagram. Is there a general formula for calculating the shortest distance between the spider and the fly? (Is there a general formula for the geodesic of the cuboid?)
I solved the original spider and the fly problem (by just creating meshes of the cube and getting lucky), but I don't see how I could generalize the result, especially as the spider and fly do not have to be at the same position they are in the original problem. In the original problem, the spider is centered and one unit from the top, and the fly is centered and one unit from the bottom. I've tried considering the simpler case where the fly and spider remain in the same spot, but I still couldn't generalize it, especially for more extreme cases (if we make the height very large compared to the others, our line will go off the mesh, I'm not sure how to deal with this.)
I looked online for any hints about the problem, and the the Mathworld Page used the word "geodesic" to describe the solution. I did some more research, but could only find solutions for the sphere and some other 3d shapes. I also couldn't find any page describing a general solution to the problem, only pages using the meshes of the rectangular prism as a solution.


Here's a sketch of a comprehensive solution. I doubt a simple closed-form formula can exist, if that's what you're looking for.
Consider the sequence of faces that the optimal path travels over. Every pair of consecutive faces has a common edge, so the entire sequence can be "unfolded" into the plane. For the path to be optimal, it must be a single straight line that lies entirely inside the unfolded faces.
There are only finitely many different unfoldings of the room, which correspond to different spanning trees of the adjacency graph of the room's faces (in this case, the octahedral graph). For each one, see if the line segment joining the unfolded positions of the spider and the fly lies entirely inside the unfolding; if so, record its length. Try all possible unfoldings, and keep the path with the shortest length.
This algorithm works for arbitrary polyhedral rooms. Edit: Well, perhaps not naively (see Namiki's counterexample), but if you interpret "lies entirely inside the unfolding" as "does not leave any face by crossing a edge that has been cut", then it should still work.