11.50 Sample ‘earth

Example of Earth map by using import.

MGL code:

import dat 'Equirectangular-projection.jpg' 'BbGYw' -1 1
subplot 1 1 0 '<>':title 'Earth in 3D':rotate 40 60
copy phi dat 'pi*x':copy tet dat 'pi*y/2'
copy x cos(tet)*cos(phi)
copy y cos(tet)*sin(phi)
copy z sin(tet)

light on
surfc x y z dat 'BbGYw'
contp [-0.51,-0.51] x y z dat 'y'

C++ code:

void smgl_earth(mglGraph *gr)
{
	mglData dat;	dat.Import("Equirectangular-projection.jpg","BbGYw",-1,1);
	// Calc proper 3d coordinates from projection
	mglData phi(dat.nx,dat.ny);	phi.Fill(-M_PI,M_PI);
	mglData tet(dat.nx,dat.ny);	tet.Fill(-M_PI/2,M_PI/2,'y');
	mglData x(dat.nx,dat.ny), y(dat.nx,dat.ny), z(dat.nx,dat.ny);
#pragma omp parallel for schedule(static)
	for(long i=0;i<dat.nx*dat.ny;i++)
	{	x.a[i] = cos(tet.a[i])*cos(phi.a[i]);
		y.a[i] = cos(tet.a[i])*sin(phi.a[i]);
		z.a[i] = sin(tet.a[i]);	}

	gr->SubPlot(1,1,0,"<>");
	if(big!=3)	gr->Title("Earth in 3D");
	gr->Rotate(40,60);	gr->Light(true);
	gr->SurfC(x,y,z,dat,"BbGYw");
	mglData vals(1);	vals.a[0]=-0.51;
	gr->ContP(vals, x,y,z,dat,"y");
}
Sample earth