1.00
Sources and simplifications
  • The field is the simplest metaball sum, f = Σ r²/d², sampled at the grid corners. Its value at a source is capped so samples stay finite.
  • Inside means f ≥ iso. The terrain height is a monotone function of f, so the waterline on the terrain is exactly the true iso-contour. The ribbon on the water is what marching squares recovers from the samples alone.
  • The saddle cases (5 and 10) are resolved by the mean of the four corners (the centre bob). The asymptotic decider [3] uses the bilinear saddle value instead; it can disagree with the mean on rare cells.
  • Corners exactly at iso count as inside, the same in every cell, so neighbouring cells always agree on a shared edge and the segments join.
  • Contours that leave the grid stay open at the border. Every contour inside the grid closes.
  • Only the march is slowed down for reading: a real implementation does all 1,024 cells of the fine grid in well under a millisecond.

Sources:

Centre bob: the mean of the four corners, which decides saddle cases 5 and 10Terrain coloured by the field: warm is inside (f ≥ iso), cool is outsideGold ribbon on the water: the stitched marching-squares contourMarching squares turns samples of a scalar field into contour lines [1]. It is the 2D form of marching cubes [2]. Here the field is a sum of metaballs [4], one per brass knob, shown as terrain in a tank. The water level is the iso-value, so land above water is inside. A survey pin stands at every grid corner: these samples are all the algorithm sees. The gantry visits each cell in turn. Each of its four probes reads one corner, and the lamp lights if that corner is inside: one bit, TL = 8, TR = 4, BR = 2, BL = 1. The four bits form a case index from 0 to 15, which picks one of 16 stencils from the type case. Cases 5 and 10 are saddles, with two diagonal corners inside. Their stencil depends on the centre bob, the mean of the four corners: at or above iso, the inside corners join; below, they stay apart [3]. Along each crossed edge, the crossing goes where linear interpolation puts the iso-value, t = (iso − a)/(b − a). Turn interpolation off and every crossing falls at an edge midpoint, so the contour turns blocky. Neighbouring cells compute the same crossing on a shared edge, so the segments join. The plotter draws them on the sheet, and they are stitched end to end into contours. Every contour inside the grid closes. A coarse grid misses thin necks and small islands that the waterline still shows.