Marching squares
Algorithm for generating contour lines on a 2D scalar field / From Wikipedia, the free encyclopedia
Dear Wikiwand AI, let's keep it short by simply answering these key questions:
Can you list the top facts and stats about marching squares?
Summarize this article for a 10 year old
SHOW ALL QUESTIONS
In computer graphics, marching squares is an algorithm that generates contours for a two-dimensional scalar field (rectangular array of individual numerical values). A similar method can be used to contour 2D triangle meshes.
This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. (February 2022) |
The contours can be of two kinds:
- Isolines – lines following a single data level, or isovalue.
- Isobands – filled areas between isolines.
Typical applications include the contour lines on topographic maps or the generation of isobars for weather maps.
Marching squares takes a similar approach to the 3D marching cubes algorithm:
- Process each cell in the grid independently.
- Calculate a cell index using comparisons of the contour level(s) with the data values at the cell corners.
- Use a pre-built lookup table, keyed on the cell index, to describe the output geometry for the cell.
- Apply linear interpolation along the boundaries of the cell to calculate the exact contour position.