Sun and Oracle Community Voices How to Buy Log In United States [Change] English

Navbar Here$navbar =
$url_id =
$ROOT_ID = 1
$url = /people/detlefs/rainbow.html

How a rainbow is formed. (A Java(TM) experiment.)

david.detlefs@sun.com

I was first told how a rainbow works in second-term college physics. The explanation mostly served to exercise some things we had just learned: Snell's law, total internal reflection, etc. That explanation showed that any light ray from the sun that refracts once on entry, reflects once internally, and then refracts on exit coming back to towards a viewer makes an angle of at most 42 degrees with the path from the sun to the droplet. I have seen this explanation in several places, including the excellent book Rainbows, Halos, and Glories, by ???, but it has always left me somewhat unsatisfied, since it does not by itself explain the presence of the rainbow. An explanation of the rainbow has two parts:
  1. Why is there a brighter part of the sky at all?
  2. Why is that part of the sky divided up into different color bands?
The existence of a maximum value is not in itself sufficient to answer question 1. Imagine that you shoot an infinite number of light rays from the sun into a spherical water droplet, within a given plane that cuts the droplet through its center. Consider those rays that enter, say, in the left half of the circle. Assume, reasonably enough, that their radial offsets are uniformly distributed. What is the corresponding distribution of outgoing angles? The maximum angle explanation tells us that it is non-zero only between 0 and 42 degrees, but what if it is evenly distributed between there? Then there would be no especially bright part of the sky.

My little demo here demonstrates that the angular distribution not only has a maximum value, but it is strongly skewed toward that maximum. By clicking below the black bar that delimits the left-side radial displacements into the blue water droplet, you send a ray into the droplet and see it come out. It gets added to the output angle histogram. You can randomly choose radial offsets and let it run awhile. Or you can run 1000 fast without animating them, to see the final shape of the histogram (1000 seems to do fine.)

We see no that the existence of the bright spot is because the distribution peaks sharply at about 42 degrees. Even if the distribution tailed on to 90 degrees, we would still get a rainbow.

Extensions one could do

Having answered question 1, we could also answer question 2, by randomly choosing a color for the ray and varying the effective index of refraction of the water droplet accordingly. Visually, we could show the rainbow as it builds up.

Other rainbow sites


Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries.