# Optics/Fermat's Principle
## The Principle

Fermat's Principle, also known as "The Principle of Least Time" states that:
    "Light travels through the path in which it can reach the destination in least time".
It is a fundamental law of optics from which the other laws of geometrical optics can be derived.

## Derivation for Law of Reflection

The derivation of Law of Reflection using Fermat's principle is straightforward. The Law of Reflection can be derived using elementary calculus and trigonometry. The generalization of the Law of Reflection is Snell's law, which is derived below using the same principle.
The medium that light travels through doesn't change. In order to minimize the time for light travel between two points, we should minimize the path taken.
1. Total path length of the light is given by
    $L=d_{1}+d_{2}\,$
2. Using Pythagorean theorem from Euclidean Geometry we see that
    $d_{1}={\sqrt {x^{2}+a^{2}}}\,$ and $d_{2}={\sqrt {(l-x)^{2}+b^{2}}}\,$
3. When we substitute both values of d$_1$ and d$_2$ for above, we get
    $L={\sqrt {x^{2}+a^{2}}}+{\sqrt {(l-x)^{2}+b^{2}}}$
4. In order to minimize the path traveled by light, we take the first derivative of L with respect to x.
    ${\frac {dL}{dx}}={\frac {x}{\sqrt {x^{2}+a^{2}}}}+{\frac {-(l-x)}{\sqrt {(l-x)^{2}+b^{2}}}}=0$
5. Set both sides equal to each other.
    ${\frac {x}{\sqrt {x^{2}+a^{2}}}}={\frac {(l-x)}{\sqrt {(l-x)^{2}+b^{2}}}}$
6. We can now tell that the left side is nothing but $\sin \theta _{i}$ and the right side $\sin \theta _{r}$ means
    $\sin \theta _{i}=\sin \theta _{r}\!\$
7. Taking the inverse sine of both sides we see that the angle of incidence equals the angle of reflection
    $\theta _{i}=\theta _{r}\!\$

## Derivation for Snell's Law

The derivation of Snell's Law using Fermat's Principle is straightforward. Snell's Law can be derived using elementary calculus and trigonometry. Snell's Law is the generalization of the above in that it does not require the medium to be the same everywhere.
To mark the speed of light in different media refractive indices named n$_1$ and n$_2$ are used.
    $v_{1}={\frac {c}{n_{1}}}\!\$
    $v_{2}={\frac {c}{n_{2}}}$
Here $c$ is the speed of light in a vacuum and $n_{1},n_{2}\geq 1\,$ because all materials slow down light as it travels through them.
1. Time for the trip equals distance traveled divided by the speed.
    $T={\frac {d_{1}}{v_{1}}}+{\frac {d_{2}}{v_{2}}}$
2. Using the Pythagorean theorem from Euclidean Geometry we see that
    ${\frac {d_{1}}{v_{1}}}={\frac {\sqrt {x^{2}+a^{2}}}{v_{1}}}\,$ and ${\frac {d_{2}}{v_{2}}}={\frac {\sqrt {b^{2}+(l-x)^{2}}}{v_{2}}}\,$
3. Substituting this result into equation (1) we get
    $T={\frac {\sqrt {x^{2}+a^{2}}}{v_{1}}}+{\frac {\sqrt {b^{2}+(l-x)^{2}}}{v_{2}}}$
4. To minimize the transit time, we take the derivative with respect to the variable $x$ and set it equal to zero:
    ${\frac {dT}{dx}}={\frac {x}{v_{1}{\sqrt {x^{2}+a^{2}}}}}+{\frac {-(l-x)}{v_{2}{\sqrt {(l-x)^{2}+b^{2}}}}}=0$
5. After careful examination the above equation we see that it is nothing but
    ${\frac {dT}{dx}}={\frac {\sin \theta _{1}}{v_{1}}}-{\frac {\sin \theta _{2}}{v_{2}}}=0$
6. This leads to
    ${\frac {\sin \theta _{1}}{v_{1}}}={\frac {\sin \theta _{2}}{v_{2}}}$
7. Substituting ${\frac {n_{1}}{c}}$ for ${\frac {1}{v_{1}}}$ and ${\frac {n_{2}}{c}}$ for ${\frac {1}{v_{2}}}$ we get
    ${\frac {n_{1}}{c}}\sin \theta _{1}={\frac {n_{2}}{c}}\sin \theta _{2}$
8. Multiplying through by $c$ gives us our result
    $n_{1}\sin \theta _{1}=n_{2}\sin \theta _{2}\!\$