Snell's law
In optics and physics, Snell's law (also known as Descartes' law or the law of diffraction), is a formula used to describe the relationship between the angles of incidence and refraction, when referring to light or other waves, passing through a boundary between two different isotropic media, such as water and glass.  The law says that the ratio of the sines of the angles of incidence and of refraction is a constant that depends on the media.
In optics, the law is used in ray tracing to compute the angles of incidence or refraction, and in experimental optics to find the refractive index of a material.
Named after Dutch mathematician Willebrord Snellius, one of its discoverers,  Snell's law states that the ratio of the sines of the angles of incidence and refraction is equivalent to the ratio of velocities in the two media, or equivalent to the opposite ratio of the indices of refraction:
-r
Snell's law follows from Fermat's principle of least time, which in turn follows from the propagation of light as waves.

# History
Ptolemy, of ancient Greece, had, through experiment, found a relationship regarding refraction angles, but which was inaccurate for angles that were not small. Ptolemy was confident he had found an accurate empirical law, partially as a result of fudging his data to fit theory (see: confirmation bias).
Snell's law was first described in a formal manuscript in a 984 writing by Ibn Sahl, who used it to work out the shapes of lenses that focus light with no geometric aberrations, known as anaclastic lenses.
It was described again by Thomas Harriot in 1602, who did not publish his work.
In 1621, Willebrord Snellius (Snel) derived a mathematically equivalent form, that remained unpublished during his lifetime. Rene Descartes independently derived the law using heuristic momentum conservation arguments in terms of sines in his 1637 treatise Discourse on Method, and used it to solve a range of optical problems. Rejecting Descartes' solution, Pierre de Fermat arrived at the same solution based solely on his principle of least time.
According to Dijksterhuis, "In De natura lucis et proprietate (1662) Isaac Vossius said that Descartes had seen Snell's paper and concocted his own proof.  We now know this charge to be undeserved but it has been adopted many times since."  Both Fermat and Huygens repeated this accusation that Descartes had copied Snell.
In French, Snell's Law is called "la loi de Descartes" or "loi de Snell-Descartes."
In his 1678 Traite de la Lumiere, Christiaan Huygens showed how Snell's law of sines could be explained by, or derived from, the wave nature of light, using what we have come to call the HuygensFresnel principle.
Although he spelled his name "Snel", as noted above, it has conventionally been spelled "Snell", apparently by misinterpreting the Latin form of his name, "Snellius".

# Explanation
Snell's law is used to determine the direction of light rays through refractive media with varying indices of refraction. The indices of refraction of the media, labeled n_1,n_2 and so on, are used to represent the factor by which a light ray's speed decreases when traveling through a refractive medium, such as glass or water, as opposed 
to its velocity in a vacuum.
As light passes the border between media, depending upon the relative refractive indices of the two media, the light will either be refracted to a lesser angle, or a greater one. These angles are measured with respect to the normal line, represented perpendicular to the boundary. In the case of light traveling from air into water, light would be refracted towards the normal line, because the light is slowed down in water; light traveling from water to air would refract away from the normal line.
Refraction between two surfaces is also referred to as reversible because if all conditions were identical, the angles would be the same for light propagating in the opposite direction.
Snell's law is generally true only for isotropic or specular media (such as glass). In anisotropic media such as some crystals, birefringence may split the refracted ray into two rays, the ordinary or o-ray which follows Snell's law, and the other extraordinary or e-ray which may not be co-planar with the incident ray.
When the light or other wave involved is monochromatic, that is, of a single frequency, Snell's law can also be expressed in terms of a ratio of wavelengths in the two media, 1 and 2:

## Total internal reflection and critical angle
When light moves from a dense to a less dense medium, such as from water to air, Snell's law cannot be used to calculate the refracted angle when the resolved sine value is higher than 1. At this point, light is reflected in the incident medium, known as internal reflection. Before the ray totally internally reflects, the light refracts at the critical angle; it travels directly along the surface between the two refractive media, without a change in phases like in other forms of optical phenomena.
As an example, a ray of light is incident at 50^o towards a waterair boundary. If the angle is calculated using Snell's Law, then the resulting sine value will not invert, and thus the refracted angle cannot be calculated by Snell's law, due to the absence of a refracted outgoing ray:
In order to calculate the critical angle, let \theta_2 = 90^o and solve for \theta_\mathrm{crit}:
When 1 > crit, no refracted ray appears, and the incident ray undergoes total internal reflection from the interface medium.

## Derivations
Snell's law may be derived from Fermat's principle, which states that the light travels the path which takes the least time.  By taking the derivative of the optical path length, the stationary point is found giving the path taken by the light (though it should be noted that the result does not show light taking the least time path, but rather one that is stationary with respect to small variations as there are cases where light actually takes the greatest time path, as in a spherical mirror). In a classic analogy by Richard Feynman, the area of lower refractive index is replaced by a beach, the area of higher refractive index by the sea, and the fastest way for a rescuer on the beach to get to a drowning person in the sea is to run along a path that follows Snell's law.
Alternatively, Snell's law can be derived using interference of all possible paths of light wave from source to observerit results in destructive interference everywhere except extrema of phase (where interference is constructive)which become actual paths.
Another way to derive Snells Law involves an application of the general boundary conditions of Maxwell equations for electromagnetic radiation.

# Vector form
Given a normalized light vector l (pointing from the light source toward the surface) and a normalized plane normal vector n, one can work out the normalized reflected and refracted rays:
\frac{n_1}{n_2}\cos\theta_1 - \cos\theta_2\right)\mathbf{n}
Note: \mathbf{n}\cdot(-\mathbf{l}) must be positive. Otherwise, use
Example:
,~\mathbf{v}_{\mathrm{refract}}=\{0.777817, -0.62849\}
The cosines may be recycled and used in the Fresnel equations for working out the intensity of the resulting rays. During total internal reflection an evanescent wave is produced, which rapidly decays from the surface into the second medium. Conservation of energy is maintained by the circulation of energy across the boundary, averaging to zero net energy transmission.

# Dispersion
In many wave-propagation media, wave velocity changes with frequency or wavelength of the waves; this is true of light propagation in most transparent substances other than a vacuum.  These media are called dispersive.  The result is that the angles determined by Snell's law also depend on frequency or wavelength, so that a ray of mixed wavelengths, such as white light, will spread or disperse.  Such dispersion of light in glass or water underlies the origin of rainbows, in which different wavelengths appear as different colors.
In optical instruments, dispersion leads to chromatic aberration, a color-dependent blurring that sometimes is the resolution-limiting effect.  This was especially true in refracting telescopes, before the invention of achromatic objective lenses.