11.49 Sample ‘dots

Function dots is another way to draw irregular points. Dots use color scheme for coloring (see Color scheme).

MGL code:

new t 2000 'pi*(rnd-0.5)':new f 2000 '2*pi*rnd'
copy x 0.9*cos(t)*cos(f):copy y 0.9*cos(t)*sin(f):copy z 0.6*sin(t):copy c cos(2*t)
subplot 2 2 0:title 'Dots sample':rotate 50 60
box:dots x y z
alpha on
subplot 2 2 1:title 'add transparency':rotate 50 60
box:dots x y z c
subplot 2 2 2:title 'add colorings':rotate 50 60
box:dots x y z x c
subplot 2 2 3:title 'Only coloring':rotate 50 60
box:tens x y z x ' .'

C++ code:

void smgl_dots(mglGraph *gr)
{
	int i, n=1000;
	mglData x(n),y(n),z(n),c(n);
	for(i=0;i<n;i++)
	{
		double t=M_PI*(mgl_rnd()-0.5), f=2*M_PI*mgl_rnd();
		x.a[i] = 0.9*cos(t)*cos(f);
		y.a[i] = 0.9*cos(t)*sin(f);
		z.a[i] = 0.6*sin(t);
		c.a[i] = cos(2*t);
	}
	if(big!=3)	{	gr->SubPlot(2,2,0);	gr->Title("Dots sample");	}
	gr->Rotate(50,60);	gr->Box();	gr->Dots(x,y,z);
	if(big==3)	return;
	gr->Alpha(true);
	gr->SubPlot(2,2,1);	gr->Title("add transparency");		gr->Rotate(50,60);	gr->Box();	gr->Dots(x,y,z,c);
	gr->SubPlot(2,2,2);	gr->Title("add coloring");	gr->Rotate(50,60);	gr->Box();	gr->Dots(x,y,z,x,c);
	gr->SubPlot(2,2,3);	gr->Title("Only coloring");		gr->Rotate(50,60);	gr->Box();	gr->Tens(x,y,z,x," .");
}
Sample dots