Magnetic Field Lines (2D)

Trace bar-magnet field lines (Gilbert two-pole model), watch compass needles align, or switch to a current-carrying wire and launch charged particles that curve under the Lorentz force.

Live readouts

Numerical checks

  • running...
The science

Bar magnet (Gilbert model). Outside the magnet the field is modelled as that of two magnetic "charges" of strength ±qm at the ends: B(r) = (μ0/4π) qm r̂ / r². The sliders set the field of one pole at 10 cm, Bp, so B = Bp (0.1 m / r)². A field line is a curve everywhere tangent to B; it is traced here with 4th-order Runge-Kutta steps along dx/ds = B/|B| starting on rings around each north pole and ending when it falls into a south pole.

Compass. A needle of magnetic moment m feels the torque τ = m × B, giving θ'' = −ωn² sin(θ−θB) − 2ζωnθ' with ωn² ∝ |B|. It oscillates and settles along the local field line; the Earth slider adds a uniform background field, which creates a neutral point (B = 0) where the magnet's field cancels it.

Wire and particles. A long straight wire carrying current I produces B = μ0I / (2πd) (into the page on one side, out on the other). A charge moves by m dv/dt = q v × B; speed is constant and the path is a circle of radius r = mv/(|q|B), which shrinks near the wire, so the path drifts sideways (a cycloid-like curve). Integration uses the Boris scheme, which conserves speed exactly. Electrons and positrons curve opposite ways. Real particle speeds of 106 m/s are shown in slow motion.

Honest simplifications. Real magnets are dipole-like with field also inside the material (the Gilbert point-pole picture is only valid outside); the view is a single plane through the axis; the wire is infinite and thin (field capped at 2 mm); no relativity, radiation or collisions. The numerical checks listed under the controls (Biot-Savart vs formula, dipole limit, Gauss's law for magnetism, gyroradius) run at page load.