Coons

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

bern[n_,i_,t_]:=Binomial[n,i]*(1-t)^(n-i)*t^i;
surf[bb_,m_,n_,u_,v_]:=Sum[Sum[bb[[i+1,j+1]]*bern[m,i,u],{i,0,m}]*bern[n,j,v],{j,0,n}];

m=3;
n=7;
bb=Table[{i-m/2,j^1.3-n/2,0.1*i^2-.8Sin[i+j]},{i,0,m},{j,0,n}];

cc = Table[(1-i/m)*bb[[1,j+1]] + (i/m)*bb[[m+1,j+1]]+(1-j/n)*bb[[i+1,1]]+(j/n)*bb[[i+1,n+1]]-(1-i/m)(1-j/n)bb[[1,1]]-(1-i/m)*(j/n)*bb[[1,n+1]]-(i/m)*(1-j/n)*bb[[m+1,1]]-(i/m)*(j/n)*bb[[m+1,n+1]],{i,0,m},{j,0,n}];
ccu= Table[(1-i/m)*bb[[1,j+1]] + (i/m)*bb[[m+1,j+1]],{i,0,m},{j,0,n}];
ccv=Table[(1-j/n)*bb[[i+1,1]]+(j/n)*bb[[i+1,n+1]],{i,0,m},{j,0,n}]; 
ccbilin= Table[(1-i/m)(1-j/n)bb[[1,1]]+(1-i/m)*(j/n)*bb[[1,n+1]]+(i/m)*(1-j/n)*bb[[m+1,1]]+(i/m)*(j/n)*bb[[m+1,n+1]],{i,0,m},{j,0,n}];


midpoint=surf[cc,m,n,0.5,0.5]
(*Print[MatrixForm[cc] ]*)


ccsurfplot=ParametricPlot3D[surf[cc,m,n,u,v],{u,0,1},{v,0,1},Mesh->None,PlotStyle->{Opacity[0.8]}];
ccusurfplot=ParametricPlot3D[surf[ccu,m,n,u,v],{u,0,1},{v,0,1},Mesh->None,PlotStyle->{Opacity[0.8]}];
ccvsurfplot=ParametricPlot3D[surf[ccv,m,n,u,v],{u,0,1},{v,0,1},Mesh->None,PlotStyle->{Opacity[0.8]}];
ccbilinsurfplot=ParametricPlot3D[surf[ccbilin,m,n,u,v],{u,0,1},{v,0,1},Mesh->None,PlotStyle->{Opacity[0.8]}];
(*bbplot=Graphics3D[{PointSize[Large],Red,Map[Point,bb],Gray,Line[bb],Line[Transpose[bb]]}];*)
ccplot=Graphics3D[{Gray,Line[cc],Line[Transpose[cc]],PointSize[Large],Green,Map[Point,cc]}];
ccuplot=Graphics3D[{Gray,Line[ccu],Line[Transpose[ccu]],PointSize[Large],Green,Map[Point,ccu]}];
ccvplot=Graphics3D[{Gray,Line[ccv],Line[Transpose[ccv]],PointSize[Large],Green,Map[Point,ccv]}];
ccbilinplot=Graphics3D[{Gray,Line[ccbilin],Line[Transpose[ccbilin]],PointSize[Large],Green,Map[Point,ccbilin]}];

Show[{ccsurfplot,ccplot},Boxed->False,Axes->False,ViewPoint->midpoint+{-m/2,-n/2,2}]
Export["coons.jpg",%]
Show[{ccuplot,ccusurfplot},Boxed->False,Axes->False,ViewPoint->midpoint+{m/2,n/2,3}]
Export["coonsu.jpg",%]
Show[{ccvplot,ccvsurfplot},Boxed->False,Axes->False,ViewPoint->midpoint+{m/2,n/2,3}]
Export["coonsv.jpg",%]
Show[{ccbilinplot,ccbilinsurfplot},Boxed->False,Axes->False,ViewPoint->midpoint+{m/2,n/2,3}]
Export["coonsuv.jpg",%]