Home▸Articles▸Nature & Climate

Understanding Rainbow Formation Through Ray Tracing

A detailed exploration of how light behaves when it enters a water droplet, leading to the formation of rainbows in nature.

mysimulator teamUpdated June 2026≈ 3 min read▶ Open the simulation

What is Ray Tracing?

Ray tracing is a fundamental technique in optics that simulates the path of light as it travels, refracts, reflects, or scatters within a medium. In the context of rainbows, ray tracing helps us visualize and understand how sunlight interacts with water droplets.

By tracing individual rays through the droplet, we can predict the angles at which light exits the droplet, leading to the formation of distinct rainbow colors.

Snell's Law and Refraction

When a ray of light enters a medium with a different refractive index (like from air into water), it bends or changes direction. This bending is described by Snell's law, which states that the ratio of the sine of the angle of incidence to the sine of the angle of refraction equals the ratio of the refractive indices of the two media.

For example, when sunlight enters a water droplet, the light slows down and bends towards the normal (an imaginary line perpendicular to the surface), causing the rainbow's primary bow.

live demo · related simulation● LIVE

Internal Reflection and Rainbow Formation

After entering the droplet, some of the light undergoes internal reflection off the back surface of the droplet. Depending on the angle of incidence, this can lead to a second internal reflection before exiting the droplet.

This process results in the secondary rainbow, which is fainter and appears at a larger angle (about 51 degrees) compared to the primary bow.

Dispersion and Color Separation

Light of different wavelengths travels at slightly different speeds through water. This phenomenon, known as dispersion, causes light to separate into its constituent colors.

The primary rainbow is formed by one internal reflection, while the secondary bow results from two internal reflections, each contributing to a more dispersed spectrum.

Frequently asked questions

How does changing the droplet medium affect the rainbow?

Changing the medium (e.g., from water to glycerol) alters the refractive index, which in turn changes the angles of refraction and reflection, affecting the positions of the primary and secondary rainbows.

Why do we see only one rainbow at a time during a rain shower?

The human eye can only perceive one rainbow at a time because each droplet acts as a separate lens. The light from other droplets is scattered in different directions, making it difficult to see multiple rainbows simultaneously.

Can we observe both primary and secondary bows together?

Yes, under specific conditions, such as when the sun is low on the horizon or during a twilight rainbow, you can sometimes observe both the primary and secondary bows in the sky at the same time.

What role does the impact parameter play in ray tracing?

The impact parameter determines how close a ray comes to the center of the droplet. It influences whether the light undergoes one or two internal reflections, which is crucial for understanding both primary and secondary rainbow formation.

Try it live

Everything above runs in your browser — open Rainbow Ray Tracer (2D) and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Rainbow Ray Tracer (2D) simulation

What did you find?

Add reproduction steps (optional)