Compass and magnetic field lines — 2D field map

Switch to 3D
Controls
Live readouts
Numerical checks
What to try
  1. With the Earth field at 0, every needle points along the field line through it: red tips follow the field from N toward S.
  2. Drag the magnet around the grid and watch needles swing; the probe compass oscillates, then settles (damped).
  3. Turn on an Earth field of 50 uT and set the direction opposite to the magnet axis: a neutral point appears where the two fields cancel.
  4. Shrink the magnet to 2 cm and check the graph: the exact two-pole field approaches the pure dipole 1/r^3 law within a few magnet lengths.
  5. Move the probe along the axis versus along the equator: the axial field is twice the equatorial field at the same distance.
The science

A bar magnet is modelled with two equal and opposite magnetic poles ±q separated by its length L (the "Gilbert" picture). Each pole produces a Coulomb-like field and the fields superpose with the uniform Earth field BE.

B(r) = (μ0/4π) q (r − rpole) / |r − rpole|³,   q = m / L Far away: Baxis = (μ0/4π) 2m / r³,   Bequator = (μ0/4π) m / r³ Compass needle: I θ̈ = −μB sin(θ − θB) − γ θ̇,   T = 2π √(I / μB)

Field lines are traced by stepping along B/|B| with a second-order midpoint method. The four checks compare the exact two-pole axis field with the point-dipole formula, test the axis/equator ratio of 2, count how many lines starting on the N pole terminate on the S pole (all of them, since total pole strength is zero), and compare an integrated needle oscillation period with the small-angle formula.

Simplifications: the field is evaluated in the plane through the magnet axis; real magnets have internal field and finite thickness; needles are non-interacting; the Earth field is uniform and horizontal; the needle damping is fixed. Magnet moment values are typical, not specific to any product.