Total internal reflection occurs when light travels from an optically dense medium to a less dense medium and the angle of incidence is greater than the critical angle. At the critical angle, the refracted ray travels along the surface of the dense medium. If the incident ray exceeds the critical angle, total internal reflection occurs and the light ray is reflected back into the dense medium rather than refracting into the less dense medium. Mirages can form due to both total internal reflection and refraction as light passes through layers of air with different densities. Snell's law defines the mathematical relationship between the angle of incidence, angle of refraction, and the indices of refraction of the media.