If one treats light as a wave-like phenomena, then Snell's law is readily derivable from geometry.

But, back in 1600's the nature of light (i.e. particle or wave) was anything but settled.

Q: How does a photon (i.e. not a wave) decide to change directions upon entering and exiting the medium?

A: It has to get to point *b* in the shortest time.

Since the distance $s$ traveled in time $t$ at a speed $v$ is \begin{equation} v = \frac{s}{t} \end{equation} and using the fact that the speed of light depends on the local index of refraction: \begin{equation} v_\textrm{light} = \frac{c}{n(\mathbf{r})} \end{equation} we can express the time to travel an infinitesimal distance $ds$ as : \begin{equation} dt = \frac{ds}{v} = \frac{ds}{c/n(\mathbf{r})} \end{equation}

Integrating this to find the total time it takes: \begin{equation} t = \int dt = \frac{1}{c}\int n(\mathbf{r}) ds \end{equation}

Finding the path ($ds$) that minimizes the total time is essentially the **Principle of Least Time**, though it would take a few more hundred years to figure out how to really do this math. (and even longer to figure out why it should even be true)

Assuming the index of refraction in our material $n(\mathbf{r})$ only changes with respect to the x position, we could write: \begin{equation} t = \frac{1}{c}\int ds \; n(x) \end{equation} or, using i.47 \begin{equation} t = \frac{1}{c} \int n(x) \sqrt{dx^2 + dy^2} = \frac{1}{c} \int n \left(x \right) \sqrt{1 + \left( \frac{dy}{dx} \right)^2} dx \end{equation} which, using the shorthand for $dy/dx = y'$ (in general, a prime will mean take the derivative w.r.t whatever the explicit independent variable is), \begin{equation} t = \frac{1}{c}\int n(x) \sqrt{1+y'^2} dx \end{equation}

Lastly, the index of refraction should be limited to just x dependent changes: $n(x,y)$ is more general. \begin{equation} t = \frac{1}{c}\int n(x,y) \sqrt{1+y'^2} dx = \int F(x,y(x),y'(x))dx \end{equation} Now, the function $F$ can be seen to depend on $x$, $y(x)$, and $y'(x)$. The techniques that follow will seek to find the path $y(x)$ that minimizes this integral.

Getting even more general, if:
\begin{equation}
I = \int F(x,y(x),y'(x))dx
\end{equation}
Can we find paths $y(x)$ that also **maximize** $I$? Or, even find what we'll call a **stationary** path, where the value of $I$ is nearly independent of small changes in the path?

The mins & maxes of a function are just the zero-crossings of the first derivative.

Find the max of this inverted paraboloid

\begin{equation} f(x,y) = -a \left( (x-x_0)^2 + (y-y_0)^2 \right) \end{equation}```
a = 1;
x0 = 2; y0 = 3;
paraboloid [x_, y_] := -a ((x - x0)^2 + (y - y0)^2)
Maximize[paraboloid[x, y], {x, y}]
Show[ContourPlot[paraboloid[x, y], {x, -5, 10}, {y, -5, 10},
Frame -> True, AxesOrigin -> {0, 0, 0},
ColorFunction -> "DarkRainbow", GridLines -> Automatic],
Graphics[{White, PointSize[Large], Point[{x, y} /. Last[%]]}]]
```

The path length for all the different paths from $a$ to $b$ can be considered a function.

The **function ** is now what we want to find stationary points for.

Show that the shortest distance between 2 points is a straight line

Find the shape of a ramp that will bring a sliding mass to a lower point the fastest.