Magnetic Field Simulator Back
Electromagnetism · Magnetic Field

Magnetic Field Lines Simulator

Place current-carrying wires and bar magnets on the canvas to visualize magnetic fields in real time. Explore Ampere's Law, dipole fields, and the attraction/repulsion between parallel currents.

Placement Mode
Current magnitude
A
Display Options
Field line density
Presets
Mag
Move mouse to read field magnitude

Click to place sources — drag to reposition

Theory & Key Formulas

Theory

Infinite straight wire:

$$B = \frac{\mu_0 I}{2\pi r}$$

Magnetic dipole (far field):

$$B_r = \frac{\mu_0 m}{4\pi r^3}2\cos\theta, \quad B_\theta = \frac{\mu_0 m}{4\pi r^3}\sin\theta$$

What are Magnetic Field Lines?

🙋
What exactly are these curved lines I'm seeing around the wire in the simulator? They look like circles.
🎓
Basically, those are magnetic field lines. They're a visual tool that shows the direction and strength of the magnetic field. The field from a straight, current-carrying wire forms perfect concentric circles. Try moving the "Current Magnitude" slider above—you'll see the lines get denser, representing a stronger field.
🙋
Wait, really? So the field strength changes with distance? I see the lines are closer together near the wire.
🎓
Exactly right. The density of the lines is a key clue. In practice, the magnetic field gets weaker as you move away from the source. For instance, the field around a power line is strong right next to it but negligible a few meters away. The equation governing this is $B = \frac{\mu_0 I}{2\pi r}$.
🙋
What about the magnet option? Its field looks totally different—more like a dipole. Is that related?
🎓
Great observation! Yes, a bar magnet is a magnetic dipole. Its field lines emerge from the north pole and loop back to the south pole. A common case is a simple compass needle, which is itself a tiny dipole aligning with the Earth's field. The simulator shows how this complex 3D field can be described by two components, $B_r$ and $B_\theta$.

Physical Model & Key Equations

The magnetic field around an infinitely long, straight conductor is derived from Ampère's Law. The field strength is inversely proportional to the radial distance from the wire.

$$B = \frac{\mu_0 I}{2\pi r}$$

$B$ : Magnetic field magnitude (Teslas). $\mu_0$ : Permeability of free space ($4\pi \times 10^{-7}$ T·m/A). $I$ : Current in the wire (Amperes). $r$: Perpendicular distance from the wire (meters).

The field of a magnetic dipole (like a bar magnet) is more complex and depends on both distance and angle. It's often described using spherical coordinates.

$$B_r = \frac{\mu_0 m}{4\pi r^3}2\cos\theta, \quad B_\theta = \frac{\mu_0 m}{4\pi r^3}\sin\theta$$

$B_r$, $B_\theta$ : Radial and angular components of the magnetic field. $m$ : Magnetic dipole moment (A·m²). $\theta$ : Angle from the dipole's north-south axis. The field strength decays much faster with distance ($1/r^3$) compared to a straight wire.

Frequently Asked Questions

Drag and drop the 'Current Line' or 'Bar Magnet' icon from the tool palette on the left side of the screen, or click the icon and then click the desired position on the canvas. After placement, you can move them by dragging, and adjust rotation or length by dragging the handles at the ends.
Magnetic field lines are drawn from the N pole to the S pole. For current lines, the direction of the magnetic field follows the right-hand screw rule: the direction in which a right-handed screw turns when driven in the direction of the current. You can confirm this by the arrow directions in the simulator.
Place two current lines parallel to each other. If the currents flow in the same direction, an attractive force acts; if in opposite directions, a repulsive force acts. The magnitude of the force depends on the distance and current values, and can be confirmed via arrows or numerical displays on the screen. To change the current value, select the object and modify it in the properties panel.
This tool is designed for educational real-time visualization and differs from rigorous numerical calculations. The magnetic field is approximated on a 2D plane based on Ampère's law. Please note that it cannot reproduce complex 3D shapes, high-frequency phenomena, or nonlinear effects of magnetic materials.

Real-World Applications

Electric Motors & Generators: The interaction between magnetic fields from permanent magnets and current-carrying coils is the fundamental principle behind electric motors and generators. Engineers use these exact field calculations to design efficient and powerful devices.

Magnetic Resonance Imaging (MRI): MRI machines use incredibly strong and precisely shaped magnetic fields, generated by superconducting coils (essentially wires with massive current), to align hydrogen atoms in the body. The field uniformity is critical for clear imaging.

Particle Accelerators: To steer and focus beams of charged particles at near-light speeds, physicists use arrays of electromagnets. Calculating the exact magnetic field profile, like the dipole fields in this simulator, is essential for controlling the particle paths.

Fault Current Protection: Circuit breakers and protective relays often use the magnetic field generated by fault currents (sudden, high current) to trigger a disconnection. The force on a mechanism increases with $B$, which is proportional to $I$, allowing for fast, reliable protection of electrical grids.

Common Misconceptions and Points to Note

Let's go over a few points where people often stumble when starting with the simulator. First, the point that "magnetic field lines are not physical lines". The lines drawn on the screen are "guide lines" that visualize the direction and strength of the magnetic field. A line becoming thicker or the number of lines increasing solely represents a higher magnetic flux density. When you review CAE analysis results in practical work, remember the meaning of this visualization.

Next, the simulation's assumptions. This tool uses simplified models like "infinitely long straight currents" or "ideal bar magnets". For instance, an actual coil has a finite length, so the shape of the field lines near its ends will differ slightly from the simulator. Also, it's important to note that it ignores the influence of surrounding materials (permeability). If there is a current near iron, the magnetic field lines will concentrate and be drawn towards the iron. Be cautious when directly applying the fundamental principles learned with the tool to complex real-world machines.

Finally, a pitfall in parameter settings. Let's think about current values in realistic orders of magnitude. For example, the magnetic field created by a few amps from a household outlet is much smaller than the Earth's magnetic field. On the other hand, a large current of several thousand amps, like in a welding machine, generates enough force to make nearby iron tools move noticeably. Even when experimenting with the simulator, imagining "how much is this current value in reality?" will help sharpen your physical intuition.

What is Magnetic Field Lines Simulator?

Magnetic Field Lines Simulator is a fundamental topic in engineering and applied physics. This interactive simulator lets you explore the key behaviors and relationships by directly manipulating parameters and observing real-time results.

By combining numerical computation with visual feedback, the simulator bridges the gap between abstract theory and physical intuition — making it an effective learning tool for students and a rapid-verification tool for practicing engineers.

How to Use

  1. Set the current value (0–50 A) using currentSlider to adjust the magnetic field strength around the conductor
  2. Adjust densitySlider (1–100 field lines) to control visualization clarity; higher density reveals finer field structure near the wire
  3. Observe the concentric circular field patterns obeying Ampere's law: B = (μ₀·I)/(2π·r), where field strength decreases inversely with distance

Worked Example

For a copper wire carrying 35 A at 0.05 m distance, the magnetic field is B = (4π×10⁻⁷ × 35)/(2π × 0.05) = 140 µT. Set currentSliderNum to 35 and densitySliderNum to 75 field lines. The simulator renders tight concentric rings near the conductor, spreading outward logarithmically. At 0.1 m, field reduces to 70 µT, confirming inverse-distance scaling critical for transformer and motor design validation.

Practical Notes

  1. Increase density when analyzing skin effect in high-frequency AC (50–400 Hz industrial supplies) to see field concentration at conductor surface
  2. Compare results with Biot-Savart law for complex geometries; straight-wire Ampere approximation fails near wire ends—use density ≥60 for accuracy
  3. In PCB design, maintain trace separation ≥3× wire diameter to prevent cross-talk; visualize overlapping fields at 20+ A to identify coupling regions