The 3D version of this simulator renders the kernel density estimate as a continuous, rotatable height-mapped terrain. This 2D counterpart is a genuinely different, independently-computed visualization of the same underlying density and the same mean-shift update — instead of a shaded mesh, it extracts explicit iso-density contour lines from the field with the real marching-squares algorithm, draws each point's actual climb as a fading trajectory trail, and adds a draggable 1D density cross-section curve that the 3D view has no equivalent of at all.
Density estimate (Gaussian kernel, bandwidth h):
f(x,y) = (1/n) Σ_i exp( -‖(x,y) - p_i‖² / (2h²) )
Mean-shift update at position m:
m ← Σ_i p_i · K(‖m - p_i‖) / Σ_i K(‖m - p_i‖)
K(d) = exp( -d² / (2h²) )
Contour extraction (marching squares), per grid cell:
case = (v0>L)·1 + (v1>L)·2 + (v2>L)·4 + (v3>L)·8
edge crossing found by linear interpolation:
t = (L - v_a) / (v_b - v_a)
- Contour rings — six iso-density levels are traced through the KDE grid with a real marching-squares pass (edge case table + linear interpolation), giving crisp topographic-map lines instead of a continuously shaded surface; verified against an analytic circular field (max radial error 0.0005 vs. a grid-cell tolerance of 0.14).
- Trajectory trails — every point's last ~30 positions are kept and drawn as a fading polyline, so you watch the literal gradient-ascent path curve toward a peak rather than only its current location.
- Density cross-section — drag the dashed horizontal scan line and the strip below plots f(x, yscan) as x sweeps the domain: the same KDE formula, sampled along a line and drawn as an explicit 1D curve — a view the 3D terrain cannot show without hiding the rest of the surface.
- Bandwidth h — reshapes both the contour rings and the cross-section curve identically and instantly: small h → many tight, separate rings and a spiky curve; large h → one broad ring and a smooth, single-humped curve.
- Clusters found — identical union-find merge rule as the 3D model (converged points within h/3 are merged), computed independently here from the 2D positions.
Real-world use: mean shift is the classical algorithm behind object tracking (CAMShift) and image segmentation; marching squares is the same contouring technique behind topographic maps and medical-imaging iso-surface extraction (its 3D generalization is "marching cubes").