Polyhedral mark
Physics Engine
Simulation systems, interactive surfaces, and the Barnes-Hut scaling track
RK4 Barnes-Hut Simulation
Computational Physics Toolkit

From local rigid bodies to many-body gravity.

This project started as a rigid-body simulation sandbox for numerical integration, collisions, and interaction feel. It now includes a deeper Barnes-Hut track: scaling from pairwise O(N²) gravity toward tree-based O(N log N) approximation, a split-view exact-vs-tree compare lab, generated scaling figures, and new theta sweeps that make the speed-versus-error tradeoff concrete.

Engine Core

Rigid-Body + Integrators

Euler and RK4 integration, ground and circle collisions, and benchmarkable motion primitives in C++.

Interactive

Python Sandboxes

Preset-driven local simulation for rigid-body work plus a dedicated Barnes-Hut compare lab for exact-vs-approximate gravity.

Public Surface

2D + 3D Demos

Browser-facing demos that make the simulation work explorable without requiring a local setup.

Scaling

Barnes-Hut

A live workstream for many-body gravity, quadtree approximation, measured complexity gains, and theta-tradeoff benchmarking.

Barnes-Hut

Scaling and approximation, both visible

The current Barnes-Hut pass now has two benchmark stories: how the tree scales as particle count rises, and how theta changes the speed-versus-error tradeoff at a fixed field.

Particle-count scaling

The benchmark pipeline now writes structured JSON, text snapshots, and generated figures so the scaling curve can be shown instead of only described.

Barnes-Hut benchmark plot
Loop speedup now reaches 6.24x at N = 1600, while force error and tree size remain visible in the same benchmark pass.

Theta sweep

The new theta sweep makes the approximation itself tunable: smaller theta values stay closer to exact gravity, while larger ones win more aggressively on runtime.

Barnes-Hut theta sweep plot
At N = 960, loop speedup climbs from 2.01x at theta = 0.35 to 7.60x at theta = 1.00, with RMS error widening along the way.
Read It

What the current numbers say

Barnes-Hut is now doing two useful jobs in the repo: it shows a real crossover story as N grows, and it gives a visible approximation knob instead of hiding the tuning decision.

  • Scaling win At theta = 0.60, the current benchmark reaches 6.24x loop speedup by N = 1600, which is enough to make the tree visibly worthwhile.
  • Accuracy floor At N = 960, theta = 0.35 keeps RMS acceleration error down at 0.0225, but only reaches 2.01x loop speedup.
  • Fast-but-loose edge theta = 1.00 reaches 7.60x loop speedup at the same N, but pushes RMS acceleration error up to 0.5027.
  • Practical reading The local compare lab keeps that tradeoff legible: exact motion on one side, Barnes-Hut on the other, with divergence, drift, and tree stats underneath.
Current Surfaces

How the project is experienced today

The engine now lives across multiple surfaces depending on whether the goal is benchmarking, sandbox interaction, or quick public exploration.

C++

Numerical core

Fast iteration on motion, collisions, and integrator behavior with benchmark-oriented scripts and terminal-native runs.

Python

Realtime rigid-body sandbox

Pause/step inspection, energy history, scene presets, and local interaction for serious reading of the simulation state.

Python

Barnes-Hut compare lab

Side-by-side exact and Barnes-Hut evolution with quadtree overlay, divergence tracking, live theta tuning, and benchmark-minded HUD metrics.

Web

Public demo surfaces

2D and 3D browser demos that make the simulation work easy to explore from the portfolio without cloning anything.

Where It Goes

Next steps for the engine

The near-term goal is to take the compare lab and dual-benchmark pipeline one step further into browser-facing many-body visualization and broader particle-distribution testing.

Open The Work

Repository and demos

The main repo now holds the rigid-body engine, the Barnes-Hut compare lab, structured benchmark outputs, generated scaling and theta figures, and the browser-facing demo entry points.

Reach Out

Simulation, controls, or research

If this overlaps with physics research, simulation tooling, teaching, or algorithm-heavy work, email is the best place to start.