Current is moving charge with a direction. That direction makes its magnetic field different from a scalar heat or potential field: at a point beside a wire, the field circulates around the wire instead of pointing straight away from it. A program needs a coordinate convention before it can draw or add such vectors. This lesson uses x right, y up, and z out of the screen. Positive current in a straight wire therefore points in +z, and the right-hand rule makes the field circulate counter-clockwise when viewed from +z.
Here, dℓ is a tiny vector in the direction of conventional current and R points from that source element to the probe. The cross product is the direction contract: swapping the operand order silently reverses every arrow. μ is the medium permeability; the simple lab uses vacuum permeability, approximately 1.25663706212 × 10⁻⁶ T·m/A. Its units are useful: the result is tesla after a length contribution, current, and inverse-square geometry are combined.
For one ideal infinitely long wire at the origin, the segment integral has a compact regression answer:
\[\lVert\mathbf B(r)\rVert=\frac{\mu_0\lvert I\rvert}{2\pi r},\qquad \mathbf B(x,y)=\frac{\mu_0 I}{2\pi(x^2+y^2)}(-y,x)\]The second form is especially convenient in code. At probe (r, 0), a positive current must give a positive y component; reversing the current must negate it. At twice the probe radius, the magnitude must halve. Those small tests expose coordinate and denominator mistakes before a finite-segment model introduces discretization error.
Loading the interactive visual. The lesson text and model remain available while it starts.
For a finite or curved wire, divide the path into short directed pieces and form a weighted vector sum. Halve the maximum segment length while keeping the same physical probe and report the difference between successive estimates. Do not compare a point that moves with the mesh, and do not treat a picture with more arrows as evidence of convergence. A useful output record contains the probe coordinate, field vector, field magnitude, segment count, smallest source-to-probe distance, and the estimated refinement change.
The singularity at a wire is not a JavaScript edge case. The ideal thin-wire model predicts an unbounded field at r = 0, where it has no physical cross-sectional information. Reject or explicitly regularize probes inside a named wire radius; never substitute zero and call that a physical field. A real conductor also has finite radius, current distribution, material response, and sometimes time-dependent electromagnetic fields.
Prediction: At the same probe, reversing an ideal straight-wire current reverses the field vector; doubling the probe radius halves its magnitude.
Start at(0.50 m, 0) with +4 A. Record the signed y component in microtesla. Reverse the current without moving the probe and predict the new vector. Reset the current, double the radius, and compare the magnitude ratio. Then write a segment-sum test that checks a finite straight wire approaches the analytic reference only for probes far from its ends.Treat current-generated magnetism as an oriented vector computation. Establish the straight-wire reference, then use directed segment sums with units, singularity policy, symmetry tests, and mesh-refinement evidence.
(r, 0), what component should a positive z-directed current produce?Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
\[\text{observable output} = f(\text{inputs},\,\text{state})\]For Fields Due to Currents, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Magnetism and Induction, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Treat Fields Due to Currents as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Approximate current-generated magnetic fields with oriented segments and convergence checks.