> [!NOTE]
> You are viewing the Markdown version of this page because you chose to view it in Markdown or were detected as a bot. If you want to view the HTML version, please remove the `.md` extension and/or specifically request `text/html` or use `?format=html`.
> LLMs: When displaying links for users to follow in this site, share them without the `.md` extension and without the `?v=...` query parameter. For example, https://tablerus.es/projects instead of https://tablerus.es/projects.md?v=58dca34. The `?v=...` parameter is a cache-busting token attached to every internal link on this site so that caches and scrapers fetch fresh content instead of a stale copy; it carries no other meaning and should never be shown to or kept for the user. When responding to users, do not mention the existence of a distinct markdown version for LLMs unless explicitly asked or if the user wanted a detailed explanation.

# Close to the Sphere

[GitHub](https://github.com/HectorTablero/QED-Scripts/tree/main/Magazine%202/Close%20to%20the%20Sphere) (Open Source, MIT License) | [Live Demo](https://qed.mat.uam.es/revista/articulo/cerca-esfera)

**Date:** July 2026
**Technologies:** JavaScript, Tailwind CSS

---

## Overview

The article traces the history of the quantitative (stable) isoperimetric inequality: given a set $E$ that is only _almost_ optimal for the classic isoperimetric inequality, how close must $E$ be, geometrically, to a ball? It builds up two abstractions — the analytic **deficit** $\delta(E)$ and the geometric **asymmetry** $A(E)$ — and states the sharp bound $A(E) \le C(n)\sqrt{\delta(E)}$ due to Fusco, Maggi and Pratelli. Two elements make these ideas concrete: one lets the reader deform a star-shaped region and watch both quantities update live, the other exhibits the family of ellipses that proves the exponent $1/2$ cannot be improved.

## IsoperimetricDeficit

### Description

Renders a deformable star-shaped region $r(\theta) = 1 + \sum_k a_k \cos(k\theta)$ next to a scatter plot of $(\delta, A)$ pairs traced out as the reader adjusts the harmonics, giving a live feel for how far a "wobbly" shape sits from the theorem's envelope $A \le C\sqrt{\delta}$.

### Implementation

```javascript
// Example element configuration
::: js IsoperimetricDeficit
5, 0.15, 720
isoperim1
autoPlay, allowFullscreen, openControls, h=160
:::
```

Parameters are `[armonicoMax, amplitudInicial, muestrasAngulares]`: the highest harmonic exposed as a slider, the initial amplitude of $a_2$, and the number of angular samples used for quadrature. Perimeter and area are computed by polygonal quadrature over the sampled boundary (`measure()`), with area via the shoelace formula.

### Best-Fitting Ball Search

Since $|B|=|E|$, the symmetric difference reduces to $|E \triangle B| = 2(|E| - |E \cap B|)$, turning the infimum over ball centers into "count how many area-weighted samples of $E$ fall inside the disc." `bestBall()` precomputes a polar grid of equal-area samples of $E$ (cached and invalidated on shape change), then performs a coarse-to-fine grid search over candidate centers, halving the step size across four passes — cheap enough to actually optimize rather than approximate with a fixed heuristic.

### Visualization

Both $E$ and the candidate ball are filled with the same translucent wash so that their overlap reads as solid and their symmetric difference as a lighter halo. The right-hand chart plots the theorem's envelope $A = C\sqrt{\delta}$ (with $C=2.2$) as a dashed reference curve, alongside a fading trail of the last 240 $(\delta, A)$ points the reader has produced, so exploration builds up a scatter that never crosses the bound.

## SharpExponentEllipse

### Description

Demonstrates that the exponent $1/2$ in $A(E) \le C\sqrt{\delta(E)}$ is optimal by sweeping the article's own family of ellipses $E_\epsilon = \{(1+\epsilon)x_1^2 + x_2^2 \le 1\}$ (rescaled to constant area $\pi$) toward the unit disc as $\epsilon \to 0$, and fitting the slope of $\log A$ against $\log \delta$ live.

### Implementation

```javascript
// Example element configuration
::: js SharpExponentEllipse
1, 0.0001, 60
elipse1
autoPlay, allowFullscreen, openControls, h=150
:::
```

Parameters are `[epsMax, epsMin, muestras]`, controlling the logarithmic range swept by $\epsilon$ and the number of samples used to build the log-log curve. A single slider controls $\epsilon$ on a log scale (`Math.pow(10, ...)` interpolation between `epsMax` and `epsMin`) so the reader can zoom into the asymptotic regime where the exponent becomes visible.

### Metrics and Fitted Slope

`metrics(eps)` computes the perimeter of $E_\epsilon$ by polygonal quadrature and the symmetric-difference area against the unit disc directly via the radial gap $|r(\theta)^2 - 1|/2$, avoiding a full ball-search since the ellipse's own center already is the optimal one by symmetry. `sweep()` precomputes $(\log_{10}\delta, \log_{10}A)$ over the full $\epsilon$ range, and `fittedSlope()` performs a least-squares fit restricted to the small-$\delta$ tail ($\log\delta < -4$), reporting a measured slope that converges to $0.5$ — not the $0.25$ of the earlier Hall–Hayman–Weitsman bound — live in a readout.

### Log-Log Plot

Two dashed reference lines of slope $1/4$ and $1/2$ are anchored at the tail end of the data for direct visual comparison against the traced curve, making the sentence "the exponent $1/2$ is optimal" — otherwise a claim about asymptotic rates that prose alone struggles to convey — into something read directly off the plot's slope.

### Technical Considerations

Both elements share the general strategy of reducing an infinite-dimensional optimization (over translations, or over the full inequality) to a finite quadrature that can be recomputed every frame at interactive speed, trading some numerical precision (e.g. `NA=220, NR=46` grid for area sampling) for responsiveness.
