Optics
Refraction
Light bending when entering a new medium — Snell's law, n₁·sin θ₁ = n₂·sin θ₂
Refraction is the bending of light when it crosses a boundary between two media — described by Snell's law (n₁·sin θ₁ = n₂·sin θ₂). The cause is wave speed change. Light slows in denser materials (higher refractive index n). Why a pencil looks bent in water, why prisms separate colors, how lenses focus light, and why mirages and rainbows form.
- Snell's lawn₁·sin θ₁ = n₂·sin θ₂
- Refractive indexn = c/v (vacuum speed / medium speed)
- Vacuum n1 (exactly, by definition)
- Water n1.33
- Glass n1.50 (typical)
- Diamond n2.42
Interactive visualization
Press play, or step through manually. The visualization is yours to drive — try it before reading on.
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
Snell's law
When light crosses from medium 1 (refractive index n₁) to medium 2 (n₂):
n₁ · sin θ₁ = n₂ · sin θ₂
Both angles measured from the surface normal. The incident ray, normal, and refracted ray are coplanar.
For air to water (n_air = 1.00, n_water = 1.33), incident at 45°:
1.00 · sin 45° = 1.33 · sin θ_water
sin θ_water = 0.707/1.33 = 0.532
θ_water = 32.1°
Light bends TOWARD the normal entering denser medium.
Refractive indices of common materials
| Material | n (visible) |
|---|---|
| Vacuum | 1.00 (exactly) |
| Air (sea level) | 1.0003 |
| Ice | 1.31 |
| Water | 1.33 |
| Ethanol | 1.36 |
| Quartz | 1.46 |
| Soda-lime glass | 1.52 |
| Crown glass | 1.52 |
| Flint glass (heavy) | 1.65 |
| Sapphire | 1.77 |
| Cubic zirconia | 2.16 |
| Diamond | 2.42 |
| Silicon | 3.42 (in IR) |
| Some metamaterials | negative (synthetic, exotic) |
Dispersion — different colors, different angles
| Color | Glass n | Water n |
|---|---|---|
| Red (700 nm) | 1.513 | 1.331 |
| Yellow (590 nm) | 1.518 | 1.333 |
| Green (550 nm) | 1.520 | 1.334 |
| Blue (450 nm) | 1.527 | 1.336 |
| Violet (400 nm) | 1.532 | 1.342 |
Difference is small (~1%) but visible — prisms split white light, raindrops form rainbows, and chromatic aberration in lenses creates color fringing.
JavaScript — refraction calculations
// Snell's law: find refracted angle
function refract(theta1_deg, n1, n2) {
const theta1 = theta1_deg * Math.PI / 180;
const sin_theta2 = (n1 / n2) * Math.sin(theta1);
if (Math.abs(sin_theta2) > 1) return null; // total internal reflection
return Math.asin(sin_theta2) * 180 / Math.PI;
}
// Air → water at 45°
console.log(`Air to water 45°: ${refract(45, 1, 1.33).toFixed(2)}°`); // 32.1
console.log(`Air to glass 30°: ${refract(30, 1, 1.5).toFixed(2)}°`); // 19.5
// Critical angle for total internal reflection
function criticalAngle(n_dense, n_rare) {
// sin θ_c = n_rare / n_dense (when refracted angle = 90°)
return Math.asin(n_rare / n_dense) * 180 / Math.PI;
}
console.log(`Glass-air critical: ${criticalAngle(1.5, 1).toFixed(2)}°`); // 41.8
console.log(`Water-air critical: ${criticalAngle(1.33, 1).toFixed(2)}°`); // 48.8
console.log(`Diamond-air critical: ${criticalAngle(2.42, 1).toFixed(2)}°`); // 24.4
// Ray-tracing: where does refraction take a ray going from air to water?
function refractRay(rayDir2D, normal2D, n1, n2) {
const cos_i = -rayDir2D[0]*normal2D[0] - rayDir2D[1]*normal2D[1];
const sin_i_squared = 1 - cos_i * cos_i;
const eta = n1 / n2;
const sin_t_squared = eta * eta * sin_i_squared;
if (sin_t_squared > 1) return null; // total internal reflection
const cos_t = Math.sqrt(1 - sin_t_squared);
return [
eta * rayDir2D[0] + (eta * cos_i - cos_t) * normal2D[0],
eta * rayDir2D[1] + (eta * cos_i - cos_t) * normal2D[1]
];
}
const rayIn = [0.7071, -0.7071]; // 45° down-right
const surfNormal = [0, 1]; // upward
console.log(refractRay(rayIn, surfNormal, 1, 1.33));
// Refraction in lens (thin lens, paraxial approximation)
function lensFocalLength(R1, R2, n_lens) {
// 1/f = (n - 1) · (1/R1 - 1/R2)
return 1 / ((n_lens - 1) * (1/R1 - 1/R2));
}
// Plano-convex lens, R1 = 0.5 m, R2 = ∞ (plano), n = 1.5
console.log(`Lens focal length: ${lensFocalLength(0.5, Infinity, 1.5)} m`);
// f = 1/(0.5 · 1/0.5) = 1 m
// Apparent depth in water (vertical viewing)
function apparentDepth(realDepth, n_water = 1.33) {
// Apparent depth = real_depth / n
return realDepth / n_water;
}
console.log(`2 m pool: looks ${apparentDepth(2).toFixed(2)} m deep`); // ~1.5
// Rainbow angle: primary rainbow occurs at ~42°
function rainbowAngle(n_water = 1.33) {
// Approximate; exact requires solving refraction + reflection
// For visible light, primary at 42° (single internal reflection)
return 42;
}
Where refraction shows up
- Optics — lenses. Eyeglasses, contact lenses, cameras, microscopes, telescopes.
- Optical fibers. Total internal reflection guides light along fiber. Long-distance communications, medical endoscopes.
- Photography. Lens design controls depth of field, perspective, focal length.
- Astronomy. Atmospheric refraction shifts star positions; refractive telescopes use lens-based focusing.
- Medical. Eye corrects vision via refraction; eyewear corrects focus errors.
- Atmospheric optics. Mirages, rainbows, halos, sun pillars all involve refraction in atmosphere.
- Geology. Refractometry identifies minerals by their refractive indices.
Common mistakes
- Wrong direction of bending. Going to denser medium → bends TOWARD normal. Going to less dense → bends AWAY from normal.
- Forgetting frequency stays constant. Wave speed and wavelength change at boundary; frequency does NOT. Color (frequency) doesn't change going from air to water.
- Treating apparent depth as real depth. A 2-m pool looks ~1.5 m deep when viewed from above (refraction at water surface). Don't dive into it as if it's truly 2 m!
- Confusing dispersion with refraction. Refraction = light bending. Dispersion = different colors bend by different amounts. Both happen together; dispersion is a special property of materials.
- Ignoring critical angle. Light going from dense to rare medium has total internal reflection beyond critical angle. Don't apply Snell's law beyond this.
- Treating refractive index as constant. n varies with wavelength (dispersion), and slightly with temperature. For precision optics, this matters.
Frequently asked questions
Why does light bend at a boundary?
When light enters a slower medium, the wavefronts crowd together (shorter wavelength). Mathematically — frequency f stays constant, but speed v decreases, so λ = v/f decreases. The crowding of wavefronts at an angle causes the wave to "tilt" — refraction. Energy still travels perpendicular to wavefronts.
What's Snell's law geometrically?
n₁·sin θ₁ = n₂·sin θ₂. Both angles measured from normal. Higher n → smaller angle from normal (more bent). Going from low n to high n (e.g., air to water): light bends TOWARD normal. Going from high n to low n (water to air): light bends AWAY from normal.
Why is refractive index different for different colors (dispersion)?
In materials, light interacts with electrons. Different frequencies of light couple differently to electron resonances. Result — refractive index is wavelength-dependent. Glass refracts violet (~1.532) more than red (~1.513). Why prisms split white light. Diamonds have stronger dispersion than glass — that's why they sparkle with color.
How do lenses use refraction?
Lens shape (convex or concave) bends incoming light by refraction. Convex (converging) lens focuses parallel light to a point (focal point). Concave (diverging) makes light spread. Combination of curvature and refractive index determines focal length. Cameras, eyes, telescopes, microscopes — all use lens refraction.
What makes a pencil look bent in water?
Light from the submerged part refracts when leaving water (going to lower-n air). Your eye traces the apparent ray back along the path it sees, but the actual path bent at the water surface. Result — image appears displaced, making the pencil look bent.
Why do rainbows form?
Sunlight refracts entering a raindrop, reflects off the back, refracts again exiting. Different wavelengths refract by slightly different angles (dispersion). Result — colors separated. Primary rainbow at ~42° from anti-sun direction (red outer, violet inner). Secondary rainbow at ~51° (reversed colors, fainter — second internal reflection).
How does atmospheric refraction affect astronomy?
Earth's atmosphere acts like a giant lens. Air density (and thus n) varies with altitude. Light from stars near the horizon bends, making them appear higher. The Sun appears flattened at sunrise/sunset because rays from the bottom edge bend more (longer atmospheric path). Apparent positions of stars are corrected by 0.5° at horizon.