11.143 Sample ‘tube

Function tube draw tube with variable radius.

MGL code:

call 'prepare1d'
light on
new yc 50 'sin(pi*x)':new xc 50 'cos(pi*x)':new z 50 'x':divto y1 20
subplot 2 2 0 '':title 'Tube plot (default)':box:tube y 0.05
subplot 2 2 1 '':title 'variable radius':box:tube y y1
subplot 2 2 2 '':title '"\#" style':box:tube y 0.05 '#'
subplot 2 2 3:title '3d variant':rotate 50 60:box:tube xc yc z y2 'r'

C++ code:

void smgl_tube(mglGraph *gr)
{
	mglData y,y1,y2;	mgls_prepare1d(&y,&y1,&y2);	y1/=20;
	if(big!=3)	{	gr->SubPlot(2,2,0,"");	gr->Title("Tube plot (default)");	}
	gr->Light(true);	gr->Box();	gr->Tube(y,0.05);
	if(big==3)	return;
	gr->SubPlot(2,2,1,"");	gr->Title("variable radius");	gr->Box();	gr->Tube(y,y1);
	gr->SubPlot(2,2,2,"");	gr->Title("'\\#' style");	gr->Box();	gr->Tube(y,0.05,"#");
	mglData yc(50), xc(50), z(50);	z.Modify("2*x-1");
	yc.Modify("sin(pi*(2*x-1))");	xc.Modify("cos(pi*2*x-pi)");
	gr->SubPlot(2,2,3);	gr->Title("3d variant");	gr->Rotate(50,60);	gr->Box();	gr->Tube(xc,yc,z,y2,"r");
}
Sample tube