home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / plot3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  4.0 KB  |  138 lines

  1. /* Plots a 3-d representation of the function z[x][y]. The x values */
  2. /* are stored as x[0..nx-1], the y values as y[0..ny-1], and the */
  3. /* z values are in the 2-d array z[][0..ly-1]. The integer "opt" */
  4. /* specifies: */
  5. /*  opt = 1:  Draw lines parallel to x-axis */
  6. /*  opt = 2:  Draw lines parallel to y-axis */
  7. /*  opt = 3:  Draw lines parallel to both axes */
  8.  
  9. #include "plplot.h"
  10. #include <math.h>
  11.  
  12. #ifdef PLSTDC
  13. #include <stdlib.h>
  14. #else
  15. extern char *malloc();
  16. extern void free();
  17. #endif
  18.  
  19. extern PLINT *oldhiview;
  20. PLINT zbackflag=0, zbcolor;
  21. PLFLT zticksp;
  22.  
  23. void plot3d(x,y,z,ly,nx,ny,opt,side)
  24. PLINT ly, nx, ny, opt, side;
  25. PLFLT *x, *y, *z;
  26. {
  27.       PLINT b, color, font;
  28.       PLFLT cxx, cxy, cyx, cyy, cyz;
  29.       PLINT init;
  30.       PLINT *work;
  31.       PLINT i, ix, iy;
  32.       PLINT level;
  33.  
  34.       glev(&level);
  35.       if (level < 3) plexit("Please set up window before calling plot3d");
  36.  
  37.       if (opt<1 || opt>3) plexit("Bad option in plot3d");
  38.       if (nx<=0 || ny<=0 || ly<ny) plexit("Bad array dimensions in plot3d.");
  39.  
  40.       /* Check that points in x and in y are strictly increasing */
  41.  
  42.       for (i=0; i<nx-1; i++)
  43.         if (x[i]>=x[i+1]) plexit("X array must be strictly increasing in plot3d");
  44.  
  45.       for (i=0; i<ny-1; i++)
  46.         if (y[i]>=y[i+1]) plexit("Y array must be strictly increasing in plot3d");
  47.  
  48.       work = (PLINT *)malloc(4*max(nx,ny)*sizeof(PLINT));
  49.       if(!work)
  50.          plexit("Out of memory in plot3d.");
  51.       b = 2*max(nx,ny)+1;
  52.       gw3wc(&cxx,&cxy,&cyx,&cyy,&cyz);
  53.       init = 1;
  54.  
  55.       if (cxx >= 0.0 && cxy <= 0.0) {
  56.         if (opt != 2) {
  57.           for (iy=2; iy<=ny; iy++)  {
  58.             plt3zz(1,iy,1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  59.             init = 0;
  60.           }
  61.         }
  62.         else  {
  63.           plt3zz(1,ny,1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  64.           init = 0;
  65.         }
  66.         if (opt != 1)
  67.           for (ix=1; ix<=nx-1; ix++)
  68.             plt3zz(ix,ny,1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  69.         else
  70.           plt3zz(1,ny,1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  71.       }
  72.       else if (cxx <= 0.0 && cxy <= 0.0) {
  73.         if (opt != 1) {
  74.           for (ix=2; ix<=nx; ix++) {
  75.             plt3zz(ix,ny,-1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  76.             init = 0;
  77.           }
  78.         }
  79.         else  {
  80.           plt3zz(nx,ny,-1,-1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  81.           init = 0;
  82.         }
  83.         if (opt != 2)
  84.           for (iy=ny; iy>=2; iy--)
  85.             plt3zz(nx,iy,-1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  86.         else
  87.           plt3zz(nx,ny,-1,-1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  88.       }
  89.       else if (cxx <= 0.0 && cxy >= 0.0) {
  90.         if (opt != 2) {
  91.           for (iy=ny-1; iy>=1; iy--) {
  92.             plt3zz(nx,iy,-1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  93.             init = 0;
  94.           }
  95.         }
  96.         else {
  97.           plt3zz(nx,1,-1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  98.           init = 0;
  99.         }
  100.         if (opt != 1)
  101.           for (ix=nx; ix>=2; ix--)
  102.             plt3zz(ix,1,-1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  103.         else
  104.           plt3zz(nx,1,-1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  105.       }
  106.       else if (cxx >= 0.0 && cxy >= 0.0) {
  107.         if (opt != 1) {
  108.           for (ix=nx-1; ix>=1; ix--) {
  109.             plt3zz(ix,1,1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  110.             init = 0;
  111.           }
  112.         }
  113.         else  {
  114.           plt3zz(1,1,1,1,opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  115.           init = 0;
  116.         }
  117.         if (opt != 2)
  118.           for (iy=1; iy<=ny-1; iy++)
  119.             plt3zz(1,iy,1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  120.         else
  121.           plt3zz(1,1,1,1,-opt,init,x,y,z,ly,nx,ny,&work[0],&work[b-1]);
  122.       }
  123.  
  124.       free((VOID *)work);
  125.  
  126.       if(side)
  127.          plside3a(x,y,z,ly,nx,ny,opt);
  128.  
  129.       if(zbackflag) {
  130.          gatt(&font,&color);
  131.          plcol(zbcolor);
  132.          plgrid3a(zticksp);
  133.          plcol(color);
  134.       }
  135.  
  136.       free((VOID *)oldhiview);
  137. }
  138.