🔴 Spanning cluster found! p ≥ pc

About this simulation

This simulation runs site percolation on a 2D square lattice: every cell in an N×N grid is independently marked "open" with probability p, and a Union-Find (disjoint-set) structure with path halving and union by rank links each open cell to its open neighbours in near-constant time. Two virtual nodes are wired to the top and bottom rows, so the code can instantly test whether the top and bottom are connected — the definition of a spanning cluster. The default p = 0.593 sits right at the known critical threshold p_c ≈ 0.5927 for this lattice, where a spanning cluster first appears with high probability. Clusters are colour-coded by their Union-Find root, and a live histogram tracks the distribution of cluster sizes.

🔬 What it shows

An N×N grid (default 60×60) where each cell opens independently with probability p. Open cells are merged into clusters via Union-Find, coloured by cluster root, and the spanning cluster — one that bridges the top row to the bottom row through the virtual-node trick — is highlighted in red with an on-screen alert. The mini histogram shows how cluster sizes are distributed for the current p.

🎮 How to use

Drag the Grid size (N) slider (20–120) to change lattice resolution, and the Open probability (p) slider (0–1, default 0.593) to move through the phase transition. Watch the Clusters and Largest cluster readouts, and the red "spanning cluster found" badge that appears once p crosses the critical value. Use Reset to redraw a fresh random grid at the current p, or Sweep to auto-animate p from 0 to 1 and back, watching the transition happen live.

💡 Did you know?

The 2D critical exponents — fractal dimension D = 91/48 ≈ 1.896, cluster-size exponent τ = 187/91 ≈ 2.055, and correlation-length exponent ν = 4/3 — were proven rigorously by Stanislav Smirnov using conformal invariance and Schramm–Loewner Evolution, work that contributed to his 2010 Fields Medal. These exponents are universal: they are the same for square, triangular, or honeycomb lattices.

Frequently asked questions

What lattice and percolation type does this simulation use?

It implements site percolation on a 2D square lattice. Each of the N×N grid cells is independently opened with probability p (rather than bond percolation, where edges rather than cells are randomly opened), and connectivity between open neighbouring cells is tracked with a Union-Find structure.

What is the critical threshold p_c used here, and why 0.593?

The p slider defaults to 0.593 because that is the numerically established critical threshold p_c ≈ 0.5927 for site percolation on an infinite 2D square lattice. Below p_c, clusters stay finite as the grid grows; at and above p_c a giant spanning cluster connecting top to bottom appears with probability approaching 1.

How does the code detect a spanning cluster?

The simulation adds two virtual nodes to the Union-Find structure: every open cell in the top row is unioned with a virtual "top" node, and every open cell in the bottom row is unioned with a virtual "bottom" node. After building all the grid connections, it simply checks whether the virtual top and virtual bottom nodes share the same root — if so, a spanning cluster exists, and it is highlighted in red.

Why is Union-Find used instead of flood-fill?

Union-Find (disjoint-set) with path halving and union by rank runs each find/union operation in near-constant amortised time, which scales much better than repeated flood-fill searches when clusters need to be merged incrementally as the grid is built. This makes it practical to rebuild large N×N grids instantly whenever N or p changes.

What do the fractal dimension and cluster-size exponent mean?

Exactly at p = p_c, the spanning cluster is a fractal with Hausdorff dimension D = 91/48 ≈ 1.896 — its "mass" scales as radius^D rather than radius^2. The cluster-size distribution follows a power law n(s) ~ s^(-τ) with τ = 187/91 ≈ 2.055, visible as a straight line on a log-log histogram. Both exponents are universal across all 2D lattice types.