Making a surface of scattered 3-D data in Mathematica

Displaying 3-dimensional data on a computer monitor or on the printed page is challenging, since these are 2-dimensional media. However, it can be accomplished in a still picture if the data lends itself to being patched together in a kind of surface, rather than being a collection of isolated points.

This is particularly easy if the x-values and y-values of the data form a rectangular grid; in this case, many graphics packages make it easy to render such data into a surface map, where the z-values of the data are interpreted as elevation, so that the peaks and valleys of the surface map indicate high and low values of z. Other approaches to grid data include contour maps and density maps.

Surface Map

Contour Map

Density Map

When the 3-D data is not neatly arranged in a rectangular grid in its first two coordinates, the problem becomes more difficult. The worst case is when the data points are randomly scattered points in three dimensions; in this case it becomes necessary to create two images to be viewed in stereo, or a sequence of images to make an animation. On the other hand, even if x-y values don't lie on a rectangular grid, IDL and Mathematica make it possible to construct a surface map if the x and y values of the data make a reasonable covering of a convex region of the x-y plane, Both systems start by using performing a "Delauney triangulation" to subdivide the convex region into triangles. The triangulation, plus the x-y-z data, provide the necessary information to create a surface. Mathematica builds the surface out of triangular patches, while IDL uses interpolation to construct a rectangular (51x51) grid of data, which can then be handled in familiar ways. The user can change the default size and span of the created grid, including what to do about z-values at grid points outside the original region.

The following example shows how Mathematica can handle the data in a list of 101 triplets of numbers in file "xyzdata.txt" which correspond to the x-y-z values of 101 points.

Load the Standard package DiscreteMath`ComputationalGeometry`, then use the function TriangularSurfacePlot. It automatically performs the Delaunay triangulation, then uses it to produce a surface consisting of triangular patches.

    xyz = ReadList["xyzdata.txt", {Real,Real,Real}];

    Get["DiscreteMath`ComputationalGeometry`"]
    TriangularSurfacePlot[xyz, ViewPoint->{2,5,2}]
result:

An alternative approach, but one which must be used with caution, is to try to "fit" a simple function (e.g., polynomial) to match the data points, using Fit or NonlinearFit.