Back to index

plt-scheme  4.2.1
plwind.c
Go to the documentation of this file.
00001 /* $Id: plwind.c,v 1.2 2005/03/17 21:39:22 eli Exp $
00002 
00003        Routines for setting up world coordinates of the current viewport.
00004 */
00005 
00006 #include "plplotP.h"
00007 
00008 #define  dtr   0.01745329252
00009 
00010 /*--------------------------------------------------------------------------*\
00011  * void plwind()
00012  *
00013  * Set up world coordinates of the viewport boundaries (2d plots).
00014 \*--------------------------------------------------------------------------*/
00015 
00016 void
00017 c_plwind(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax)
00018 {
00019     PLFLT dx, dy, mmxmi, mmxma, mmymi, mmyma;
00020     PLWindow w;
00021 
00022     if (plsc->level < 2) {
00023        plabort("plwind: Please set up viewport first");
00024        return;
00025     }
00026 
00027 /* Best to just warn and recover on bounds errors */
00028 
00029     if (xmin == xmax) {
00030        plwarn("plwind: Invalid window limits in x.");
00031        xmin--; xmax++;
00032     }
00033     if (ymin == ymax) {
00034        plwarn("plwind: Invalid window limits in y.");
00035        ymin--; ymax++;
00036     }
00037 
00038     dx = (xmax - xmin) * 1.0e-5;
00039     dy = (ymax - ymin) * 1.0e-5;
00040 
00041 /* The true plot window is made slightly larger than requested so that */
00042 /* the end limits will be on the graph  */
00043 
00044     plsc->vpwxmi = xmin - dx;
00045     plsc->vpwxma = xmax + dx;
00046     plsc->vpwymi = ymin - dy;
00047     plsc->vpwyma = ymax + dy;
00048 
00049 /* Compute the scaling between coordinate systems */
00050 
00051     dx = plsc->vpwxma - plsc->vpwxmi;
00052     dy = plsc->vpwyma - plsc->vpwymi;
00053 
00054     plsc->wpxscl = (plsc->vppxma - plsc->vppxmi) / dx;
00055     plsc->wpxoff = (xmax * plsc->vppxmi - xmin * plsc->vppxma) / dx;
00056     plsc->wpyscl = (plsc->vppyma - plsc->vppymi) / dy;
00057     plsc->wpyoff = (ymax * plsc->vppymi - ymin * plsc->vppyma) / dy;
00058 
00059     mmxmi = plP_dcmmx(plsc->vpdxmi);
00060     mmxma = plP_dcmmx(plsc->vpdxma);
00061     mmymi = plP_dcmmy(plsc->vpdymi);
00062     mmyma = plP_dcmmy(plsc->vpdyma);
00063 
00064 /* Set transformation variables for world coordinates to mm */
00065 
00066     plsc->wmxscl = (mmxma - mmxmi) / dx;
00067     plsc->wmxoff = (xmax * mmxmi - xmin * mmxma) / dx;
00068     plsc->wmyscl = (mmyma - mmymi) / dy;
00069     plsc->wmyoff = (ymax * mmymi - ymin * mmyma) / dy;
00070 
00071 /* Set transformation variables for world coordinates to device coords */
00072 
00073     plsc->wdxscl = plsc->wmxscl * plsc->xpmm / (plsc->phyxma - plsc->phyxmi);
00074     plsc->wdxoff = plsc->wmxoff * plsc->xpmm / (plsc->phyxma - plsc->phyxmi);
00075     plsc->wdyscl = plsc->wmyscl * plsc->ypmm / (plsc->phyyma - plsc->phyymi);
00076     plsc->wdyoff = plsc->wmyoff * plsc->ypmm / (plsc->phyyma - plsc->phyymi);
00077 
00078 /* Register plot window attributes */
00079 
00080     w.dxmi = plsc->vpdxmi;
00081     w.dxma = plsc->vpdxma;
00082     w.dymi = plsc->vpdymi;
00083     w.dyma = plsc->vpdyma;
00084 
00085     w.wxmi = plsc->vpwxmi;
00086     w.wxma = plsc->vpwxma;
00087     w.wymi = plsc->vpwymi;
00088     w.wyma = plsc->vpwyma;
00089 
00090     plP_swin(&w);
00091 
00092 /* Go to level 3 */
00093 
00094     plsc->level = 3;
00095 }
00096 
00097 /*--------------------------------------------------------------------------*\
00098  * void plw3d()
00099  *
00100  * Set up a window for three-dimensional plotting. The data are mapped
00101  * into a box with world coordinate size "basex" by "basey" by "height",
00102  * with the base being symmetrically positioned about zero. Thus
00103  * the mapping between data 3-d and world 3-d coordinates is given by:
00104  *
00105  *   x = xmin   =>   wx = -0.5*basex
00106  *   x = xmax   =>   wx =  0.5*basex
00107  *   y = ymin   =>   wy = -0.5*basey
00108  *   y = ymax   =>   wy =  0.5*basey
00109  *   z = zmin   =>   wz =  0.0
00110  *   z = zmax   =>   wz =  height
00111  *
00112  * The world coordinate box is then viewed from position "alt"-"az",
00113  * measured in degrees. For proper operation, 0 <= alt <= 90 degrees,
00114  * but az can be any value.
00115 \*--------------------------------------------------------------------------*/
00116 
00117 MZ_DLLEXPORT
00118 void
00119 c_plw3d(PLFLT basex, PLFLT basey, PLFLT height, PLFLT xmin0,
00120        PLFLT xmax0, PLFLT ymin0, PLFLT ymax0, PLFLT zmin0,
00121        PLFLT zmax0, PLFLT alt, PLFLT az)
00122 {
00123     PLFLT xmin, xmax, ymin, ymax, zmin, zmax, d;
00124     PLFLT cx, cy, saz, caz, salt, calt, zscale;
00125 
00126     if (plsc->level < 3) {
00127        plabort("plw3d: Please set up 2-d window first");
00128        return;
00129     }
00130     if (basex <= 0.0 || basey <= 0.0 || height <= 0.0) {
00131        plabort("plw3d: Invalid world coordinate boxsize");
00132        return;
00133     }
00134     if (xmin0 == xmax0 || ymin0 == ymax0 || zmin0 == zmax0) {
00135        plabort("plw3d: Invalid axis range");
00136        return;
00137     }
00138     if (alt < 0.0 || alt > 90.0) {
00139        plabort("plw3d: Altitude must be between 0 and 90 degrees");
00140        return;
00141     }
00142 
00143     d = 1.0e-5 * (xmax0 - xmin0);
00144     xmax = xmax0 + d;
00145     xmin = xmin0 - d;
00146     d = 1.0e-5 * (ymax0 - ymin0);
00147     ymax = ymax0 + d;
00148     ymin = ymin0 - d;
00149     d = 1.0e-5 * (zmax0 - zmin0);
00150     zmax = zmax0 + d;
00151     zmin = zmin0 - d;
00152     cx = basex / (xmax - xmin);
00153     cy = basey / (ymax - ymin);
00154     zscale = height / (zmax - zmin);
00155     saz = sin(dtr * az);
00156     caz = cos(dtr * az);
00157     salt = sin(dtr * alt);
00158     calt = cos(dtr * alt);
00159 
00160     plsc->domxmi = xmin;
00161     plsc->domxma = xmax;
00162     plsc->domymi = ymin;
00163     plsc->domyma = ymax;
00164     plsc->zzscl = zscale;
00165     plsc->ranmi = zmin;
00166     plsc->ranma = zmax;
00167 
00168     plsc->base3x = basex;
00169     plsc->base3y = basey;
00170     plsc->basecx = 0.5 * (xmin + xmax);
00171     plsc->basecy = 0.5 * (ymin + ymax);
00172 
00173     plsc->cxx = cx * caz;
00174     plsc->cxy = -cy * saz;
00175     plsc->cyx = cx * saz * salt;
00176     plsc->cyy = cy * caz * salt;
00177     plsc->cyz = zscale * calt;
00178 }