An ant sits on one corner of a closed cardboard box and wants to reach the far top corner. It cannot tunnel through, so the straight line through the inside is useless. Its route along the surface looks bent as it folds over an edge. Unfold the two faces it crosses into one flat rectangle, though, and the best route is a straight line again, which the Pythagorean theorem can measure.
Unfolding works because it does not stretch the surface: every path on the box keeps its length on the flat net. On a flat sheet straight is shortest, so the shortest path on the box is the one that becomes straight when unfolded. A can works the same way: unroll its side into a rectangle. A sphere cannot be flattened without stretching, so there the shortest path is an arc of a great circle, a circle centered at the sphere's center, like the equator.
Obstacles change the answer too. To get past a building, the shortest path runs straight to a corner, then straight on from there, hugging the corner like a string pulled tight around a post.
On an open flat field none of this is needed: the straight segment and the distance formula give the answer at once. The special thinking matters only when the straight segment is blocked or leaves the surface. One caution: a box can be unfolded in several ways, and each gives a different straight line. Measure each one and keep the smallest.
Think of it like this. A shortest path behaves like a string pulled tight between two pins: on a flat board it snaps straight, laid over a box it lies flat across the faces, and on a ball it settles along a great circle. A tight string only finds the best route nearby, though, and can get caught on the wrong side of an obstacle.
Core idea. The shortest route between two points is a straight line on a flat plane but bends to fit a curved or obstacle-filled space.