The formation of rainbows is a topic which seems to lend itself to erroneous explanations. So let us try to avoid errors.

A falling raindrop will be be almost a perfect sphere, due to surface tension. It certainly will not be drop-shaped.

Light entering it will mostly pass out the other side, after being focussed (inexactly) by the spherical lens. But an amount will be reflected on the first attempt to exit the water droplet. This is the part which forms the rainbow, so just this reflected path is shown in the diagram below.

Rainbow water droplet ray diagram

On entering the raindrop the light is deviated by an angle of θ-φ, on reflecting by an angle of 180°-2φ, and on exit by an angle of θ-φ, where θ is the angle between the incident light and the surface of the raindrop, and φ is the angle of refraction given by Snell's law:

n sin(φ)=sin(θ)

where n is the refractive index, about 1.33 in the case of water.

So the total angle through which the light ray deviates is 180°+2θ-4φ. It can be more convenient to work with the acute angle between the incident and reflected rays, and this is simply 4φ-2θ.

Depending on where the light strikes the drop, from in line with its centre, to grazing it at its top, θ can vary between 0° and 90°. Raindrops are small when considered at the distance of rainbows, so all that matters is the angle through which the light is reflected, and not the tiny sideways displacement it may suffer. But it is not immediately clear how one gets a rainbow from the range of possible values of θ, which presumably map to a range of possible values of 4φ-2θ. It would seem that light is being scattered everywhere, not in a single direction which depends on the precise value of the refractive index, a value which does vary slightly from red to blue.

So let us use python and its turtle graphics to plot what happens for a few dozen equispaced rays incident on a spherical droplet, and let us also create a histogram of the angle of deviation.


Rainbow water droplet multiple rays diagramRainbow water droplet histogram of angles

As the plot is produced, one can see that the angle 4φ-2θ reaches a maximum of a little over 42° and then decreases again. Furthermore, the crude histogram shows that there are more rays close to the maximum than elsewhere.

With this understanding, we can remove all the turtle graphics from our python, and simply produce a histogram, but with many more rays, here about 5,000.


Rainbow water droplet histogram of angles

The peak at the maximum angle is huge! (And thin -- it may be necessary to increase the plot window width to see it all.) If the light source generating the rainbow were monochromatic, this would lead to a cone of light being reflected backwards, at all angles between 0° and about 42.5° (where 0° means reflected back to the source), but with a sharp increase in intensity at the maximum.

With sunlight, the variation of refractive index with wavelength (colour) means that this peak in intensity occurs at a slightly different angle for each colour, so we see the colours separated. We barely notice the dimmer reflected light away from this peak, but, if one looks carefully at a photograph of a rainbow, one can usually observe that the sky within the bow looks brighter than the sky immediately above the bow. Within the bow there is extra light from the reflections at smaller angles, whereas above the bow there is no enhancement from reflection.

We could have dispensed with the Raspberry Pi and used calculus to produce the histogram. But this analysis of the rainbow was first recorded by René Descartes in 1637. Isaac Newton was not then born, and calculus was still some decades away.

Descartes was not able to explain the colours of the rainbow, for he did not realise that the refractive index of water depends on the colour of the light, varying from about 1.331 for red light to around 1.344 for violet.


What does the function 4φ-2θ look like? The answer for visualising it in python might be

import matplotlib.pyplot as plt
import numpy as np


Alternatively one can install the plotting program gnuplot

$ sudo apt-get install gnuplot

And then, this time working in radians, so the range for theta is about 0 to 1.5,

  $ gnuplot
  gnuplot> plot [0:1.5] 4*asin(sin(x)/1.33)-2*x

The peak is at approximately 0.75 radians, which is 0.75*180/π degrees, or approximately 43°.

Plots in Gnuplot and matplotlib

Gnuplot on the left, matplotlib on the right.


Is there gold at the end of the rainbow? Where is its end?

The rays of light from the distant Sun are all parallel to each other. The rainbow is a circle made when these rays are reflected through 42°. But the distance to the point (raindrop) at which the reflection occurs can be anything. All raindrops along a line will contribute to a point of the rainbow. One cannot measure the distance to the rainbow, unless the rain is falling as a very thin curtain.

The end of a rainbow

The above simple diagram shows the Sun 20° above the horizon, so its rays slope down at 20°. The red line which rises at 22° meets the Sun's rays at an angle of 42°, so represents the line along which the strong reflection giving rise to a rainbow will occur. Provided there are raindrops where it is shown intersecting with the Sun's rays, those drops will contribute to the bow, despite being a different distances from the observer on the ground. An observer will see a bow the top of which is 22° above the horizontal.

Note also that if the Sun is higher than 42° in the sky, the red line will no longer rise. To see a bow one would have to look downwards, possible only if the horizon is below the horizontal (e.g. from an aeroplane or from the top of a hill). The largest bows are seen when the Sun is low in the sky, such as near sunrise and sunset. In the UK bows can been seen at midday in Winter, but not at midday in Summer unless one's horizon is below the horizontal.

See also some photos of rainbows.