Rainbow Ray Tracer (2D)

This 2D companion to the 3D atmospheric rainbow trades the wide sky scene for the geometry underneath it: a flat cross-section of a single spherical droplet with individual light rays traced through it one Snell's-law refraction, one or two internal reflections, and a final refraction at a time. Every ray in the fan is a genuine vector-optics computation — the seven coloured rays you see splitting apart are seven different refractive indices, each producing its own exit angle from the same entry height. The graph beside the droplet plots that exit (scattering) angle against entry height for every traced ray, and its peak at roughly 42° and dip at roughly 51° are the primary and secondary rainbow angles, discovered here the same way Descartes and Airy derived them: by tracing rays through a sphere and finding where they bunch up.

🔬 What It Demonstrates

Real vector refraction and reflection at a circular boundary, wavelength-dependent dispersion, and the minimum-deviation caustic that makes the rainbow angle bright rather than an arbitrary cutoff.

🎮 How to Use

Drag the impact-parameter slider to move a single highlighted ray across the droplet, or press Sweep to animate it. Toggle the ray fan and the secondary bow, and switch the droplet's liquid to see the angles shift.

💡 Did You Know?

The bright edge of a rainbow exists because many different entry heights all produce almost the same exit angle there — a ray-density pile-up called a caustic, the same optical effect that makes light patterns dance on a swimming-pool floor.