IT lexicon › Programming › Marching squares

Marching squares

Programming På svenska → Updated: 2026-10-24

The two-dimensional cousin of marching cubes: it traces contour lines through a grid of scalar values, one cell at a time, from sixteen corner cases.

Each cell has four corners that lie above or below a threshold, giving 2⁴ = 16 cases. A lookup table maps each case to one or two line segments, and linear interpolation along the cell's edges places the endpoints so the contour comes out smooth rather than stair-stepped.

The result is an isoline — the same idea as the contour lines on a topographic map or the isobars on a weather chart. In games and graphics it is used for 2D metaballs, for tracing the outline of destructible 2D terrain, and for vectorizing thresholded images. Step up to a full volume and it becomes marching cubes; keep sharp corners and you reach for dual contouring.

← Back to the lexicon