Understanding Electric Fields by Creating a Simulation
A Rabbit Hole
I was recently watching a YouTube video on the Ukraine war, and there was a part where it showed a first person view of a reconnaissance drone flying at night, armed with a thermal camera.
I knew that thermal cameras worked by detecting IR radiation, and I knew hotter objects (e.g. living things) emit more IR, but I didn’t know why. Why was it that a higher temperature meant more IR radiation?
Why do Hotter Objects Emit More IR Radiation?
I started digging into this, and long story short, the molecules in a hotter object move around, rotate, and vibrate more. These molecules of course have charges, and in fact when the charge distribution is uneven, they have what are called dipole moments. As the molecules move, rotate, and vibrate, these dipole moments oscillate. When dipole moments oscillate, it means that the underlying electric field is oscillating, and it is this underlying electric field oscillation that starts the propagation of an electromagnetic wave!
We’ll get into why an electric field oscillation causes an electromagnetic wave to propagate in a bit, but first, why is it that an electromagnetic wave in the IR band is the one that’s emitted, why not another frequency/band?
The answer to this is that the oscillation of the dipole moments (and thus the electric field) in the molecules is at a frequency that corresponds to the IR band. So in simpler terms, the molecules in hot objects vibrate at a frequency that just happens to correspond to the IR band.
Now, why is it that electric field oscillations cause an electromagnetic wave to propagate? This is because of the relationship between electric fields and magnetic fields, which is described by Maxwell’s equations. In short, a changing electric field induces a magnetic field, and a changing magnetic field induces an electric field.
So, the molecules move, which means the dipole moments change, which means the electric field changes, which induces a changing magnetic field around it, which in turn induces a changing electric field around it, and so on and so forth. This electromagnetic wave self-propagates through empty space, it needs no medium.
As an EM wave propagates further and further from the source, the energy of the wave dissipates, proportional to distance from the source squared. This is because the energy is spreading out on the surface of an ever-growing sphere, and if you recall, the relationship between the surface area of a sphere and its radius is given by:
Where:
- is the surface area
- is the radius of the sphere
This means the surface area grows proportionally to the radius squared, and since the electromagnetic wave is spreading out on the surface of this sphere, the energy density (energy per unit area) decreases as the radius squared.
Understanding Electric Fields
This rabbit hole sparked an interest to deepen my understanding of electric fields. What exactly are they? Can I understand the math behind them? Can I connect them to related concepts (charge, mass, force, etc.)?
True to the modern times, I started by asking Deepseek, looking at the formulas, trying to make sense of them, and doing a few problems. I then watched a few helpful YouTube videos on related topics.
Here is my current understanding.
Basic Electric Field Formula
Charges emit electric fields, similar to how masses emit gravitational fields. The magnitude of the electric field at some distance from a point charge is given by:
Where:
- is the electric field strength (in N/C)
- is Coulomb’s constant (just a constant)
- is the charge (in C)
- is the distance from the charge
The direction is away from the charge if the charge is positive, and towards the charge if the charge is negative.
Notice that the magnitude of the electric field falls proportionally to the distance squared. In other words its magnitude falls quadratically with distance!
Vector Form of the Electric Field Formula
An electric field is a vector field, which means for every point in space, there is a vector that describes the electric field at that point, both its magnitude and its direction. Our formula above is a little wishy-washy, let’s include vectors:
Where:
- is the electric field vector
- is the unit vector in the direction of the electric field (away from the charge if positive, towards if negative)
- is the position vector from the charge to the point where we want to calculate the electric field
So let’s clarify some terminology. When we say electric field, we are talking about the entire vector field (all the vectors). If you want to describe the electric field vector (magnitude and direction) at a specific point in space, you call it an electric field vector.
Now that I understood what electric fields were and their formula, I wanted to simulation/visualize them. The plan was simple. Have a couple of charges defined in space, divide the space into a grid, and calculate the electric field vector at each point in the grid. Then, draw arrows at each point in the grid to represent the electric field vector at that point.
Now, before I show you the simulation, let me discuss one more thing.
Electric Force
The unit of electric field is N/C (Newtons per Coulomb), which means that the electric field at a point in space tells you how much force a charge would feel if it were placed at that point. The amount of force the charge would feel is proportional to the magnitude of the charge. Here is the formula (non vector form):
Where:
- is the force on the charge (in N)
- is the charge (in C)
- is the electric field at that point (in N/C)
The force on the charge is in the same direction as the electric field vector at that point (if the charge is positive, opposite if negative).
With an understanding of how electric fields apply a force on charges, I updated my simulation to make charges accelerate according to the electric force acting on them.
It was fairly simple. I get the field vector at the position of the charge, then I multiply it by the charge to get the force on the charge, and then I deduce an acceleration from the force (and the object’s mass). I then update the object’s velocity/position.
Some notes:
- The electric field vector says it will apply an electric force proportional to the magnitude of the charge of the object it is acting on. This force will be in the same direction as the electric field vector (if the charge is positive, opposite if negative).
- So if you know the charge of the object at the point, you know the electric force on it (in N)
- If you know the force on the object, and its mass, you know how much its acceleration should be
- Use the acceleration and delta-time to update the velocity and use the velocity and delta-time to update the position
Electric Field Vector Due to Multiple Charges
I know, I know, I said I would show you the simulation, but I wanted to mention one last thing. I wanted to have the ability to add multiple charges in my simulation, so I had to figure out the electric field vector at the grid points due to multiple charges.
This is pretty straight forward. Each charge contributes to that electric field vector. I just sum up all these contributions:
Where:
- is the total electric field vector at that point
- is the electric field vector at that point due to charge
- is the number of charges
The Simulation
I wrote the simulation using a combination of Python
and JavasScript
. The math/simulation is done in Python
, and the visualization is done in JavaScript
using three.js
. Pyodide
is what allows me to run my Python
code client-side (in the browser). Pyodide
also allows my Python
code to call JavaScript
and vice versa. So as the user interacts with the simulation, JavaScript
event handlers call into my Python
code to update the simulation state.
And finally, here is a link to the simulation: Electric Field Simulator
And here are some cool gifs of it in action.
Charge gets sling-shotted:
Charge gets absolutely pwned by the electric field!
A stable orbit forms: