Feed
Marching squares is primarily used to generate contours from a map (represented by a two-dimensional array). Marching cubes corresponds to the method of generating meshes in space. The most common application is the generation of atmospheric pressure maps in weather forecasts, and is often used for random terrain generation.
Marching Squares
First, the algorithm steps.
(1) The input is a scalar grid, which is a two-dimensional table.
This table can be generated from a two-dimensional image, from a height map, and so on. Each vertex corresponds to a scalar value.
(2) The next thing to do is to subtract the vertex value from a standard value σ and get a +/-grid. Here σ= 5, get the following table:
The point which is marked black is called the positive point, and there is no marked black called negative point.
(3) Next is the contour generation. The four vertices adjacent to the grid are a cell, and for each cell, there are 2^4 = 16 cases Depending on the vertex's positive and negative.
The 16 situation corresponds to the drawing of the contour line as well as 16. Here, midpoint is inserted on each side of each cell.
By connecting the midpoint of the cell, you can draw the outline.
Generating a contour line from the +/-grid generated by the second step results in the following
(4) Correction of contours by interpolation
The main correction here is to draw the contour lines more precisely by linear difference values. The contour line is now passing through the cell's midpoint, actually going through the position of σ, which can be obtained by the linear difference. The final results are as follows
The flow of the algorithm is summarized as follows
The pseudo code of the algorithm is as follows:
Ambiguity
For the 8th and 12th cell types, there are two ways to generate outlines, which can create randomness.
The same two distributions, two kinds of contours appear
However, these two situations do not say error, it still conforms to the profile characteristics.
Marching Cubes
Marching cubes is actually extending the algorithm to measurements space, and the cell becomes a cube. Compared to the Squar division of 16 methods, cube has 2^8 = 256 cases, but can be simplified to the following 22 cases, the other can be obtained by rotation.
This algorithm is often used to generate some medical images.
There is also a very interesting thing called Metaballs, which is also used in this algorithm.
Reference
Squares Made for marching-http://blog.project-retrograde.com/2013/05/marching-squares/
Marching Squares Wiki
Marching squares, partitioning space-http://catlikecoding.com/unity/tutorials/marching-squares/
Metaballs and Marching squares-http://jamie-wong.com/2014/08/19/metaballs-and-marching-squares/
The Marching Cube-http://users.polytech.unice.fr/~lingrand/marchingcubes/algo.html#msamb
Metaballs ii-http://www.paulsprojects.net/metaballs2/metaballs2.html
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Marching Squares & Marching cubes