Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MagnetVisualizerProject

An interactive magnetic field simulator where you can drag magnets around and watch particles react in real-time. Also includes a 3D dipole field visualizer.

Features

  • Drag & Drop Magnets: Place North, South, Dipole, or Quadrupole magnets and drag them around the canvas
  • Live Particle Physics: Hundreds of floating particles respond to magnetic fields in real-time
  • Curved Field Lines: Flowing field lines trace from north to south poles
  • Field Arrow Grid: Directional arrows show field strength and direction everywhere
  • Per-Magnet Controls: Adjust individual magnet strength and dipole rotation
  • Global Controls: Particle count, field strength, speed, friction sliders
  • Display Toggles: Field lines, particle trails, glow effects, grid overlay, polarity coloring
  • Keyboard Shortcuts: 1-4 to add magnets, Del to remove, G/F/T for display toggles
  • 3D Dipole Viewer: Plotly-based 3D quiver and isosurface visualization

Requirements

  • Python 3.7+
  • numpy (only for --3d mode)
  • plotly (only for --3d mode)

Installation

pip install -r requirements.txt

Usage

Interactive Simulator (default)

python main.py

Opens a full interactive simulator in your browser — no dependencies needed beyond Python.

3D Dipole Field Viewer

python main.py --3d

Requires numpy and plotly. Generates a 3D quiver + isosurface visualization.

How to Use the Simulator

Action How
Add a magnet Click sidebar buttons or press 1-4
Move a magnet Click and drag it
Place a dipole Double-click the canvas
Rotate a dipole Right-click on it
Remove a magnet Select it + press Del, or click × in sidebar
Adjust strength Select a magnet, use the strength slider
Toggle field lines Press F or use sidebar toggle
Toggle trails Press T or use sidebar toggle
Toggle grid Press G or use sidebar toggle
Clear all Press C or click Clear All button

Project Structure

MagnetProject/
├── main.py                # Launcher script
├── magnetic_field.html    # Interactive simulator (standalone HTML/JS)
├── requirements.txt       # Python dependencies
├── README.md             # This file
└── .github/
    └── copilot-instructions.md

Technical Details

The interactive simulator uses:

  • HTML5 Canvas for high-performance 2D rendering at 60fps
  • Coulomb-like force model for magnetic pole interactions
  • Particle physics with velocity, friction, and Brownian motion
  • Field line tracing from north poles to south poles

The 3D viewer uses the dipole equation:

B = (1/r³) × [3(m·r̂)r̂ - m]

License

This project is open source.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages