How To Draw Contour Lines

Christoph Karl Walter Grein

Drawing contour lines is quite straight-forward. Starting point is a sample of the function values over a grid (xi, yj).

For a given function value f0, we determine for each grid point, whether f(xi,yj) is greater or smaller than f0. Linear interpolation along x and y then establishes the points of the contour line. These may be connected by straight lines or by a smoothing curve.

How these points have to be connected is obvious except for one special case. Imagine we have a grid square where all four points alternate around f0. Then we have three possibilities to connect the points: We can have a valley between two peaks, a ridge separating two valleys, or a saddle point. There is nothing that can tell which should be selected but a sample over a finer grid. So we might decide to choose at random.

We must be careful not to connect points as shown in the image on the left which is mathematically impossible or else we get (wrong) contour lines like the one shown in the first picture on the right rather than one of the other three (correct ones).

Choosing at random one of the (correct) connections has however dangers of its own. If we are not careful to remember for each square how we connected the points for value f0 when we plot the line for another value f1, we easily arrive at a situation as shown here.

Thus for simplicity, we choose the kind of connection from a fixed table. This table is defined in package body Landscape.Isohypse.Construct.Neighbourhood, and you may redefine the entries if you want to experiment a bit. In its current state, the table favours the non-saddle-point solution. The results of different choices are shown in the image on the left.


Back to Landscape.


Last update: 18 June 1999