Marching squares extracts a piecewise-linear contour from scalar values sampled at the four corners of each two-dimensional grid cell. It is the 2D form of marching cubes: each corner is classified by the sign of its signed distance function (SDF), producing one of 16 possible segment configurations. section 11.3.1 section 11.7
A practical contouring pass follows this pattern:
- Sample the scalar or SDF value at every grid-cell corner. section 11.3.1
- Use sign differences to select the segment arrangement for the cell. section 11.3.1
- Place each segment inside the cell by linearly interpolating along edges whose endpoint signs differ. section 11.3.1
- Refine the grid when the contour’s piecewise-linear approximation is too coarse; smaller cells improve appearance but increase representation size and computation. section 11.3.1 section 11.7
Approximating a circle
A circle SDF sampled on a grid yields segments wherever neighboring corner values have opposite signs. Linear interpolation moves each segment endpoint away from the cell borders toward the estimated zero crossing, producing a smoother contour than border-only segments. The same approach can reconstruct metaball contours and other implicit shapes. section 11.3.1
Figure 11.15 All 16 combinations of line segments. Note that the symmetrical configurations are included.
Inspecting all 16 cell configurations makes the sign-based lookup step concrete. section 11.3.1
