11.141 Sample ‘triangulation

Example of use triangulate for arbitrary placed points.

MGL code:

new x 100 '2*rnd-1':new y 100 '2*rnd-1':copy z x^2-y^2
new g 30 30:triangulate d x y
title 'Triangulation'
rotate 50 60:box:light on
triplot d x y z:triplot d x y z '#k'
datagrid g x y z:mesh g 'm'

C++ code:

void smgl_triangulation(mglGraph *gr)	// surface triangulation
{
	mglData x(100), y(100), z(100);
	gr->Fill(x,"2*rnd-1");	gr->Fill(y,"2*rnd-1");	gr->Fill(z,"v^2-w^2",x,y);
	mglData d = mglTriangulation(x,y), g(30,30);

	if(big!=3)	gr->Title("Triangulation");
	gr->Rotate(40,60);	gr->Box();	gr->Light(true);
	gr->TriPlot(d,x,y,z);	gr->TriPlot(d,x,y,z,"#k");

	gr->DataGrid(g,x,y,z);	gr->Mesh(g,"m");
}
Sample triangulation