I have the code for this somewhere and will post it if I can find it, but the process is this.
Triangulate the 2D space. If the coordinates are regular, then this simply involves drawing each horizontal andeach vertical, and thenone diagonal for each point. This would be a notional triangulation, of course. The simplest approach is to create a triangle class and use a List(Of triangle objects. Your triangle class consists of three points each of whichhas an (X,Y) position and a value - the reading at that coordinate.
Then, for each countour line, process each triangle in the space. Sequence doesn't matter. The points of the trianglewill have values that are eitherall three above the contour value or all three below the contour value,or two sides of the triangle will cross the contour value (one end of a side above, other end below, for two of the three sides).These are the only three possibilities, providedyou fudge things slightly so that an exact match between the value at apoint of a triangle and the contour valueis treated as a small arbitrary mismatch (but be consistent in your arbitrariness).If the triangleis entirely above or entirely below the contour value, ignore it. For the remaining triangles, work out the proportionate distance along each of the two sides where the contour value crosses the side. Draw a line between these two points (there will always be two). This is a real line, not a notional one.
FloodFill the regions between the lines with colors representing the contour values.
|