Separation 0 cm Force on B 0 mN Torque 0 mN·m U 0 mJ Dipole model OK FPS 0
Red end = north pole, silver end = south pole. Drag magnet B across the table with a mouse or finger (it is free to turn); drag anywhere else to orbit, wheel or pinch to zoom. Filings and compass needles follow the combined field of both magnets and the Earth.
Two Bar Magnets: Dipole-Dipole Force, Torque, Compass Grid and Iron Filings
Push, pull and twist a magnet with another magnet, and see the field it makes with filings and a grid of compasses. Every force and torque comes from the point-dipole formulas.
Pause Reset Filings: on Compasses: on Magnet A: pinned Magnet B angle: free Quality: High
View: from above View: perspective
Magnets and table
Magnet A (pinned unless released)
Magnet B (free)
Live readout
Force between the magnets vs separation
Solid lines: the dipole law for the two arrangements (slope -4 on this log-log plot). Dot: the live state of the magnets on the table.
Energy history
Experiment: the force law
Measured by evaluating the simulator's own force routine on two arrangements at five separations, then fitting a straight line on log-log axes. Prediction: slope -4; coaxial force is exactly twice the side-by-side force.
Run force-law sweep
Independent numerical checks
Controls Presets place the magnets in a classic arrangement and release magnet B. A free magnet B turns over when it is in an unstable arrangement (for example north facing north); lock its angle to see the pure push and unlock to watch it flip. Drag magnet B (it follows your finger or mouse through a soft spring). Release to see it snap, slide and turn. The sliders change magnet strength, the Earth's field, table friction and the angle of magnet A. Magnet B's angle slider sets it directly.
The science
Point dipole. A magnet is described by its moment m = Br V / μ0 (Br remanence, V volume; a 4 x 1.6 x 0.8 cm neodymium block with Br about 1.3 T has m of roughly 5 A·m²; the remanence is a typical value for such magnets). Its field is B(r) = (μ0 /4π) [3(m·r̂)r̂ − m] / r³.
Force and torque. On a second dipole m2 at displacement r from m1 : F = (3μ0 /4πr⁴) [ (m1 ·r̂)m2 + (m2 ·r̂)m1 + (m1 ·m2 )r̂ − 5(m1 ·r̂)(m2 ·r̂)r̂ ] and τ = m2 × B. Energy is U = −m2 ·B. Two checks follow: coaxial moments give F = 3μ0 m1 m2 / (2πr⁴) (attractive when facing opposite poles) and parallel moments side by side give half that, repulsive. The force falls as 1/r⁴, the torque only as 1/r³, which is why magnets turn to align before they slide together.
Compass needle. A needle of moment mn and inertia I in field B oscillates with period T = 2π √(I / (mn B)) for small angles; here it is damped and follows the total field of both magnets plus the Earth (default 50 µT, typical mid-latitude magnitude, horizontal component only is drawn).
Motion. Magnet B has mass 38 g and a rigid-body angular inertia about the vertical axis; sliding friction is Coulomb plus a small viscous term, spin friction is viscous. Integrated by semi-implicit Euler with sub-steps of 0.7 ms or smaller. Contact between the two bars is a rigid-rectangle push-out with a small restitution.
Simplifications. A real bar magnet is not a point dipole: inside about two magnet lengths the point formula is wrong by tens of percent (the HUD warns when the centres are that close), the force is capped at 50 N and magnetisation is assumed rigid (no induced magnetisation, no hysteresis, no iron in the table). Filings are drawn as small rods that point along the local field direction; real filings also clump along field lines. The field is evaluated in the table plane only.
Educational model; strong neodymium magnets can pinch fingers and wipe cards, handle real ones with care.