I built a real MNA circuit solver from scratch, then wrapped it in Three.js

I built a real MNA circuit solver from scratch, then wrapped it in Three.js

Leader 1 2 9
calendar_today agoschedule2 min read
— Originally published at luvaai.in

The problem with "circuit simulators" on the web

Most browser-based circuit tools either fake it (animate current flow without real math) or wrap an existing SPICE engine. I wanted to actually implement the math myself — a Modified Nodal Analysis (MNA) solver, the same technique real SPICE tools use under the hood — and then give it a 3D interface instead of the usual flat 2D schematic.

The result is CircuitForge: place components on a 3D breadboard, wire them up, and get real computed node voltages and branch currents — not an animation.

The actual solver

MNA builds a matrix from Kirchhoff's Current Law at every node, plus extra equations for voltage sources, then solves it. Stripped down, the core loop looks roughly like this:

const g = 1 / resistance;
matrix[nodeA][nodeA] += g;
matrix[nodeB][nodeB] += g;
matrix[nodeA][nodeB] -= g;
matrix[nodeB][nodeA] -= g;

Solve Ax = z for the node voltage vector, and you get exact values — not an approximation. I validated it against hand-calculated results on a few real circuits (simple divider, diode network, a series-parallel KCL cross-check) before trusting it in production. Full writeup with the actual worked numbers is here: luvaai.in/learn/circuit-simulator-accuracy-validation.

Then the fun part: making it 3D

Three.js handles the scene, camera, and raycasting for placing/wiring components. The tricky bit wasn't rendering — it was making wire connections feel physical: snapping to component pins, detecting valid connection points, and keeping the 3D positions in sync with the underlying circuit graph the solver actually operates on. Two completely separate data models (3D scene graph vs. circuit netlist) that have to stay perfectly consistent.

What it can't do (yet)

Being upfront: this is DC operating-point analysis only right now — no transient simulation, no AC frequency sweeps. If you need to see a capacitor charge curve over time, this isn't there yet. It's on the roadmap, but I'd rather ship an honestly-scoped DC solver than fake a transient one.

Try it

Live at luvaai.in — no signup needed, just start placing components. If you've built anything with raycasting-based node/wire editors, or have thoughts on extending MNA to transient analysis, I'd love to hear it in the comments.

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

How I Built a React Portfolio in 7 Days That Landed ₹1.2L in Freelance Work

Dharanidharan - Feb 9

Cisco's Amy Chang: A Model's "Passport" Doesn't Tell You Where It Actually Came From

Tom Smithverified - Aug 27

I Wrote a Script to Fix Audible's Unreadable PDF Filenames

snapsynapseverified - Apr 20

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

5 Web Dev Pitfalls That Are Silently Killing Your Projects (With Real Fixes)

Dharanidharan - Mar 3
chevron_left
780 Points12 Badges
3Posts
2Comments
6Connections
Solo dev building CircuitForge (free 3D circuit simulator at luvaai.in). Wrestling with Three.js, React 19, and simulation math.

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!