The Biot–Savart Law — Magnetic Field of a Current-Carrying Wire
Every magnet you have ever held owes its field to moving charge. The Biot–Savart law is the magnetostatic counterpart of Coulomb's law: instead of a static charge producing an electric field, a current element produces a magnetic field that circles around the direction of flow. Integrate it along a wire of any shape and you can compute the field anywhere in space — exactly what a physics engine needs to animate compasses, solenoids, and current loops.
1. The Biot–Savart Law
Consider a wire carrying current I. A tiny element of the wire, of length dl and direction along the current, contributes a magnetic field dB at a field point located a displacement r away:
dB = (μ₀ / 4π) · I · (dl × r̂) / r²
where μ₀ = 4π × 10⁻⁷ T·m/A — the permeability of free space
r̂ = unit vector from the current element to the field point
The cross product means the field is always perpendicular to both the current direction and the line to the field point — magnetic field lines circle around a wire, they never point radially toward or away from it, unlike an electric field around a charge. The total field at any point is the vector sum (integral) of dB over the entire current path.
Right-Hand Rule
Point the thumb along the current; the curled fingers show the direction the field circles the wire.
1/r² Falloff, Locally
Each element's contribution falls as 1/r², exactly like Coulomb's law, but the vector direction rotates with r̂ along the wire.
Linear Superposition
Magnetostatics is linear: the field of a bent or braided wire is simply the sum of the fields of its straight segments.
Steady Currents Only
The law assumes magnetostatics — the current is constant in time. Fast transients require the retarded, time-dependent form.
2. Field of an Infinite Straight Wire
Integrating the Biot–Savart law along an infinite straight wire at perpendicular distance a from the field point gives one of the most useful results in electromagnetism:
B(a) = μ₀ I / (2π a)
Direction: circles the wire, right-hand rule
The field falls off as 1/a, not 1/a² — because the "source" is an entire infinite line, not a point. Doubling your distance from a long straight wire halves the field, not quarters it. This 1/a scaling is exactly what Ampère's law predicts from symmetry, and it is a useful sanity check for any Biot–Savart numerical integrator: feed it a long straight segment and confirm the field matches μ₀I/(2πa) away from the ends.
3. Field of a Finite Wire Segment
Real simulations use finite segments, not infinite wires. For a straight segment seen from perpendicular distance a, with the two ends subtending angles θ₁ and θ₂ from the perpendicular foot, the closed-form result is:
B(a) = (μ₀ I / 4π a) · (sin θ₂ − sin θ₁)
θ measured from the perpendicular to each end of the segment
As the segment's ends go to ±∞, sin θ → ±1 and this reduces exactly to the infinite-wire result μ₀I/(2πa) from Section 2 — a good way to verify the formula. This closed-form expression is fast enough to evaluate per-segment in real time, which is why polygon-approximated wire loops in a simulation use it instead of brute-force numerical quadrature per segment.
4. Field on the Axis of a Circular Current Loop
For a circular loop of radius R carrying current I, the field on the axis at distance z from the loop's center is:
B(z) = μ₀ I R² / [2 (R² + z²)^(3/2)]
At the center (z = 0): B(0) = μ₀ I / (2R)
Far away (z ≫ R): B(z) ≈ μ₀ I R² / (2z³) — a magnetic dipole field
This is the building block for solenoids: stack N loops per unit length and integrate along the solenoid's axis to derive the familiar B = μ₀nI formula for the field deep inside a long solenoid, where n = N/length. It is also the field profile behind every "magnetic field" simulation that lets you drag a current loop and watch the field lines bulge outward on either face.
5. Superposition: Arbitrary Wire Shapes
Because the Biot–Savart law is linear in current, the field of any wire shape — a coil, a braid, a helix, a lightning-bolt fractal — is just the vector sum of the fields from each small straight segment approximating the curve:
B(P) = Σᵢ (μ₀ Iᵢ / 4π aᵢ) · (sin θ₂ᵢ − sin θ₁ᵢ) · n̂ᵢ
Sum over every discretised segment i, using the finite-segment formula
This is precisely how a "magnetic field of a wire" simulation is built: the user-drawn or procedurally generated path is broken into N straight segments, and the field at every point on a visualisation grid is the sum of N finite-segment contributions — an O(N) cost per grid point, or O(N·M) for an M-point grid.
6. Numerical Implementation in JavaScript
A general-purpose Biot–Savart solver represents the wire as a polyline (array of 3D points) and sums the finite-segment contribution for each edge:
function segmentField(p1, p2, current, fieldPoint, mu0 = 4 * Math.PI * 1e-7) {
// Vector along the segment
const dl = { x: p2.x - p1.x, y: p2.y - p1.y, z: p2.z - p1.z };
const segLen = Math.hypot(dl.x, dl.y, dl.z);
const dir = { x: dl.x / segLen, y: dl.y / segLen, z: dl.z / segLen };
// Perpendicular distance a, and angles theta1/theta2 from the foot of the perpendicular
const toP1 = { x: fieldPoint.x - p1.x, y: fieldPoint.y - p1.y, z: fieldPoint.z - p1.z };
const along = toP1.x * dir.x + toP1.y * dir.y + toP1.z * dir.z;
const perp = {
x: toP1.x - along * dir.x,
y: toP1.y - along * dir.y,
z: toP1.z - along * dir.z
};
const a = Math.max(Math.hypot(perp.x, perp.y, perp.z), 1e-6); // avoid singularity on the wire
const theta1 = Math.atan2(-along, a);
const theta2 = Math.atan2(segLen - along, a);
// Finite-segment closed form: B = (mu0 I / 4 pi a) (sin theta2 - sin theta1)
const mag = (mu0 * current / (4 * Math.PI * a)) * (Math.sin(theta2) - Math.sin(theta1));
// Direction: dir x perpUnit gives the azimuthal (circling) direction
const perpUnit = { x: perp.x / a, y: perp.y / a, z: perp.z / a };
const circ = {
x: dir.y * perpUnit.z - dir.z * perpUnit.y,
y: dir.z * perpUnit.x - dir.x * perpUnit.z,
z: dir.x * perpUnit.y - dir.y * perpUnit.x
};
return { x: mag * circ.x, y: mag * circ.y, z: mag * circ.z };
}
function wireFieldAt(polyline, current, fieldPoint) {
let total = { x: 0, y: 0, z: 0 };
for (let i = 0; i < polyline.length - 1; i++) {
const b = segmentField(polyline[i], polyline[i + 1], current, fieldPoint);
total.x += b.x; total.y += b.y; total.z += b.z;
}
return total;
}
7. Biot–Savart vs. Ampère's Law
| Property | Biot–Savart Law | Ampère's Law |
|---|---|---|
| Form | Direct integral over the source | Line integral of B around a closed loop |
| Best for | Arbitrary wire shapes, numerical field maps | Highly symmetric geometries (infinite wire, solenoid, toroid) |
| Computation | O(N segments) per field point | Algebraic, once symmetry is identified |
| Equivalence | Both derive from the same Maxwell equation (∇×B = μ₀J); each is more convenient in different situations | |
In a simulation, Biot–Savart is the workhorse because it needs no symmetry assumption — it works equally well for a straight wire, a solenoid, or a hand-drawn squiggle. Ampère's law is reserved for validating the numerical result against the handful of geometries where a closed-form answer exists.
8. Applications
Electromagnets & Solenoids
Stacking current loops (Section 4) gives the uniform interior field used in MRI magnets, relays, and speaker voice coils.
Motors & Actuators
The Biot–Savart field from stator windings combines with the Lorentz force law to produce torque in every electric motor.
Magnetic Field Mapping
Geophysical and biomedical instruments reconstruct current distributions from measured external fields — the inverse Biot–Savart problem.
Plasma & Fusion Devices
Tokamak and stellarator coil design relies on Biot–Savart field maps to shape the confining magnetic bottle.