Skip to content

Interactive 3D/AR simulation of entropy increase in a closed system using React Three Fiber and Rapier physics.

Notifications You must be signed in to change notification settings

saskaZs/Entropy-Visualization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”΄πŸ”΅ ENTROPY – Interactive Entropy Simulation

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

πŸš€ Features

  • 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.

πŸ“‚ Project Structure

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


🧠 Theoretical Background

This simulation visualizes one of the most profound concepts in physics: the Second Law of Thermodynamics.

1. Macrostate vs. Microstate

  • 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.

2. Entropy Definition (Boltzmann)

$$ S = k \cdot \ln W $$

  • $k$: Boltzmann constant
  • $W$: number of microstates corresponding to the macrostate

Higher $W$ β†’ higher entropy. The system naturally evolves toward states with maximum $W$.

3. Shannon Entropy (Used in Simulation)

Since exact $W$ is computationally infeasible, we approximate using spatial Shannon entropy: $$H = - \sum_{i} p_i \log_2 p_i$$

  • Grid divides space into cells.
  • $p_i$: fraction of red (or blue) particles in cell $i$.
  • Averaged over all cells β†’ global entropy measure.

$H = 0$ when particles are perfectly separated (pure cells).
$H = 1$ (maximum) when perfectly mixed (50/50 in every cell).

4. Irreversibility

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.


πŸ“¦ Installation & Running

Prerequisites

  • Node.js (v16+ recommended)

Steps

cd code/entropy
npm install
npm run dev

About

Interactive 3D/AR simulation of entropy increase in a closed system using React Three Fiber and Rapier physics.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published