11.109 Sample ‘refill

Example of refill and gspline.

MGL code:

new x 10 '0.5+rnd':cumsum x 'x':norm x -1 1
copy y sin(pi*x)/1.5
subplot 2 2 0 '<_':title 'Refill sample'
box:axis:plot x y 'o ':fplot 'sin(pi*x)/1.5' 'B:'
new r 100:refill r x y:plot r 'r'

subplot 2 2 1 '<_':title 'Global spline'
box:axis:plot x y 'o ':fplot 'sin(pi*x)/1.5' 'B:'
new r 100:gspline r x y:plot r 'r'

new y 10 '0.5+rnd':cumsum y 'x':norm y -1 1
copy xx x:extend xx 10
copy yy y:extend yy 10:transpose yy
copy z sin(pi*xx*yy)/1.5
alpha on:light on
subplot 2 2 2:title '2d regular':rotate 40 60
box:axis:mesh xx yy z 'k'
new rr 100 100:refill rr x y z:surf rr

new xx 10 10 '(x+1)/2*cos(y*pi/2-1)':new yy 10 10 '(x+1)/2*sin(y*pi/2-1)'
copy z sin(pi*xx*yy)/1.5
subplot 2 2 3:title '2d non-regular':rotate 40 60
box:axis:plot xx yy z 'ko '
new rr 100 100:refill rr xx yy z:surf rr

C++ code:

void smgl_refill(mglGraph *gr)
{
	mglData x(10), y(10), r(100);
	x.Modify("0.5+rnd");	x.CumSum("x");	x.Norm(-1,1);
	y.Modify("sin(pi*v)/1.5",x);
	if(big!=3)	{	gr->SubPlot(2,2,0,"<_");	gr->Title("Refill sample");	}
	gr->Axis();	gr->Box();	gr->Plot(x,y,"o ");
	gr->Refill(r,x,y);	// or you can use r.Refill(x,y,-1,1);
	gr->Plot(r,"r");	gr->FPlot("sin(pi*x)/1.5","B:");
	if(big==3)	return;
	gr->SubPlot(2,2,1,"<_");	gr->Title("Global spline");
	gr->Axis();	gr->Box();	gr->Plot(x,y,"o ");
	r.RefillGS(x,y,-1,1);	gr->Plot(r,"r");
	gr->FPlot("sin(pi*x)/1.5","B:");

	gr->Alpha(true);	gr->Light(true);
	mglData z(10,10), xx(10,10), yy(10,10), rr(100,100);
	y.Modify("0.5+rnd");	y.CumSum("x");	y.Norm(-1,1);
	for(int i=0;i<10;i++)	for(int j=0;j<10;j++)
		z.a[i+10*j] = sin(M_PI*x.a[i]*y.a[j])/1.5;
	gr->SubPlot(2,2,2);	gr->Title("2d regular");	gr->Rotate(40,60);
	gr->Axis();	gr->Box();	gr->Mesh(x,y,z,"k");
	gr->Refill(rr,x,y,z);	gr->Surf(rr);

	gr->Fill(xx,"(x+1)/2*cos(y*pi/2-1)");
	gr->Fill(yy,"(x+1)/2*sin(y*pi/2-1)");
	for(int i=0;i<10*10;i++)
		z.a[i] = sin(M_PI*xx.a[i]*yy.a[i])/1.5;
	gr->SubPlot(2,2,3);	gr->Title("2d non-regular");	gr->Rotate(40,60);
	gr->Axis();	gr->Box();	gr->Plot(xx,yy,z,"ko ");
	gr->Refill(rr,xx,yy,z);	gr->Surf(rr);
}
Sample refill