Visualizing Electric Equipotentials

Hey all, not a question this time, but rather I just wanted to share something I whipped up a little bit ago for my class on introductory electromagnetism.

Basically, it’s a drop-in way to visualize the contour lines of electric potential i.e. equipotentials given a configuration of point-charges. For example,

include("../src/IntroElectromagnetism.jl")
using .IntroElectromagnetism

# initialize the system of objects
particleTuple = (
    Particle(charge = 2, position = 1 * [cos(0 * 2pi/3), sin(0 * 2pi/3)]),
    Particle(charge = 2, position = 1 * [cos(1 * 2pi/3), sin(1 * 2pi/3)]),
    Particle(charge = 2, position = 1 * [cos(2 * 2pi/3), sin(2 * 2pi/3)]),
    Particle(charge = -1,position = [0, 0]),
    Particle(charge = 10, position = [2,0])
)
drawEquipotentials(particleTuple)

produces

Plot Bounds: The x and y plot bounds are automatically decided based on the minimums and maximums of the positions of the charges, while the bounds on the contours are the extrema from sampling the potential field on a 3x3 grid over the bounding box.

Object Glyphs: Currently, positive charges are red, and negative charges are blue. Changing this to something more color-blind friendly and accessible is on the TODO list e.g. square glyphs for positive and circle glyphs for negative. The size of the glyph for each charge represents how much charge that object has i.e. “bigger dot” = “more charge”

Saving Plot: Finally, to make the plotting consistent (e.g. inside VSCode REPL vs standard terminal call), the figures are saved to .png files with a name interactively requested from the user.

All in all, I just really love making visualizations cause they can make some really cool pictures. Future work on this project is to add support for moving charges and animate the simulation of the system. Let me know what you think and if you want to help make it better, I encourage submitting a pull request!


This project is part of a larger repo dedicated to producing open-access teaching materials for introductory electromagnetism; feel free to explore those other materials including a midterm (made in Typst!).

10 Likes