November 27, 2026

Magnetic Field Lines Simulator: Bar Magnets, Iron Filings and a Compass

Iron filings forming magnetic field lines around a bar magnet on dark paper

Magnetic field lines are a drawing convention for the direction and strength of a magnetic field. The simulator below lets bar magnets be dragged and turned while it redraws both the field lines and a field of iron filings. It is built by the same owner as Marcellino NY, which carries a companion piece on Faraday’s filings experiments.

What a field line means

OpenStax says field lines are defined to point the way the north end of a small compass points, and that the strength of the field is proportional to how close the lines lie. The University of Texas adds that they never cross, never begin or end in space, and that a picture on a page shows a 2D slice of a 3D field.

Faraday introduced the idea, according to NASA, under the name “lines of force”. The compass in the app follows the same rule: its red end points along the local field.

Iron filings forming magnetic field lines around a bar magnet on dark paper

The model in the app

Each bar magnet is treated as two opposite point poles, one at each end. At every point the app adds up the contribution of each pole, B = Σ q r / (|r|² + ε)^(3/2), where q is +1 for a north pole and −1 for a south pole, r is the vector from that pole, and ε is a small softening term that keeps the field finite at a pole. This is a teaching model of a bar magnet’s field in the plane, not a full 3D calculation.

Field lines are traced by stepping along B in 4-pixel steps with a midpoint correction, starting at 7 pixels from each north pole at equal angles. A line stops when it reaches a south pole or leaves the frame.

Two bar magnets with iron filings bridging the gap on a dark workbench

Filings and lines, and what each shows

The filings are short dashes at jittered positions on a grid, each turned to point along B. A dash is longer and brighter where the field is stronger. The drawn lines carry the same number of lines per pole whatever the strength, so line density in the app does not measure field strength the way the rule from OpenStax describes. The brightness of the filings does.

The real field lines also continue through the magnet. JoVE states that each line forms a closed loop through the north pole, around to the south pole and back through the magnet, whereas the app stops each line at a south pole.

Laptop showing a dark simulation of golden magnetic field lines between two bar magnets

Experiments to try

  • Attract: two magnets with a north end facing a south end, which joins their lines into a single bundle.
  • Repel: two like poles facing each other, where the lines bend away and a null region appears between them.
  • Three and Four: arrangements of several magnets, where the lines form saddles with no field at the center.
  • Drag the compass across the board to read the local direction.

Faraday’s original experiments used paper coated with melted wax, laid over bar magnets and dusted with iron filings, according to the Royal Institution. The filings view in the app is a digital relative of that setup. Michigan State’s Faraday module notes that tapping the surface frees the filings from friction so they can respond to the field.

Wooden box of iron filings and a sieve beside a bar magnet on dark leather

Controls

  • Drag a magnet to move it, drag an end to turn it, double-click to flip.
  • Choose Both, Filings or Lines, and a preset arrangement.
  • Set the number of lines per pole from 6 to 32, add up to six magnets, and use Full screen.

Sources

496 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *