An educational 3D (and AR-capable) simulation demonstrating the irreversible increase of entropy in a closed system, inspired by the classic thought experiment of mixing two types of gas particles.
Red and blue particles bounce elastically inside a cubic box with no external forces. Over time, they mix irreversibly β entropy rises from near zero (ordered/separated state) to maximum (fully mixed).
The simulation calculates and displays Shannon entropy in real-time based on spatial distribution, making the Second Law of Thermodynamics visually intuitive.
entropy.mp4
- Realistic Physics: Elastic collisions between particles and walls (conservation of momentum and energy).
- Entropy Calculation: Space divided into 3D grid cells; Shannon entropy computed from red/blue ratios per cell.
- Real-Time HUD: Current entropy value displayed (desktop) or floating panel (AR).
- AR Support: View the simulation in augmented reality on supported devices.
- Adjustable Parameters: Particle count, speed, box size, grid resolution (configurable in code).
- No External Forces: Purely statistical mechanics β demonstrates spontaneous entropy increase.
eslint.config.js # ESLint configuration for code quality and React hooks
index.html # HTML entry point with meta, Launchar SDK script, and root div
package.json # Dependencies (R3F, Rapier, XR, stdlib gammaln) and scripts
package-lock.json # Locked dependency versions
main.jsx # React entry: renders with StrictMode
index.css # Global styles for layout and dark theme
App.jsx # Main app: XR store, Canvas setup, Physics, ParticleContainer, EntropyGrid, AR button
EntropyGrid.jsx # Grid visualization and entropy calculation (uses gammaln for ln!)
ParticleContainer.jsx # Particle spawning, RigidBody setup, position polling for entropy
This simulation visualizes one of the most profound concepts in physics: the Second Law of Thermodynamics.
- Initially, all red particles on one side, blue on the other β highly ordered macrostate.
- Many possible microstates (particle positions/velocities) correspond to separated state β low multiplicity.
- Fully mixed state has vastly more microstates β high multiplicity.
-
$k$ : Boltzmann constant -
$W$ : number of microstates corresponding to the macrostate
Higher
Since exact
- Grid divides space into cells.
-
$p_i$ : fraction of red (or blue) particles in cell$i$ . - Averaged over all cells β global entropy measure.
Even though individual collisions are time-reversible, the overwhelming statistical preference for high-entropy states makes return to ordered state practically impossible.
This is why "unmixing" gases spontaneously never happens β even though it's not forbidden by Newton's laws.
- Node.js (v16+ recommended)
cd code/entropy
npm install
npm run dev