Mathematics of rainbows
Their location as a fun optimization problem
Applied question
I’m sure that you’ve all seen rainbows and were struck by their beauty at some point. I would guess that most of you have seen how a prism can create rainbow effect as well. You probably know that this happens because light is refracted or bent when it passes from one medium to another (like from air to water or glass). If you really got into the weeds, you might have learned that the amount of refraction obeys an equation called Snell’s law. Furthermore, the amount of refraction depends on the wavelength. Thus the different colors bend different amounts and the light is separated into those different colors.
A schematic diagram of that might look something like so:
How does this work to form a rainbow, though? And why is it that a rainbow forms where it does?
More specifically, it’s explained on Wikipedia’s rainbow page that rainbows consistently form at an angle of about \(42^{\circ}\) above the horizon. Why is that?
As it turn out, that \(42^{\circ}\) angle can be derived by a minimization process in calculus. The purpose of this webpage is to explain that process.
Analysis
Here’s a schematic diagram of a light rays coming in from the horizon behind you, bouncing off of distant rain in front of you, and then coming toward you:
We want to set up an optimization problem explaining where that magic angle of \(42^{\circ}\) comes from. First, we need to consider the path of a light ray which passes through a distant raindrop and, ultimately, to our adoring eyes. That might look something like so:
Note that the light ray is first refracted, then reflected, and then refracted again. At the first point, the entering normal angle \(\alpha\) is related to the angle of refraction \(\beta\) by Snell’s law:
\[\sin (\alpha )=k \sin (\beta ).\]
The parameter \(k\) is called the index of refraction and depends upon the material and the wavelength being refracted. At the second point, the angle of incidence and the angle of reflection are both \(\beta\). At the exit point, the angle of incidence is now \(\beta\) and the angle of refraction is \(\alpha\). Note that the total clockwise rotation that the ray goes through is
\[(\alpha -\beta )+(\pi -2\beta )+(\alpha -\beta )=\pi +2\alpha -4\beta\]
We might call this total clockwise rotation the deviation of the ray.
Now, of course, there are many parallel light rays entering the raindrop. A large collection of these might look something like this:
Since the drop is very small and far away, we could even illustrate the exiting rays by collecting them to show them emanating from a point:
The opacity in this image emphasizes the following crucial point: The light coming out of the drop will be most intense where the exiting rays are most strongly concentrated. This happens at the bottom of the picture, where the angle of deviation of the incoming light is the smallest. Thus to figure out where to look for a rainbow, we should try to find that minimum possible deviation. The angle at which we need to look up will be supplementary to the minimum possible deviation.
Now as we saw above,
\[d(\alpha ,\beta )=\pi +2\alpha -4\beta\]
represents the amount of clockwise rotation that a light ray undergoes as it passes through a spherical body (such as a raindrop) as a function of the entering normal angle \(\alpha\) and the angle of refraction \(\beta\). We need to reduce this to a function of a single variable, which we can do since \(\alpha\) and \(\beta\) are related via Snell’s law. Specifically,
\[\sin (\alpha )=k \sin (\beta )\text{ }\Rightarrow \text{ }\beta = \arcsin \left(\frac{1}{k}\sin (\alpha )\right).\]
Thus,
\[d(\alpha )=\pi +2\alpha -4\arcsin \left(\frac{1}{k}\sin (\alpha )\right).\]
Now, the index of refraction for light passing from light into water is \(k\approx4/3\). Thus, we’ve got to minimize this expression when \(k\) is that value. Since this is supposed to be just for fun, I’m going to use a computer algebra system to do it. That system is called SymPy and is implemented in Python.
Here’s some code to define the deviation function and compute it’s derivative:
from sympy import *
= var('alpha')
alpha = 4/3
k def d(alpha):
return pi + 2*alpha - 4*asin(sin(alpha)/k)
= diff(d(alpha), alpha)
deriv deriv
\(\displaystyle 2 - \frac{3.0 \cos{\left(\alpha \right)}}{\sqrt{1 - 0.5625 \sin^{2}{\left(\alpha \right)}}}\)
Since we’re using SymPy, it’s easy to find the critical points:
= solve(deriv, alpha)
critical_points critical_points
[-1.03657028222698, 1.03657028222698]
It turns out that there are two critical points that are equal but opposite. I believe that we can use either one, if we interpret correctly. Let’s choose the positive one. Thus, if we want the minimal deviation in degrees, we can do the following:
= critical_points[1]
cp = N(d(cp)*180/pi)
minimal_deviation minimal_deviation
\(\displaystyle 137.970341134302\)
We want to tilt our head to the supplementary angle:
180 - minimal_deviation
\(\displaystyle 42.0296588656977\)
So if the sun is setting behind us and it is raining in front of us, we need to look up at an angle of approximately \(42^{{}^{\circ}}\) to see the rainbow!
I wonder where the secondary rainbow comes from??
The code
You can run the code on this page on any system with Python and SymPy. At UNCA, that includes Google Colab, which is part of our Google Suite. Anyone can also run it in this Sage Cell.