11.132 Sample ‘ternary

Example of ternary coordinates.

MGL code:

ranges 0 1 0 1 0 1
new x 50 '0.25*(1+cos(2*pi*x))'
new y 50 '0.25*(1+sin(2*pi*x))'
new z 50 'x'
new a 20 30 '30*x*y*(1-x-y)^2*(x+y<1)'
new rx 10 'rnd':new ry 10:fill ry '(1-v)*rnd' rx
light on

subplot 2 2 0:title 'Ordinary axis 3D':rotate 50 60
box:axis:grid
plot x y z 'r2':surf a '#'
xlabel 'B':ylabel 'C':zlabel 'Z'

subplot 2 2 1:title 'Ternary axis (x+y+t=1)':ternary 1
box:axis:grid 'xyz' 'B;'
plot x y 'r2':plot rx ry 'q^ ':cont a:line 0.5 0 0 0.75 'g2'
xlabel 'B':ylabel 'C':tlabel 'A'

subplot 2 2 2:title 'Quaternary axis 3D':rotate 50 60:ternary 2
box:axis:grid 'xyz' 'B;'
plot x y z 'r2':surf a '#'
xlabel 'B':ylabel 'C':tlabel 'A':zlabel 'D'

subplot 2 2 3:title 'Ternary axis 3D':rotate 50 60:ternary 1
box:axis:grid 'xyz' 'B;'
plot x y z 'r2':surf a '#'
xlabel 'B':ylabel 'C':tlabel 'A':zlabel 'Z'

C++ code:

void smgl_ternary(mglGraph *gr)	// flag #
{
	gr->SetRanges(0,1,0,1,0,1);
	mglData x(50),y(50),z(50),rx(10),ry(10), a(20,30);
	a.Modify("30*x*y*(1-x-y)^2*(x+y<1)");
	x.Modify("0.25*(1+cos(2*pi*x))");
	y.Modify("0.25*(1+sin(2*pi*x))");
	rx.Modify("rnd"); ry.Modify("(1-v)*rnd",rx);
	z.Modify("x");

	gr->SubPlot(2,2,0);	gr->Title("Ordinary axis 3D");
	gr->Rotate(50,60);		gr->Light(true);
	gr->Plot(x,y,z,"r2");	gr->Surf(a,"BbcyrR#");
	gr->Axis(); gr->Grid();	gr->Box();
	gr->Label('x',"B",1);	gr->Label('y',"C",1);	gr->Label('z',"Z",1);

	gr->SubPlot(2,2,1);	gr->Title("Ternary axis (x+y+t=1)");
	gr->Ternary(1);
	gr->Plot(x,y,"r2");	gr->Plot(rx,ry,"q^ ");	gr->Cont(a);
	gr->Line(mglPoint(0.5,0), mglPoint(0,0.75), "g2");
	gr->Axis(); gr->Grid("xyz","B;");
	gr->Label('x',"B");	gr->Label('y',"C");	gr->Label('t',"A");

	gr->SubPlot(2,2,2);	gr->Title("Quaternary axis 3D");
	gr->Rotate(50,60);		gr->Light(true);
	gr->Ternary(2);
	gr->Plot(x,y,z,"r2");	gr->Surf(a,"BbcyrR#");
	gr->Axis(); gr->Grid();	gr->Box();
	gr->Label('t',"A",1);	gr->Label('x',"B",1);
	gr->Label('y',"C",1);	gr->Label('z',"D",1);

	gr->SubPlot(2,2,3);	gr->Title("Ternary axis 3D");
	gr->Rotate(50,60);		gr->Light(true);
	gr->Ternary(1);
	gr->Plot(x,y,z,"r2");	gr->Surf(a,"BbcyrR#");
	gr->Axis(); gr->Grid();	gr->Box();
	gr->Label('t',"A",1);	gr->Label('x',"B",1);
	gr->Label('y',"C",1);	gr->Label('z',"Z",1);
}

Sample ternary