[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section is devoted to visualization of 3D data arrays. 3D means the data which depend on 3 indexes (parameters) like tensor a(i,j,k)=a(x(i),y(j),x(k)), i=1...n, j=1...m, k=1...l or in parametric form {x(i,j,k),y(i,j,k),z(i,j,k),a(i,j,k)}. Most of samples will use the same data for plotting. So, I put its initialization in separate function
void mgls_prepare3d(mglData *a, mglData *b=0) { register long i,j,k,n=61,m=50,l=40,i0; if(a) a->Create(n,m,l); if(b) b->Create(n,m,l); mreal x,y,z; for(i=0;i<n;i++) for(j=0;j<m;j++) for(k=0;k<l;k++) { x=2*i/(n-1.)-1; y=2*j/(m-1.)-1; z=2*k/(l-1.)-1; i0 = i+n*(j+m*k); if(a) a->a[i0] = -2*(x*x + y*y + z*z*z*z - z*z - 0.1); if(b) b->a[i0] = 1-2*tanh((x+y)*(x+y)); } }
or using C functions
void mgls_prepare3d(HMDT a, HMDT b=0) { register long i,j,k,n=61,m=50,l=40,i0; if(a) mgl_data_create(a,n,m,l); if(b) mgl_data_create(b,n,m,l); mreal x,y,z; for(i=0;i<n;i++) for(j=0;j<m;j++) for(k=0;k<l;k++) { x=2*i/(n-1.)-1; y=2*j/(m-1.)-1; z=2*k/(l-1.)-1; i0 = i+n*(j+m*k); if(a) mgl_data_set_value(a, -2*(x*x + y*y + z*z*z*z - z*z - 0.1), i,j,k); if(b) mgl_data_set_value(b, 1-2*tanh((x+y)*(x+y)), i,j,k); } }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function surf3 is one of most suitable (for my opinion) functions to visualize 3D data. It draw the isosurface(s) – surface(s) of constant amplitude (3D analogue of contour lines). You can draw wired isosurfaces if specify ‘#’ style. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->Light(true); gr->Alpha(true); gr->SubPlot(2,2,0); gr->Title("Surf3 plot (default)"); gr->Rotate(50,60); gr->Box(); gr->Surf3(c); gr->SubPlot(2,2,1); gr->Title("'\\#' style"); gr->Rotate(50,60); gr->Box(); gr->Surf3(c,"#"); gr->SubPlot(2,2,2); gr->Title("'.' style"); gr->Rotate(50,60); gr->Box(); gr->Surf3(c,"."); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function surf3c is similar to surf3 but its coloring is determined by another data. The sample code is:
int sample(mglGraph *gr) { mglData c,d; mgls_prepare3d(&c,&d); gr->Title("Surf3C plot"); gr->Rotate(50,60); gr->Light(true); gr->Alpha(true); gr->Box(); gr->Surf3C(c,d); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function surf3a is similar to surf3 but its transparency is determined by another data. The sample code is:
int sample(mglGraph *gr) { mglData c,d; mgls_prepare3d(&c,&d); gr->Title("Surf3A plot"); gr->Rotate(50,60); gr->Light(true); gr->Alpha(true); gr->Box(); gr->Surf3A(c,d); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function cloud draw cloud-like object which is less transparent for higher data values. Similar plot can be created using many (about 10-20) Surf3A(a,a)
isosurfaces. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->SubPlot(2,2,0); gr->Title("Cloud plot"); gr->Rotate(50,60); gr->Alpha(true); gr->Box(); gr->Cloud(c,"wyrRk"); gr->SubPlot(2,2,1); gr->Title("'!' style"); gr->Rotate(50,60); gr->Box(); gr->Cloud(c,"!wyrRk"); gr->SubPlot(2,2,2); gr->Title("'.' style"); gr->Rotate(50,60); gr->Box(); gr->Cloud(c,".wyrRk"); gr->SubPlot(2,2,3); gr->Title("meshnum 10"); gr->Rotate(50,60); gr->Box(); gr->Cloud(c,"wyrRk","meshnum 10"); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function dens3 draw just usual density plot but at slices of 3D data. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->Title("Dens3 sample"); gr->Rotate(50,60); gr->Alpha(true); gr->SetAlphaDef(0.7); gr->SetOrigin(0,0,0); gr->Axis("_xyz"); gr->Box(); gr->Dens3(c,"x"); gr->Dens3(c); gr->Dens3(c,"z"); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function cont3 draw just usual contour lines but at slices of 3D data. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->Title("Cont3 sample"); gr->Rotate(50,60); gr->Alpha(true); gr->SetAlphaDef(0.7); gr->SetOrigin(0,0,0); gr->Axis("_xyz"); gr->Box(); gr->Cont3(c,"x"); gr->Cont3(c); gr->Cont3(c,"z"); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function contf3 draw just usual filled contours but at slices of 3D data. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->Title("ContF3 sample"); gr->Rotate(50,60); gr->Alpha(true); gr->SetAlphaDef(0.7); gr->SetOrigin(0,0,0); gr->Axis("_xyz"); gr->Box(); gr->ContF3(c,"x"); gr->ContF3(c); gr->ContF3(c,"z"); gr->Cont3(c,"kx"); gr->Cont3(c,"k"); gr->Cont3(c,"kz"); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Functions DensXYZ draw density plot on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->Title("Dens[XYZ] sample"); gr->Rotate(50,60); gr->Box(); gr->DensX(c.Sum("x"),0,-1); gr->DensY(c.Sum("y"),0,1); gr->DensZ(c.Sum("z"),0,-1); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Functions ContXYZ draw contour lines on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->Title("Cont[XYZ] sample"); gr->Rotate(50,60); gr->Box(); gr->ContX(c.Sum("x"),"",-1); gr->ContY(c.Sum("y"),"",1); gr->ContZ(c.Sum("z"),"",-1); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Functions ContFXYZ
draw filled contours on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field. The sample code is:
int sample(mglGraph *gr) { mglData c; mgls_prepare3d(&c); gr->Title("Cont[XYZ] sample"); gr->Rotate(50,60); gr->Box(); gr->ContFX(c.Sum("x"),"",-1); gr->ContFY(c.Sum("y"),"",1); gr->ContFZ(c.Sum("z"),"",-1); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function triplot and quadplot draw set of triangles (or quadrangles for QuadPlot
) 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. The sample code is:
int sample(mglGraph *gr) { mreal 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}; mreal 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#"); mreal t[] = {0,1,2, 0,1,3, 0,2,3, 1,2,3}; mreal 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"); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Function dots is another way to draw irregular points. Dots
use color scheme for coloring (see Color scheme). The sample code is:
int sample(mglGraph *gr) { int i, n=1000; mglData x(n),y(n),z(n); for(i=0;i<n;i++) { mreal 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); } gr->Title("Dots sample"); gr->Rotate(50,60); gr->Box(); gr->Dots(x,y,z); return 0; }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated on May 5, 2014 using texi2html 1.82.