This is the classic isoperimetric problem: among every closed curve of a fixed perimeter L, which one encloses the largest area? Calculus of variations answers it by treating the area A[γ] = ∮ as a functional of the curve γ and maximizing it subject to the constraint L[γ] = L₀ using a Lagrange multiplier λ:
maximize A[γ]
subject to L[γ] = L₀
Euler–Lagrange condition: κ(s) = λ for every arc-length s
A curve can only be a stationary point of this constrained functional if its curvature κ is constant everywhere — and the only simple closed curve with constant curvature is a circle, of curvature λ = 2π/L₀. That is the isoperimetric inequality: 4πA ≤ L², with equality only for the circle.
The simulation makes the optimization visible by numerically integrating the gradient flow that this Euler–Lagrange equation implies — each point of the curve moves along its outward normal N with velocity
∂X/∂t = (λ̄ − κ) N, λ̄ = 2π / L (target curvature)
which is exactly the first-variation direction that increases area fastest while leaving the total length unchanged to first order (a tiny uniform rescale each step removes the residual numerical drift so L stays pinned). Wherever the curve bulges out less than the target circle (κ > λ̄) it gets pulled in; wherever it is flatter than the target (κ < λ̄) it pushes out. The flow has no other rest state than κ = λ̄ everywhere, so any starting blob, star or square relaxes onto a circle and the isoperimetric ratio 4πA/L² climbs monotonically toward its ceiling of 1.
- Shape buttons — pick a different starting curve (all normalized to the same number of points).
- Vertices N — resolution of the discretized curve; more points track curvature more accurately.
- Flow speed — scales the time step of the gradient-flow integration.
- Pause / Reset — freeze the evolution, or regenerate the current shape preset to watch it converge again.
Real-world relevance: the same constrained-optimization logic — extremize a functional subject to a conservation law via a Lagrange multiplier — underlies soap-film minimal surfaces, geodesics, and the brachistochrone; it is the founding idea of the calculus of variations and, later, of optimal control theory.