Given a map with a set of points, with the observed values printed at each point, a human can easily draw contours between the points, after a little training. We can break it into the following discrete steps, although after you learn how to contour, you really don't have to think about it -- you just go to it and do it.
Two points can always be connected by a straight line. The values we are contouring are z-values, which could be any sort of numbers from observations of elevation, soil moisture, wind speed, etc. Whatever the z-vales are, they are just numbers. Each point will have a z value associated with it. We can draw a straight line between two points, say with values of 227 and 247, and assuming a contour interval of 10 units, we would mark a 230 and a 240 crossing point for two contour lines with these values.
Locating the precise path of the contour line between the points in this way is called linear interpolation. Linear for the layout of the number line, and interpolation for the location of the crossing point(s). We could use other mathematical techniques of interpolation, but linear interpolation between two points is the easiest and most common way.
We can look at three points at a time and do the same sort of work to locate the path of contour lines. First, observe that the data points on the map can be connected by lines making up a set of triangles:
We pick an area of the map to start, and it really doesn't matter where. Scanning the range of z values on the map, a contour interval of 50 for this data will give us four contours: 150, 200, 250, and 300. Arbitrarily, we select the following three points to start drawing contours:
We can use linear interpolation (marking off a number line) between the points to draw contours between three points, like so:
Closeup view of three selected points and the contours drawn using linear interpolation
These three points have number lines drawn between them for linear interpolation of contour line positions. To locate where contours pass between three points, locate specific crossings along the sides of the triangle, which have been marked off with number lines. After connecting the dots, we'll see straight contour lines that are parallel (A triangle is in a plane, so contours of it will be straight and parallel to one another). In the case of the selected three points above, there are two contours passing between the three points, a 250 and a 300 contour line. A contour does not pass between the bottom two points -- not at the contour interval we are using, which is 50.
Linearly interpolated contour lines drawn in this fashion, as if done by a robot or a computer, will appear unnatural (wrong) and a bit angular, but it is not totally wrong -- it just needs a little tweaking. The tweaking comes from effort to round the contours where they make angular bends, especially sharp ones:
Note how a little interpretation modifies the path of the contour lines to be slightly different than the positions dictated by linear interpolation alone. In several places the modified contours (purple) swing wide from those made by linear interpolation. This is ok. In fact, sometimes we take for granted how smart we humans are. A human can visualize a surface and the way the contours should (usually) smoothly bend around a feature, in this case a hill. There's one more important bit of interpretation needed on this map. Look at the top of the hill in the map above, and find the 345 point, the highest point on the map, as indicated by the raw z values of all the points. But, is that really the highest point on the map? Is that the exact top of the hill? Could the hill go up above 350? Looking at the spacing of the contours, which shows the rate of change of the slope, it appears that a 350 contour would fit nicely:
Removing the black contour lines from linear interpolation and the clutter, and a little smoothing of the contours, we have a finished map:
Now that we see the basic method of linear interpolation, followed by interpretation where needed, we can look at how computers handle the problem of mapping x,y,z data.