11.142 Sample ‘triplot

Functions triplot and quadplot draw set of triangles (or quadrangles, correspondingly) for irregular data arrays. Note, that you have to provide not only vertexes, but also the indexes of triangles or quadrangles. I.e. perform triangulation by some other library. See also triangulate.

MGL code:

list q 0 1 2 3 | 4 5 6 7 | 0 2 4 6 | 1 3 5 7 | 0 4 1 5 | 2 6 3 7
list xq -1 1 -1 1 -1 1 -1 1
list yq -1 -1 1 1 -1 -1 1 1
list zq -1 -1 -1 -1 1 1 1 1
light on
subplot 2 2 0:title 'QuadPlot sample':rotate 50 60
quadplot q xq yq zq 'yr'
quadplot q xq yq zq '#k'
subplot 2 2 2:title 'QuadPlot coloring':rotate 50 60
quadplot q xq yq zq yq 'yr'
quadplot q xq yq zq '#k'
list t 0 1 2 | 0 1 3 | 0 2 3 | 1 2 3
list xt -1 1 0 0
list yt -1 -1 1 0
list zt -1 -1 -1 1
subplot 2 2 1:title 'TriPlot sample':rotate 50 60
triplot t xt yt zt 'b'
triplot t xt yt zt '#k'
subplot 2 2 3:title 'TriPlot coloring':rotate 50 60
triplot t xt yt zt yt 'cb'
triplot t xt yt zt '#k'
tricont t xt yt zt 'B'

C++ code:

void smgl_triplot(mglGraph *gr)
{
	double q[] = {0,1,2,3, 4,5,6,7, 0,2,4,6, 1,3,5,7, 0,4,1,5, 2,6,3,7};
	double xc[] = {-1,1,-1,1,-1,1,-1,1}, yc[] = {-1,-1,1,1,-1,-1,1,1}, zc[] = {-1,-1,-1,-1,1,1,1,1};
	mglData qq(6,4,q), xx(8,xc), yy(8,yc), zz(8,zc);
	gr->Light(true);	//gr->Alpha(true);
	gr->SubPlot(2,2,0);	gr->Title("QuadPlot sample");	gr->Rotate(50,60);
	gr->QuadPlot(qq,xx,yy,zz,"yr");
	gr->QuadPlot(qq,xx,yy,zz,"k#");
	gr->SubPlot(2,2,2);	gr->Title("QuadPlot coloring");	gr->Rotate(50,60);
	gr->QuadPlot(qq,xx,yy,zz,yy,"yr");
	gr->QuadPlot(qq,xx,yy,zz,"k#");

	double t[] = {0,1,2, 0,1,3, 0,2,3, 1,2,3};
	double xt[] = {-1,1,0,0}, yt[] = {-1,-1,1,0}, zt[] = {-1,-1,-1,1};
	mglData tt(4,3,t), uu(4,xt), vv(4,yt), ww(4,zt);
	gr->SubPlot(2,2,1);	gr->Title("TriPlot sample");	gr->Rotate(50,60);
	gr->TriPlot(tt,uu,vv,ww,"b");
	gr->TriPlot(tt,uu,vv,ww,"k#");
	gr->SubPlot(2,2,3);	gr->Title("TriPlot coloring");	gr->Rotate(50,60);
	gr->TriPlot(tt,uu,vv,ww,vv,"cb");
	gr->TriPlot(tt,uu,vv,ww,"k#");
	gr->TriCont(tt,uu,vv,ww,"B");
}

Sample triplot