Each bar magnet is modeled as a point magnetic dipole with moment vector m. The field it produces at displacement r from its center is the exact dipole formula (the same one that governs a compass needle or the Earth’s own field), evaluated here in the 2D plane containing m:
B(r) = k · [ 3(m·r̂)r̂ − m ] / |r|³
in polar form around one dipole:
B_r = 2k·m·cosθ / r³
B_θ = k·m·sinθ / r³
With several magnets the net field is the vector sum (superposition). Field lines are not drawn as decoration — each one starts on a small circle around a magnet and is traced step by step by walking in the direction of the local unit vector B/|B| (2nd-order midpoint integration), exactly like a compass needle would align at every point along the path. A line ends when it is recaptured within another pole’s core radius or leaves the frame.
- Line density — the “lines per pole” slider sets how many lines are seeded per magnet; by the Gauss’s-law convention used in every textbook diagram, more/denser lines through a region mean a stronger local field, so a stronger reference magnet visibly crowds more lines into the same space.
- Alignment — 0° makes all magnets point the same way (open, roughly parallel external field); 180° opposes neighboring magnets (closed loops crossing between poles), the classic attract/repel bar-magnet patterns.
- Color-by-strength — recolors every traced segment by the local |B| magnitude (red = strong, near a pole; blue = weak, far away) instead of by line age.