Mathematical Principles for Scientific Computing and Visualization
http : // www.farinhansford.com/books/scv
by Gerald Farin and Dianne Hansford

This notebook demonstrates 

Figures  14.3, 14.4, 14.5, and 14.7 were created with this notebook.

See Chapter 14 : Visualizing Scalar Values over 2D for details.

Updated May 2008

(* Set the output folder *)
(SetDirectory[ToFileName[Extract["FileName"/.NotebookInformation[EvaluationNotebook[]],{1},FrontEnd`FileName]]];) 


(* Create a variable to change the number of evaluations in the plots *)
(num=35;) 

(* Create a plot of the function sin(xy) over [-pi,pi] *)
(* We are creating 4 versions below -- different rendering techniques *)

(pic1=Plot3D[Sin[x y],{x,-π,π},{y,-π,π},PlotPoints->num,Ticks->{Automatic,Automatic,None},ViewPoint->{-0.033`,0.03`,3.381`},BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11}]) 

(pic2=Plot3D[Sin[x y],{x,-π,π},{y,-π,π},Mesh->False,PlotPoints->num,Ticks->{Automatic,Automatic,None},ViewPoint->{-0.033`,0.03`,3.381`},BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11}]) 

(pic3=Plot3D[Sin[x y],{x,-π,π},{y,-π,π},PlotPoints->num,Ticks->{Automatic,Automatic,None},ViewPoint->{-0.033`,0.03`,3.381`},BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11},ColorFunction->(White&)]) 

(pic4=Plot3D[Sin[x y],{x,-π,π},{y,-π,π},PlotStyle->FaceForm[],PlotPoints->num,ViewPoint->{-0.033`,0.03`,3.381`},Ticks->{Automatic,Automatic,None},BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11}]) 

(* Put the plots together *)
(g=GraphicsGrid[{{pic1,pic2},{pic3,pic4}}]) ;

(* Display the four plots *)
Show[g] 

(* Output to a postcript file *)
(* Uncomment this when wanted -- takes a long time to execute! *)
(* Export["meshes.eps",g]; *)

Now experiments with a plotting style that uses random points distributed over the function.

(* Define the number of points to create *)
(numpts=35 35;) 

(* Define a function to evaluate *)
(myf[x_,y_]:=Sin[x y];) 


(* Create xy points over the [-pi,pi] domain using the random number generator. *)(pntsx=Table[2 π (RandomReal[]-0.5`),{x,1,numpts}];) (pntsy=Table[2 π (RandomReal[]-0.5`),{y,1,numpts}];) 

(* Evaluate function at the xy values created *)(pntsz=Table[myf[pntsx[[i]],pntsy[[i]]],{i,1,numpts}];) 


(* Load the xyz values into a table for plotting *)(pts=Table[{pntsx[[i]],pntsy[[i]],myf[pntsx[[i]],pntsy[[i]]]},{i,1,numpts}];) 

(* Create a plot *)ListPointPlot3D[pts,PlotStyle->PointSize[0.01`],BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11}] 

(* Now create a plot *)

(numgrid=35;) 

(* Redefine the function above but so we get points on a regular grid *)
(myf2[x_,y_]:=Sin[(2 π ((x/numgrid)-0.5`)) (2 π ((y/numgrid)-0.5`))];) 


(* Total number of points we will generate *)(numtot=(numgrid+1) (numgrid+1)-1;) 

(xpts=Table[Mod[k,numgrid+1],{k,0,numtot}];) 
(ypts=Table[IntegerPart[(k/(numgrid+1))],{k,0,numtot}];) 

(pntsplot=Table[{2 π (((xpts[[i]])/numgrid)-0.5`),2 π (((ypts[[i]])/numgrid)-0.5`),myf2[xpts[[i]],ypts[[i]]]},{i,1,numtot}];) 

(splot=ListPointPlot3D[pntsplot,PlotStyle->PointSize[0.01`],Ticks->{Automatic,Automatic,None},BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11}]) 

(* Output pointcloud to postscript file *)
(* Export["pointcloud.eps",splot]; *) 

(* This is a VERY smooth plot -- with a lot evaluations *)
(picsmooth=Plot3D[Sin[x y],{x,-π,π},{y,-π,π},Mesh->False,PlotPoints->200,Ticks->{Automatic,Automatic,None},BaseStyle->{"FontFamily"->"Helvetica","FontSize"->11}]) 

(* Output to postscript file *)
(* Export["mesh_smooth.eps",picsmooth]; *)