TRIGRID

Given data points defined by the parameters X, Y, and 
Z and a triangulation of the planar set of points deter-
mined by X and Y, the TRIGRID function returns a regular 
grid of interpolated Z values. Linear or smooth quintic 
polynomial interpolation may be selected. Extrapolation 
for grid points outside of the triangulation area is also 
an option. The resulting grid is a two-dimensional array 
of the same data type as Z, with user specified bounds and 
spacing. An input triangulation can be constructed using 
the procedure TRIANGULATE. Together the TRIANGULATE pro-
cedure and the TRIGRID function constitute IDL's solution 
to the problem of irregularly-gridded data.

Calling Sequence

        Result = TRIGRID(X, Y, Z, Triangles [, GS, B])
        
Arguments

    X, Y, Z
    
        Input arrays of X, Y, and Z coordinates of data 
        points. Integer, long, double-precision and float-
        ing-point values are allowed. In addition, Z can be 
        a complex array. All three arrays must have the same 
        number of elements.
        
    Triangles
    
        A longword array of the form output by TRIANGU-
        LATE. That is, Triangles has the dimensions (3, Num-
        ber-of-Triangles) and, for each i, Triangles(0,i), 
        Triangles(1,i), and Triangles(2,i) are the indices 
        of the vertices of the i-th triangle.
        
    GS
    
        If present, GS should be a two-element vector 
        [XS, YS], where XS is the horizontal spacing between 
        grid points and YS is the vertical spacing. The 
        default is based on the extents of X and Y. If the 
        grid starts at X value x0 and ends at x1,then the 
        horizontal spacing is
        
        (X1- X0)/50
        
        The default for YS is computed in the same way. 
        Since the default grid spacing divides each axis 
        into 50 intervals and produces 51 samples, TRIGRID 
        returns a grid with dimensions (51, 51).
        
    B
    
        If present, B should be a four-element vector 
        [x0, y0, x1, y1], where x0 and y0 are the lower X and 
        Y grid limits, and x1 and y1 are the upper limits. 
        The default for B is:
        
        [MIN(X), MIN(Y), MAX(X), MAX(Y)]
        
Keywords

    EXTRAPOLATE
    
        This keyword sets the quintic interpolation 
        mode. TRIGRID extrapolates to grid points outside 
        the triangulation if this keyword is assigned to the 
        array of boundary node indices returned by the 
        optional parameter B of the TRIANGULATE procedure. 
        The extrapolation is not smooth, but should give 
        acceptable results in most cases.
        
    MISSING
    
        The Z value to be used for grid points that lie 
        outside the triangles in Triangles. The default is 
        0.
        
    QUINTIC
    
        If QUINTIC is set, smooth interpolation is per-
        formed using Akima's quintic polynomials from "A 
        Method of Bivariate Interpolation and Smooth Surface 
        Fitting for Irregularly Distributed Data Points" in 
        ACM Transactions on Mathematical Software, 4, 148-
        159. The default method is linear interpolation.
        
        Derivatives are estimated by Renka's global 
        method in "A Triangle-Based C1 Interpolation Method" 
        in Rocky Mountain Journal of Mathematics, vol. 14, 
        no. 1, 1984.
        
        QUINTIC is not available for complex data val-
        ues. 
        
Example

The following example creates and displays a 50 point 
random normal distribution. The random points are then 
triangulated, with the triangulation displayed. Next, the 
interpolated surface is computed and displayed using lin-
ear and quintic interpolation. Finally, the smooth extrap-
olated surface is generated and shown.

x = RANDOMN(seed, 50)	Make 50 normal XY points.

y = RANDOMN(seed, 50)

z = EXP(-(x^2 + y^2))	Make the Gaussian.

PLOT, x, y, psym=1	Show points.

TRIANGULATE, x, y, tr, b	Obtain triangulation.

FOR i=0, N_ELEMENTS(tr)/3-1 DO BEGIN
Show the triangles.

  t = [tr(*,i), tr(0,i)]	Subscripts of vertices [0,1,2,0].

  PLOTS, x(t), y(t)	Connect triangles.

ENDFOR

SURFACE, TRIGRID(x, y, z, tr)	Show linear surface.

SURFACE, TRIGRID(x, y, z, tr, /QUINTIC)
Show smooth quintic surface.

SURFACE, TRIGRID(x, y, z, tr, EXTRA = b)
Show smooth extrapolated surface.

