I have a 2D height map in the following format
06 36 39 42 43 55 ...
37 40 43 43 45 46 ...
40 43 44 45 46 48 ...
44 44 46 47 48 50 ...
41 44 45 47 48 48 ...
...
And I need to remap it into a grin based contour format (so it can further be mapped into sprites)
. . . . | . .
. . . . \ . .
. . . / / . .
. . . | . . .
. . . | . . .
. / - / . . .
Here .
meaning flat area, |
and -
straight cliffs, /
and \
cliff corners (each representing 2 different possibilities).
I have tried a standard marching squares approach, but found that sampling only 3 neighbours leads to quite a lot of problems, due to overloading the adjacent cases. (Note the extra out of place straight cliffs below)
. . . . | . \
. . . . \ \ .
. . . / / - .
. . . | - . .
. . . | . . .
. / - / . . .
What I would like, is some references to algorithms/approaches that help deal with this sort of thing. I know that contour walking with some sort of depth first search is an option but have not tried it out yet, and would prefer to leave that as a last resort. There is also the questions of representation of some features, for example whether to include cliff ridges that are 1 element thick or just ignore them. Another option is to pass through the generated contours and change them so they smoothly fit together, but this seems really hacky...
(height_map - threshold)
. – Telephone.
,-
,|
,/
and \ – Platoon