Fermat's principle states that light takes the path that requires the shortest time. Therefore, there is an analogy between the path taken by a particle under gravity and the path taken by a light ray and the problem can be modeled by a set of media bounded by parallel planes, each with a different index of refraction (leading to a different speed of light). Consequently, the path taken by a light in these media where light propagates at variable speeds is the answer to the problem. Because of the conservation of mechanical energy, the speed of the particle in a medium is constant along a horizontal plane and proportional to the square root of the height difference between the instantaneous position and the initial position of the particle. Fermat's principle yields Snell's law, which states that the ratio between the cosine of the angle between a ray and the boundary plane of a medium to the speed of the ray is constant.

In this Demonstration, parallel planes passing through the vertices of a regular polygon bound the media. The inradius of the polygon is 1. When you rol