Modeling Double Slit Interference With Python

Rhett Allain
7 min readAug 13, 2023
Photo: Rhett Allain. Interference due to a diffraction grating because it looks cool.

The goal here is to model the pattern of light you get when a laser passes through a double slit. There’s a lot of stuff to do for this, so let’s get started.

Light as an Electromagnetic Wave

Of course light is an electromagnetic wave. That means it’s an oscillation of both the electric and magnetic fields. When the electric field changes, the magnetic field changes and both fields change in space AND time.

Suppose the wave is traveling in the x-direction. Then the magnitude of the electric and magnetic fields can be calculated as the following:

Where f is the frequency of the wave and λ is the wavelength. Since the fields change in both space and time, it’s fun to make a visual graphic (not needed for the calculations). It looks like this. Note: this is just the EM wave along one line — a light ray. There could be many of these in different directions from the source.

Here’s a video tutorial showing how to make this animation. What about the intensity of light? This can be calculated based on the electric field (you could do it for the magnetic field too) but in general, it’s proportional to the square of the magnitude of the electric field.

We are going to use that later.

Two Point Sources

Suppose I have two point sources that produce EM waves that are in phase (maximum electric fields at the same time). If you want, you could think of this as a double slit, but both slits have zero width (the width matters in the real world).

These two sources are a distance d apart and the light rays travel out towards a screen a distance L away. These two light rays (with a wavelength λ) will meet at some point on the screen such that the path length is different. Here’s a diagram.

Yes, there’s a bunch of stuff going on in that diagram. Let me go over the details.



Rhett Allain

Physics faculty, science blogger of all things geek. Technical Consultant for CBS MacGyver and MythBusters. WIRED blogger.