views:

657

answers:

4

I am looking for a function or example to produce a list of lines representing contours at a specific height within a heightmap.

Eg,

Lines[] = GetContours(Heights[512,512], HeightValue)

Where Heights is a 512x512 array of floating point values, HeightValue is the height at which the contour should be drawn. Heights may contain multiple lines for that specific height (eg a Saddle, or island chain)

Does anyone have or know where to get an algorithm to generate this?

+2  A: 

What you're actually trying to do is to draw an iso-line.
see my question about it a while ago.
The link given in one of the answers was very helpful.

shoosh
A: 

The standard algorithm is marching squares.

marcog
+1  A: 

Algorithm:

a) Find which polygons have vertices above&below the height you're interested in.

b) Intersect the edges of those polygons with the plane to get lines on the plane.

c) Join the lines together in strips.

Jimmy J
+1  A: 

Take a look at Srtm2Osm, a tool I've made to generate contours from NASA's SRTM data. You can find the algorithm in the C# code.

Igor Brejc