From: <sm...@us...> - 2009-05-29 19:52:54
|
Revision: 10013 http://plplot.svn.sourceforge.net/plplot/?rev=10013&view=rev Author: smekal Date: 2009-05-29 19:51:53 +0000 (Fri, 29 May 2009) Log Message: ----------- Added plmap to the improved D bindings. Added working D examples 18 and 19 and changed CMakeLists.txt accordingly. Commited also example 9 which doesn't compile yet. Modified Paths: -------------- trunk/bindings/d/plplot.d trunk/examples/d/CMakeLists.txt Added Paths: ----------- trunk/examples/d/x09d.d trunk/examples/d/x18d.d trunk/examples/d/x19d.d Modified: trunk/bindings/d/plplot.d =================================================================== --- trunk/bindings/d/plplot.d 2009-05-29 19:27:13 UTC (rev 10012) +++ trunk/bindings/d/plplot.d 2009-05-29 19:51:53 UTC (rev 10013) @@ -6,6 +6,15 @@ // improved D interface +// certain functions must be declared as C functions so that PLplot +// can handle them +extern (C) { + alias PLINT function(PLFLT, PLFLT) def_func; + alias void function(PLINT, PLFLT* , PLFLT*) fill_func; + alias void function(PLFLT, PLFLT, PLFLT*, PLFLT*, PLPointer) pltr_func; + alias void function(PLINT, PLFLT*, PLFLT*) mapform_func; +} + // helper function to convert D dynamic arrays in C dynamic arrays private PLFLT** convert_array(PLFLT[][] a) { @@ -21,16 +30,6 @@ return c_a; } -// certain functions must be declared as C functions so that PLplot -// can handle them -extern (C) { - alias PLINT function(PLFLT, PLFLT) def_func; - alias void function(PLINT, PLFLT* , PLFLT*) fill_func; - alias void function(PLFLT, PLFLT, PLFLT*, PLFLT*, PLPointer) pltr_func; -} - - - /* Process options list using current options info. */ int plparseopts(char[][] args, PLINT mode) { @@ -186,11 +185,12 @@ } /* plot continental outline in world coordinates */ -//void c_plmap(void function(PLINT , PLFLT *, PLFLT *)mapform, char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); +void plmap(mapform_func mapform, string type, PLFLT minlong, PLFLT maxlong, + PLFLT minlat, PLFLT maxlat) +{ + c_plmap(mapform, toStringz(type), minlong, maxlong, minlat, maxlat); +} -/* Plot the latitudes and longitudes on the background. */ -//void c_plmeridians(void function(PLINT , PLFLT *, PLFLT *)mapform, PLFLT dlong, PLFLT dlat, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); - /* Plots a mesh representation of the function z[x][y]. */ //void c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt); @@ -469,29 +469,6 @@ /* Sets an optional user abort handler. */ //void plsabort(void function(char *)handler); -/* Transformation routines */ - -/* Identity transformation. */ -//void pltr0(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - -/* Does linear interpolation from singly dimensioned coord arrays. */ -//void pltr1(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - -/* Does linear interpolation from doubly dimensioned coord arrays */ -/* (column dominant, as per normal C 2d arrays). */ -//void pltr2(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - -/* Just like pltr2() but uses pointer arithmetic to get coordinates from */ -/* 2d grid tables. */ -//void pltr2p(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - -/* Identity transformation for plots from Fortran. */ -//void pltr0f(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data); - -/* Does linear interpolation from doubly dimensioned coord arrays */ -/* (row dominant, i.e. Fortran ordering). */ -//void pltr2f(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data); - /* Function evaluators */ /* Does a lookup from a 2d function array. Array is of type (PLFLT **), */ @@ -975,7 +952,7 @@ //alias c_plline plline; //alias c_plline3 plline3; alias c_pllsty pllsty; -alias c_plmap plmap; +//alias c_plmap plmap; alias c_plmeridians plmeridians; alias c_plmesh plmesh; alias c_plmeshc plmeshc; @@ -1360,16 +1337,16 @@ void c_pllsty(PLINT lin); /* plot continental outline in world coordinates */ -void c_plmap(void function(PLINT , PLFLT *, PLFLT *)mapform, char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); +void c_plmap(void function(PLINT, PLFLT*, PLFLT*) mapform, char *type, PLFLT minlong, + PLFLT maxlong, PLFLT minlat, PLFLT maxlat); /* Plot the latitudes and longitudes on the background. */ +void c_plmeridians(void function(PLINT, PLFLT*, PLFLT*) mapform, PLFLT dlong, PLFLT dlat, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); -void c_plmeridians(void function(PLINT , PLFLT *, PLFLT *)mapform, PLFLT dlong, PLFLT dlat, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); - /* Plots a mesh representation of the function z[x][y]. */ +void c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt); -void c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt); - /* Plots a mesh representation of the function z[x][y] with contour */ void c_plmeshc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel); @@ -1749,37 +1726,31 @@ void plsabort(void function(char *)handler); - /* Transformation routines */ +/* Transformation routines */ /* Identity transformation. */ +void pltr0(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, PLPointer pltr_data); -void pltr0(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - /* Does linear interpolation from singly dimensioned coord arrays. */ +void pltr1(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, PLPointer pltr_data); -void pltr1(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - /* Does linear interpolation from doubly dimensioned coord arrays */ /* (column dominant, as per normal C 2d arrays). */ +void pltr2(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, PLPointer pltr_data); -void pltr2(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - /* Just like pltr2() but uses pointer arithmetic to get coordinates from */ /* 2d grid tables. */ +void pltr2p(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, PLPointer pltr_data); -void pltr2p(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); - /* Identity transformation for plots from Fortran. */ +void pltr0f(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, void* pltr_data); -void pltr0f(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data); - /* Does linear interpolation from doubly dimensioned coord arrays */ /* (row dominant, i.e. Fortran ordering). */ +void pltr2f(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, void* pltr_data); -void pltr2f(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data); +/* Function evaluators */ - /* Function evaluators */ - /* Does a lookup from a 2d function array. Array is of type (PLFLT **), */ /* and is column dominant (normal C ordering). */ Modified: trunk/examples/d/CMakeLists.txt =================================================================== --- trunk/examples/d/CMakeLists.txt 2009-05-29 19:27:13 UTC (rev 10012) +++ trunk/examples/d/CMakeLists.txt 2009-05-29 19:51:53 UTC (rev 10013) @@ -28,6 +28,7 @@ "06" "07" "08" +# "09" "10" "11" "12" @@ -35,6 +36,8 @@ "14" "15" "17" + "18" + "19" "23" "24" "25" Added: trunk/examples/d/x09d.d =================================================================== --- trunk/examples/d/x09d.d (rev 0) +++ trunk/examples/d/x09d.d 2009-05-29 19:51:53 UTC (rev 10013) @@ -0,0 +1,369 @@ +/* $Id: $ + + Contour plot demo. + + This file is part of PLplot. + + PLplot is free software; you can redistribute it and/or modify + it under the terms of the GNU General Library Public License as published + by the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PLplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with PLplot; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +import std.string; +import plplot; + +#define XPTS 35 /* Data points in x */ +#define YPTS 46 /* Data points in y */ + +#define XSPA 2./(XPTS-1) +#define YSPA 2./(YPTS-1) + +/* polar plot data */ +#define PERIMETERPTS 100 +#define RPTS 40 +#define THETAPTS 40 + +/* potential plot data */ +#define PPERIMETERPTS 100 +#define PRPTS 40 +#define PTHETAPTS 64 +#define PNLEVEL 20 + +static PLFLT clevel[11] = +{-1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1.}; + +/* Transformation function */ + +extern (C) { + PLFLT[] tr = {XSPA, 0.0, -1.0, 0.0, YSPA, -1.0}; + + void mypltr(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, void* pltr_data) + { + *tx = tr[0]*x + tr[1]*y + tr[2]; + *ty = tr[3]*x + tr[4]*y + tr[5]; + } +} + +static void polar() +/*polar contour plot example.*/ +{ + int i,j; + PLcGrid2 cgrid2; + PLFLT **z; + PLFLT px[PERIMETERPTS], py[PERIMETERPTS]; + PLFLT t, r, theta; + PLFLT lev[10]; + + plenv(-1., 1., -1., 1., 0, -2); + plcol0(1); + +/*Perimeter*/ + for (i = 0; i < PERIMETERPTS; i++) { + t = (2.*M_PI/(PERIMETERPTS-1))*(double)i; + px[i] = cos(t); + py[i] = sin(t); + } + plline(PERIMETERPTS, px, py); + +/*create data to be contoured.*/ + plAlloc2dGrid(&cgrid2.xg, RPTS, THETAPTS); + plAlloc2dGrid(&cgrid2.yg, RPTS, THETAPTS); + plAlloc2dGrid(&z, RPTS, THETAPTS); + cgrid2.nx = RPTS; + cgrid2.ny = THETAPTS; + + for (i = 0; i < RPTS; i++) { + r = i/(double)(RPTS-1); + for (j = 0; j < THETAPTS; j++) { + theta = (2.*M_PI/(double)(THETAPTS-1))*(double)j; + cgrid2.xg[i][j] = r*cos(theta); + cgrid2.yg[i][j] = r*sin(theta); + z[i][j] = r; + } + } + + for (i = 0; i < 10; i++) { + lev[i] = 0.05 + 0.10*(double) i; + } + + plcol0(2); + plcont(z, RPTS, THETAPTS, 1, RPTS, 1, THETAPTS, lev, 10, + pltr2, (void *) &cgrid2); + plcol0(1); + pllab("", "", "Polar Contour Plot"); + plFree2dGrid(z, RPTS, THETAPTS); + plFree2dGrid(cgrid2.xg, RPTS, THETAPTS); + plFree2dGrid(cgrid2.yg, RPTS, THETAPTS); +} + +/*--------------------------------------------------------------------------*\ + * f2mnmx + * + * Returns min & max of input 2d array. +\*--------------------------------------------------------------------------*/ + +static void +f2mnmx(PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmin, PLFLT *fmax) +{ + int i, j; + + *fmax = f[0][0]; + *fmin = *fmax; + + for (i = 0; i < nx; i++) { + for (j = 0; j < ny; j++) { + *fmax = MAX(*fmax, f[i][j]); + *fmin = MIN(*fmin, f[i][j]); + } + } +} + +static void potential() +/*shielded potential contour plot example.*/ +{ + PLcGrid2 cgrid2; + PLFLT rmax, xmin, xmax, x0, ymin, ymax, y0, zmin, zmax; + PLFLT peps, xpmin, xpmax, ypmin, ypmax; + PLFLT eps, q1, d1, q1i, d1i, q2, d2, q2i, d2i; + PLFLT div1, div1i, div2, div2i; + PLFLT **z; + PLINT nlevelneg, nlevelpos; + PLFLT dz, clevel, clevelneg[PNLEVEL], clevelpos[PNLEVEL]; + PLINT ncollin, ncolbox, ncollab; + PLFLT px[PPERIMETERPTS], py[PPERIMETERPTS]; + PLFLT t, r, theta; + + /*create data to be contoured.*/ + plAlloc2dGrid(&cgrid2.xg, PRPTS, PTHETAPTS); + plAlloc2dGrid(&cgrid2.yg, PRPTS, PTHETAPTS); + plAlloc2dGrid(&z, PRPTS, PTHETAPTS); + cgrid2.nx = PRPTS; + cgrid2.ny = PTHETAPTS; + + for (i = 0; i < PRPTS; i++) { + r = 0.5 + (double) i; + for (j = 0; j < PTHETAPTS; j++) { + theta = (2.*M_PI/(double)(PTHETAPTS-1))*(0.5 + (double) j); + cgrid2.xg[i][j] = r*cos(theta); + cgrid2.yg[i][j] = r*sin(theta); + } + } + + rmax = r; + f2mnmx(cgrid2.xg, PRPTS, PTHETAPTS, &xmin, &xmax); + f2mnmx(cgrid2.yg, PRPTS, PTHETAPTS, &ymin, &ymax); + x0 = (xmin + xmax)/2.; + y0 = (ymin + ymax)/2.; + + /* Expanded limits */ + peps = 0.05; + xpmin = xmin - fabs(xmin)*peps; + xpmax = xmax + fabs(xmax)*peps; + ypmin = ymin - fabs(ymin)*peps; + ypmax = ymax + fabs(ymax)*peps; + + /* Potential inside a conducting cylinder (or sphere) by method of images. + Charge 1 is placed at (d1, d1), with image charge at (d2, d2). + Charge 2 is placed at (d1, -d1), with image charge at (d2, -d2). + Also put in smoothing term at small distances. + */ + + eps = 2.; + + q1 = 1.; + d1 = rmax/4.; + + q1i = - q1*rmax/d1; + d1i = pow(rmax, 2.)/d1; + + q2 = -1.; + d2 = rmax/4.; + + q2i = - q2*rmax/d2; + d2i = pow(rmax, 2.)/d2; + + for(int i=0; i<PRPTS; i++) { + for(int j=0; j<PTHETAPTS; j++) { + div1 = sqrt(pow(cgrid2.xg[i][j]-d1, 2.) + pow(cgrid2.yg[i][j]-d1, 2.) + pow(eps, 2.)); + div1i = sqrt(pow(cgrid2.xg[i][j]-d1i, 2.) + pow(cgrid2.yg[i][j]-d1i, 2.) + pow(eps, 2.)); + div2 = sqrt(pow(cgrid2.xg[i][j]-d2, 2.) + pow(cgrid2.yg[i][j]+d2, 2.) + pow(eps, 2.)); + div2i = sqrt(pow(cgrid2.xg[i][j]-d2i, 2.) + pow(cgrid2.yg[i][j]+d2i, 2.) + pow(eps, 2.)); + z[i][j] = q1/div1 + q1i/div1i + q2/div2 + q2i/div2i; + } + } + f2mnmx(z, zmin, zmax); + + /* Positive and negative contour levels.*/ + dz = (zmax-zmin)/PNLEVEL; + nlevelneg = 0; + nlevelpos = 0; + for(int i=0; i<PNLEVEL; i++) { + clevel = zmin + (i+0.5)*dz; + if(clevel<=0.) + clevelneg[nlevelneg++] = clevel; + else + clevelpos[nlevelpos++] = clevel; + } + /* Colours! */ + ncollin = 11; + ncolbox = 1; + ncollab = 2; + + /* Finally start plotting this page! */ + pladv(0); + plcol0(ncolbox); + + plvpas(0.1, 0.9, 0.1, 0.9, 1.0); + plwind(xpmin, xpmax, ypmin, ypmax); + plbox("", 0., 0, "", 0., 0); + + plcol0(ncollin); + if(nlevelneg >0) { + /* Negative contours */ + pllsty(2); + plcont(z, 1, PRPTS, 1, PTHETAPTS, clevelneg, pltr2, (void*)&cgrid2); + } + + if(nlevelpos >0) { + /* Positive contours */ + pllsty(1); + plcont(z, 1, PRPTS, 1, PTHETAPTS, clevelpos, pltr2, (void*)&cgrid2); + } + + /* Draw outer boundary */ + for(int i=0; i<PPERIMETERPTS; i++) { + t = (2.*PI/(PPERIMETERPTS-1))*i; + px[i] = x0 + rmax*cos(t); + py[i] = y0 + rmax*sin(t); + } + + plcol0(ncolbox); + plline(px, py); + + plcol0(ncollab); + pllab("", "", "Shielded potential of charges in a conducting sphere"); +} + + +/*--------------------------------------------------------------------------*\ + * main + * + * Does several contour plots using different coordinate mappings. +\*--------------------------------------------------------------------------*/ +int main(char[][] args) +{ + PLINT[] mark = [ 1500 ], space = [ 1500 ]; + + /* Parse and process command line arguments */ + plparseopts(args, PL_PARSE_FULL); + + /* Initialize plplot */ + plinit(); + + /* Set up function arrays */ + PLFLT xx, yy; + PLFLT[][] z = new PLFLT[][XPTS]; + for(int i=0; i<XPTS; i++) + z[i] = new PLFLT[YPTS]; + + PLFLT[][] w = new PLFLT[][XPTS]; + for(int i=0; i<XPTS; i++) + w[i] = new PLFLT[YPTS]; + + for(int i=0; i<XPTS; i++) { + xx = cast(double)(i-(XPTS/2))/(XPTS/2); + for(int j=0; j<YPTS; j++) { + yy = cast(double)(j-(YPTS/2))/(YPTS / 2)-1.0; + z[i][j] = xx*xx - yy*yy; + w[i][j] = 2*xx*yy; + } + } + + /* Set up grids */ + cgrid1.xg = (new PLFLT[XPTS]).ptr; + cgrid1.yg = (new PLFLT[XPTS]).ptr; + + PLFLT[][] cgrid2.xg = new PLFLT[][XPTS]; + for(int i=0; i<XPTS; i++) + cgrid2.xg[i] = new PLFLT[YPTS]; + + PLFLT[][] cgrid2.yg = new PLFLT[][XPTS]; + for(int i=0; i<XPTS; i++) + cgrid2.yg[i] = new PLFLT[YPTS]; + + PLFLT argx, argy, distort; + for(int i=0; i<XPTS; i++) { + for(int j=0; j<YPTS; j++) { + mypltr(cast(PLFLT)i, cast(PLFLT)j, &xx, &yy, null); + + argx = xx * M_PI/2; + argy = yy * M_PI/2; + distort = 0.4; + + cgrid1.xg[i] = xx + distort * cos(argx); + cgrid1.yg[j] = yy - distort * cos(argy); + + cgrid2.xg[i][j] = xx + distort * cos(argx) * cos(argy); + cgrid2.yg[i][j] = yy - distort * cos(argx) * cos(argy); + } + } + + /* Plot using identity transform */ + pl_setcontlabelparam(0.006, 0.3, 0.1, 1); + plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); + plcol0(2); + plcont(z, 1, XPTS, 1, YPTS, clevel, mypltr); + + plstyl(mark, space); + plcol0(3); + plcont(w, 1, XPTS, 1, YPTS, clevel, mypltr); + plstyl(null, null); + plcol0(1); + pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); + pl_setcontlabelparam(0.006, 0.3, 0.1, 0); + + /* Plot using 1d coordinate transform */ + plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); + plcol0(2); + plcont(z, 1, XPTS, 1, YPTS, clevel, pltr1, cast(void*)&cgrid1); + + plstyl(1, mark, space); + plcol0(3); + plcont(w, 1, XPTS, 1, YPTS, clevel, pltr1, cast(void*)&cgrid1); + plstyl(null, null); + plcol0(1); + pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); + + /* Plot using 2d coordinate transform */ + plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); + plcol0(2); + plcont(z, 1, XPTS, 1, YPTS, clevel, pltr2, (void *)&cgrid2); + + plstyl(mark, space); + plcol0(3); + plcont(w, 1, XPTS, 1, YPTS, clevel, pltr2, (void *)&cgrid2); + plstyl(null, null); + plcol0(1); + pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); + + pl_setcontlabelparam(0.006, 0.3, 0.1, 0); + polar(); + + pl_setcontlabelparam(0.006, 0.3, 0.1, 0); + potential(); + + plend(); + + return 0; +} Property changes on: trunk/examples/d/x09d.d ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/examples/d/x18d.d =================================================================== --- trunk/examples/d/x18d.d (rev 0) +++ trunk/examples/d/x18d.d 2009-05-29 19:51:53 UTC (rev 10013) @@ -0,0 +1,130 @@ +/* $Id: $ + + 3-d line and point plot demo. Adapted from x08c.c. +*/ + +import std.math; +import std.string; + +import plplot; + +int opt[] = [ 1, 0, 1, 0 ]; +PLFLT alt[] = [ 20.0, 35.0, 50.0, 65.0 ]; +PLFLT az[] = [ 30.0, 40.0, 50.0, 60.0 ]; + +/*--------------------------------------------------------------------------*\ + * main + * + * Does a series of 3-d plots for a given data set, with different + * viewing options in each plot. +\*--------------------------------------------------------------------------*/ +int main(char[][] args) +{ + const int npts=1000; + + /* Parse and process command line arguments */ + plparseopts(args, PL_PARSE_FULL); + + /* Initialize plplot */ + plinit(); + + for(int k=0; k<4; k++) + test_poly(k); + + PLFLT[] x = new PLFLT[npts]; + PLFLT[] y = new PLFLT[npts]; + PLFLT[] z = new PLFLT[npts]; + + /* From the mind of a sick and twisted physicist... */ + PLFLT r; + for(int i=0; i<npts; i++) { + z[i] = -1. + 2.*i/npts; + + /* Pick one ... */ + /* r = 1. - cast(PLFLT)i/npts; */ + r = z[i]; + + x[i] = r*cos(2.*PI*6.*i/npts); + y[i] = r*sin(2.*PI*6.*i/npts); + } + + for(int k=0; k<4; k++) { + pladv(0); + plvpor(0.0, 1.0, 0.0, 0.9); + plwind(-1.0, 1.0, -0.9, 1.1); + plcol0(1); + plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k]); + plbox3("bnstu", "x axis", 0.0, 0, + "bnstu", "y axis", 0.0, 0, + "bcdmnstuv", "z axis", 0.0, 0); + + plcol0(2); + + if(opt[k]) + plline3(x, y, z); + else + plpoin3(x, y, z, 1 ); + + plcol0(3); + plmtex("t", 1.0, 0.5, 0.5, format("#frPLplot Example 18 - Alt=%.0f, Az=%.0f", alt[k], az[k])); + } + + plend(); + + return 0; +} + +void test_poly(int k) +{ + PLINT draw[][] = [ [ 1, 1, 1, 1 ], + [ 1, 0, 1, 0 ], + [ 0, 1, 0, 1 ], + [ 1, 1, 0, 0 ] ]; + + PLFLT[] x = new PLFLT[5]; + PLFLT[] y = new PLFLT[5]; + PLFLT[] z = new PLFLT[5]; + + pladv(0); + plvpor(0.0, 1.0, 0.0, 0.9); + plwind(-1.0, 1.0, -0.9, 1.1); + plcol0(1); + plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k]); + plbox3("bnstu", "x axis", 0.0, 0, + "bnstu", "y axis", 0.0, 0, + "bcdmnstuv", "z axis", 0.0, 0); + + plcol0(2); + + PLFLT theta(int a) { return 2*PI*a/20; } + PLFLT phi(int a) { return PI*a/20.1; } + + for(int i=0; i<20; i++) { + for(int j=0; j<20; j++) { + x[0] = sin(phi(j)) * cos(theta(i)); + y[0] = sin(phi(j)) * sin(theta(i)); + z[0] = cos(phi(j)); + + x[1] = sin(phi(j+1)) * cos(theta(i)); + y[1] = sin(phi(j+1)) * sin(theta(i)); + z[1] = cos(phi(j+1)); + + x[2] = sin(phi(j+1)) * cos(theta(i+1)); + y[2] = sin(phi(j+1)) * sin(theta(i+1)); + z[2] = cos(phi(j+1)); + + x[3] = sin(phi(j)) * cos(theta(i+1)); + y[3] = sin(phi(j)) * sin(theta(i+1)); + z[3] = cos(phi(j)); + + x[4] = sin(phi(j)) * cos(theta(i)); + y[4] = sin(phi(j)) * sin(theta(i)); + z[4] = cos(phi(j)); + + plpoly3(x, y, z, draw[k], 1 ); + } + } + + plcol0(3); + plmtex("t", 1.0, 0.5, 0.5, "unit radius sphere"); +} Property changes on: trunk/examples/d/x18d.d ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/examples/d/x19d.d =================================================================== --- trunk/examples/d/x19d.d (rev 0) +++ trunk/examples/d/x19d.d 2009-05-29 19:51:53 UTC (rev 10013) @@ -0,0 +1,79 @@ +/* $Id: $ + + Illustrates backdrop plotting of world, US maps. + Contributed by Wesley Ebisuzaki. +*/ + +import std.math; + +import plplot; + +extern (C) { + /*--------------------------------------------------------------------------*\ + * mapform19 + * + * Defines specific coordinate transformation for example 19. + * Not to be confused with mapform in src/plmap.c. + * x[], y[] are the coordinates to be plotted. + \*--------------------------------------------------------------------------*/ + void mapform19(PLINT n, PLFLT* x, PLFLT* y) + { + double xp, yp, radius; + + for(int i=0; i<n; i++) { + radius = 90.0-y[i]; + xp = radius*cos(x[i]*PI/180.0); + yp = radius*sin(x[i]*PI/180.0); + x[i] = xp; + y[i] = yp; + } + } +} + + +/*--------------------------------------------------------------------------*\ + * main + * + * Shows two views of the world map. +\*--------------------------------------------------------------------------*/ +int main(char[][] args) +{ + /* Parse and process command line arguments */ + plparseopts(args, PL_PARSE_FULL); + + /* Longitude (x) and latitude (y) */ + PLFLT miny = -70; + PLFLT maxy = 80; + + plinit(); + + /* Cartesian plots */ + /* Most of world */ + PLFLT minx = 190; + PLFLT maxx = 190+360; + + plcol0(1); + plenv(minx, maxx, miny, maxy, 1, -1); + plmap(null, "usaglobe", minx, maxx, miny, maxy); + + /* The Americas */ + minx = 190; + maxx = 340; + + plcol0(1); + plenv(minx, maxx, miny, maxy, 1, -1); + plmap(null, "usaglobe", minx, maxx, miny, maxy); + + /* Polar, Northern hemisphere */ + minx = 0; + maxx = 360; + + plenv(-75., 75., -75., 75., 1, -1); + plmap(&mapform19, "globe", minx, maxx, miny, maxy); + + pllsty(2); + plmeridians(&mapform19, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0); + + plend(); + return 0; +} Property changes on: trunk/examples/d/x19d.d ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |