---
title: "Fermat Path Finder Interactive Lab | Sandbox Physics"
description: "Why can one rule about travel time explain reflection, refraction and curved light rays?"
canonical_url: "https://sandboxphysics.com/labs/fermat-path-finder/"
language: "en"
page_type: "lab"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/labs/fermat-path-finder/"
last_modified: "2026-10-27"
---

Optics 007 · Ray worlds, boundaries, and natural optics

# Fermat Path Finder

**Why can one rule about travel time explain reflection, refraction and curved light rays?** Because a real ray is the path whose travel time does not change, to first order, when you wiggle the path slightly with its ends fixed. That single condition gives equal angles at a mirror, Snell's law at an interface, and curved rays wherever the refractive index varies smoothly.

Source and detector stay fixed while you drag a trial path across an opaque mirror, an interface between two indices or a continuous parabolic GRIN medium. The physical ray, the trial variation, the optical-path landscape and the residual of the governing law all come from one model.

> Interactive simulation: open this page in a web browser to change the parameters and run the model.

Fermat's principle asks for a stationary optical path, which is not always the shortest distance. The model uses monochromatic geometric optics in lossless, isotropic media. The dashed variations are for comparison and are not extra rays. Wave amplitude and diffraction are not simulated.

Physics tutorial

## Audit the physics of Fermat Path Finder

**Background** Fermat's principle compares nearby paths that share the same two endpoints. The real ray is the one that makes the optical-path functional stationary: $\delta\mathrm{OPL}=\delta\!\int_A^B n(\mathbf r)\,\mathrm ds=0$. The word “stationary” matters. The direct paths in this Lab are local minima, but other optical systems can have stationary maxima or saddle paths. The principle does not say that light always takes the geometrically shortest route.

**Why it matters** Why can one rule about travel time explain reflection, refraction and curved light rays?

Start with the essentials

- **Focus question**: Why can one rule about travel time explain reflection, refraction and curved light rays?
- **One-sentence intuition**: The magenta trial paths all keep the same endpoints and vary through one parameter. At the gold path, $\left.\frac{\partial\mathrm{OPL}(a)}{\partial a}\right|_{a=0}=0$. The floating landscape, the signed arrival-time shift and the derivative therefore all pick out the same stationary curve.

### Core mathematical model

#### Optical path length with fixed endpoints

$$
\mathrm{OPL}[\mathbf r]=\int_A^B n(\mathbf r)\,\mathrm ds,\qquad \delta\mathrm{OPL}=0
$$

Every comparison path must keep both endpoints. A shorter path to some other detector tells you nothing about Fermat stationarity.

#### Stationary crossing point on a boundary

$$
n_1\sin\theta_1=n_2\sin\theta_2
$$

Making the optical path stationary as the hit point slides along the boundary keeps the tangential optical momentum the same. For a mirror both segments have the same index, and the condition becomes equal angles of incidence and reflection.

#### Ray equation for a continuously varying index

$$
\frac{\mathrm d}{\mathrm ds}\!\left(n\frac{\mathrm d\mathbf r}{\mathrm ds}\right)=\nabla n
$$

The GRIN path is integrated from this equation and solved as a boundary-value problem. A separate numerical check tracks the axial optical momentum, which is conserved.

### Common difficulties

#### Mistaking stationary optical path for shortest distance

**Typical misconception** Light simply takes the geometrically shortest line, so the refractive index and the nearby paths hardly matter.

**Better mental model** Optical path length weights each segment by its local refractive index. Reflection, refraction and smooth bending all follow from making that weighted length stationary with the endpoints held fixed.

### Run the experiment

1. 01

   #### Scene 1: Mirror equal-angle stationarity

   In the mirror scene, drag the magenta surface point onto the gold hit. Compare the two mirror angles and find the stationary point of the arrival-time landscape.

   **What to observe:** Only the gold path turns at the mirror, at the hit where the angles are equal. The dashed comparison path is not reflected light, and no photon pulses travel along it.

2. 02

   #### Scene 2: Snell interface stationarity

   Switch to the two-medium scene and move the target. The stationary crossing moves with it, while the source and target stay fixed during each variation sweep.

   **What to observe:** The stationary crossing usually sits away from where a straight line would cross the interface, because the slower medium weighs more heavily in the optical path.

3. 03

   #### Scene 3: GRIN curved geodesic

   Enter the GRIN scene and orbit the camera through the index contours. Then bring the trial deformation back to zero while watching the first variation and the momentum residual.

   **What to observe:** The GRIN ray bends smoothly toward higher index. Real rays launched in nearby directions end up elsewhere, while every magenta variation still ends on the chosen target.

Physical conclusion

One principle, stationary optical path, gives equal-angle reflection, Snell's law and smooth GRIN bending, as long as the endpoints, the index field and the limits of the approximation are stated clearly.

Waves & optics · Starter path

## From one ray to interference measurement

Start with refraction, find where the ray picture stops working, then use interference to measure tiny distances.

[Start here → **Optical Boundary Explorer** Turn the incident angle and watch reflected and transmitted power trade off. Then switch to the critical-angle scene. Observe · 11 min](https://sandboxphysics.com/labs/optical-boundary-explorer/)

1. [1 Optical Boundary Explorer](https://sandboxphysics.com/labs/optical-boundary-explorer/)
2. [2 Rainbow Caustic Observatory](https://sandboxphysics.com/labs/rainbow-laboratory/)
3. [3 Camera Obscura](https://sandboxphysics.com/labs/camera-obscura/)
4. [4 Coherent Wave Composer](https://sandboxphysics.com/labs/coherent-wave-composer/)
5. [5 Young Double-Slit Bench](https://sandboxphysics.com/labs/young-double-slit-bench/)
6. [6 Michelson Precision Lab](https://sandboxphysics.com/labs/michelson-precision-lab/)

[View the full path →](https://sandboxphysics.com/topics/waves-and-optics/#starter-path)
