# How can I plot a rainbow?

I'm trying to write a program that can simulate a rainbow. So far I've got figured out how to determine the change in the refractive index depending on the wavelength, the angular deviation of the scattered ray depending on the number of reflexions inside the water droplet, and so on. The only thing I'm still uncertain of is how I can plot the rainbow using this info. I'm thinking about using something like sin and cosine of the angle of the scattered ray, but then I don't know what determines the radius of the rainbow in the sky. Any help is welcome.

Please keep in mind I have simple knowledge of programming and overall optics (bachelor's degree in physics level).

• Would Computational Science be a better home for this question? Commented Sep 30, 2021 at 16:28
• @Qmechanic I'll write it there too, thanks. I just thought it would be a better suit here because my problem is not on the code itself, but how to transform the information I have into the information I need to actually make the plot
– Jeff
Commented Sep 30, 2021 at 16:43

then I don't know what determines the radius of the rainbow in the sky

The angular radius of the rainbow depends only of the refractive index of rain water. Regardless of where you are, it's always about 42° for primary bow and about 51° for secondary bow. Exact values of radii depend on frequency of light.

The center of the rainbow is opposite to the Sun.

Also, don't forget that the Sun itself has an angular diameter of about 0.5°, which results in smearing of the rainbow by half a degree.

Are any of these 18 acceptable?

The 30 lines of code is written by Fabrice Neyret on Shadertoy

• It's not even close to a rainbow, just a sequence of somewhat saturated sRGB colors. Commented Sep 30, 2021 at 21:03

A rainbow forms an arc which is part of a circle. When viewing a rainbow, if you face the center of the rainbow, the sun will be at your back. A beam of sunlight which goes past your head goes to the center of the circle. Other beams, parallel to that one, go into the rain and are reflected back to your eye. For each color, there is a particular angle of reflection which enhances that reflection. That angle is generally calculated between an incident parallel ray and the one that reflects back to your eye, and it determines the observed angular size of the circle. (Do a side view sketch.) The apparent actual size of the circle will depend on your distance to the rain.

• Actually, the apparent size (i.e. angular radius) of the circle will be the same for any rain. It only depends on refractive index of rain water. The dependence of refractive index will define actual size of the circle for each frequency of light. Also, there's easily visible secondary bow, which is at another angle, depending on the same parameters, but takes two internal reflections, rather than one for the primary bow. Commented Sep 30, 2021 at 21:11