Re: surface plots from irregularly spaced data (scatter) points
- To: mathgroup at smc.vnet.net
- Subject: [mg4409] Re: surface plots from irregularly spaced data (scatter) points
- From: fschwab at polaris.cv.nrao.edu (Fred Schwab)
- Date: Fri, 19 Jul 1996 04:36:51 -0400
- Organization: National Radio Astronomy Observatory
- Sender: owner-wri-mathgroup at wolfram.com
Re: Surface plots from irregularly spaced data Here's a quick and dirty approach that I sometimes use, which is based on a brute-force implementation of Shepard's interpolation formula [1]. The suitability, with particular emphasis on graphics applications, of this and various other scattered-data interpolation methods is discussed in Reference [2]. I chose Shepard's method mainly on the basis of its simplicity and because it doesn't tend to go "wild" in sparsely sampled regions. In the code below, I've selected a weighting exponent alpha=4; see Reference [1] for illustrations of the effect of varying this parameter. ----------------------------------------------------------------------------- <<Graphics`Graphics3D` f[x_,y_]:=Sin[x y] plt0=Plot3D[f[x,y],{x,0,3},{y,0,3},PlotPoints->30] n=500 xys=Table[3{Random[],Random[]},{n}] data=Map[{#[[1]],#[[2]],f[#[[1]],#[[2]]]}&,xys] shepard[x_,y_,list_]:=Module[{l,m,alpha=4,w,eps=10.^-16}, m=Length[list]; w=Map[((x-#[[1]])^2+(y-#[[2]])^2+eps)^(-alpha/2)&,list]; Sum[list[[l,3]] w[[l]],{l,m}]/Sum[w[[l]],{l,m}]] fi=Compile[{x,y},Evaluate[shepard[x,y,data]]] plt1=Plot3D[fi[x,y],{x,0,3},{y,0,3},PlotPoints->30] plt2=ScatterPlot3D[data] plt3=Show[plt1,plt2] ----------------------------------------------------------------------------- Here, I first generate a plot of f(x,y)=sin(x y) over the rectangle 0<x<3, 0<y<3, as in the example on page 155 of the Mathematica book (2nd Ed.). Then I generate 500 data points randomly distributed over the same domain, sample f at these points, construct an interpolating function, fi, and call Plot3D to make a plot of this interpolant. Finally, with ScatterPlot3D I show the a scatter plot of the randomly generated data and then superimpose it upon the 3-D perspective plot of the interpolant. I must, of necessity, use "Compile" and "Evaluate" before calling a plotting function, otherwise this would run too slowly. Still, this brute-force method is too time-consuming for very large n (n>1000, say). Probably the best approach for large-scale applications would be to call, say, a Fortran- or C-coded mathlink application designed along the lines of the codes in References [4,5] - which are described in Reference [3] - in order to generate a regularly spaced table of data, and to follow that with a call to ListPlot3D. References: [1] W. J. Gordon and J. A. Wixom, ``Shepard's method of `metric interpolation' to bivariate and multivariate interpolation'', Mathematics of Computation, 32 (1978) 253-264. [2] R. Franke, ``Scattered data interpolation: tests of some methods'', Mathematics of Computation, 38 (1982) 181-200. [3] R. J. Renka, ``Multivariate interpolation of large sets of scattered data'', ACM Transactions on Mathematical Software, 14 (1988) 139-148. [4] ___________, ``Algorithm 660: QSHEP2D: Quadratic Shepard method for bivariate interpolation of scattered data'', ibid., 149-150. [5] ___________, ``Algorithm 661: QSHEP3D: Quadratic Shepard method for trivariate interpolation of scattered data'', ibid., 151-152. - Fred Schwab (fschwab at nrao.edu) National Radio Astronomy Observatory Charlottesville, VA ==== [MESSAGE SEPARATOR] ====