home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum23.lzh / f23b / SOFTWARE / PDRAW / plotps.c < prev    next >
Text File  |  1992-01-15  |  35KB  |  1,024 lines

  1. /***    plotps.c - for POSTSCRIPT plotting   ***/
  2.  
  3. #include <stdio.h>
  4. #include <strings.h>
  5. #include <math.h>
  6. #include "header.h"
  7.  
  8. initps(ips)
  9. FILE *ips;
  10. {
  11.    extern double scale;
  12.    char   time[MAXCHAR];
  13.    float d;
  14.  
  15.    d = 6*scale;
  16.  
  17.    /* begin postscript output */
  18.    fprintf(ips,"%c!\n",'%');
  19. #ifdef GS_OK
  20.    fprintf(ips,"/defFontSizeTop %6.2f def\n",25*scale);
  21.    fprintf(ips,"/defFontSizeSide %6.2f def\n",20*scale);
  22.    fprintf(ips,"/defFontSizeAxes %6.2f def\n",15*scale);
  23.  
  24.    fprintf(ips,"/UPJ  {} def\n");
  25.    fprintf(ips,"/MIJT  {0 defFontSizeTop -2 div rmoveto} def\n");
  26.    fprintf(ips,"/BOJT  {0 defFontSizeTop neg rmoveto} def\n");
  27.    fprintf(ips,"/MIJS  {0 defFontSizeSide -2 div rmoveto} def\n");
  28.    fprintf(ips,"/BOJS  {0 defFontSizeSide neg rmoveto} def\n");
  29.    fprintf(ips,"/MIJA  {0 defFontSizeAxes -2 div rmoveto} def\n");
  30.    fprintf(ips,"/BOJA  {0 defFontSizeAxes neg rmoveto} def\n");
  31.  
  32.    fprintf(ips,"/LEJ  {} def\n");
  33.    fprintf(ips,"/CEJ  {dup stringwidth pop -2 div 0 rmoveto} def\n");
  34.    fprintf(ips,"/RIJ  {dup stringwidth pop neg 0 rmoveto} def\n");
  35. #endif
  36.    fprintf(ips,"/MoveDraw {lineto currentpoint stroke moveto} def\n");
  37.  
  38.    fprintf(ips,"/markA { %6.2f %6.2f rmoveto\n",d/2,-d/2);
  39.    fprintf(ips,"         %6.2f %6.2f rlineto\n",0.0,  d);
  40.    fprintf(ips,"         %6.2f %6.2f rlineto\n", -d,0.0);
  41.    fprintf(ips,"         %6.2f %6.2f rlineto\n",0.0, -d);
  42.    fprintf(ips,"         %6.2f %6.2f rlineto\n",  d,0.0);
  43.    fprintf(ips,"         gsave\n");
  44.    fprintf(ips,"         1.0 setgray fill\n");
  45.    fprintf(ips,"         grestore\n");
  46.    fprintf(ips,"         stroke } def\n");
  47.  
  48.    fprintf(ips,"/markB { %6.2f %6.2f rmoveto\n",d/2,-d/2);
  49.    fprintf(ips,"         %6.2f %6.2f rlineto\n",0.0,  d);
  50.    fprintf(ips,"         %6.2f %6.2f rlineto\n", -d,0.0);
  51.    fprintf(ips,"         %6.2f %6.2f rlineto\n",0.0, -d);
  52.    fprintf(ips,"         %6.2f %6.2f rlineto\n",  d,0.0);
  53.    fprintf(ips,"         gsave\n");
  54.    fprintf(ips,"         0.5 setgray fill\n");
  55.    fprintf(ips,"         grestore\n");
  56.    fprintf(ips,"         stroke } def\n");
  57.  
  58.    fprintf(ips,"/markC { %6.2f %6.2f rmoveto\n",d/2,-d/2);
  59.    fprintf(ips,"         %6.2f %6.2f rlineto\n",0.0,  d);
  60.    fprintf(ips,"         %6.2f %6.2f rlineto\n", -d,0.0);
  61.    fprintf(ips,"         %6.2f %6.2f rlineto\n",0.0, -d);
  62.    fprintf(ips,"         %6.2f %6.2f rlineto\n",  d,0.0);
  63.    fprintf(ips,"         gsave\n");
  64.    fprintf(ips,"         0.0 setgray fill\n");
  65.    fprintf(ips,"         grestore\n");
  66.    fprintf(ips,"         stroke } def\n");
  67.  
  68.    fprintf(ips,"/markD { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
  69.    fprintf(ips,"         %6.2f %6.2f rlineto\n", d/2, d/2);
  70.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2, d/2);
  71.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2,-d/2);
  72.    fprintf(ips,"         %6.2f %6.2f rlineto\n", d/2,-d/2);
  73.    fprintf(ips,"         gsave\n");
  74.    fprintf(ips,"         1.0 setgray fill\n");
  75.    fprintf(ips,"         grestore\n");
  76.    fprintf(ips,"         stroke } def\n");
  77.  
  78.    fprintf(ips,"/markE { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
  79.    fprintf(ips,"         %6.2f %6.2f rlineto\n", d/2, d/2);
  80.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2, d/2);
  81.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2,-d/2);
  82.    fprintf(ips,"         %6.2f %6.2f rlineto\n", d/2,-d/2);
  83.    fprintf(ips,"         gsave\n");
  84.    fprintf(ips,"         0.5 setgray fill\n");
  85.    fprintf(ips,"         grestore\n");
  86.    fprintf(ips,"         stroke } def\n");
  87.  
  88.    fprintf(ips,"/markF { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
  89.    fprintf(ips,"         %6.2f %6.2f rlineto\n", d/2, d/2);
  90.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2, d/2);
  91.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2,-d/2);
  92.    fprintf(ips,"         %6.2f %6.2f rlineto\n", d/2,-d/2);
  93.    fprintf(ips,"         gsave\n");
  94.    fprintf(ips,"         0.0 setgray fill\n");
  95.    fprintf(ips,"         grestore\n");
  96.    fprintf(ips,"         stroke } def\n");
  97.  
  98.    fprintf(ips,"/markG { %6.2f %6.2f rmoveto\n",-0.50*d,-0.22*d);
  99.    fprintf(ips,"         %6.2f %6.2f rlineto\n",      d,    0.0);
  100.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
  101.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
  102.    fprintf(ips,"         gsave\n");
  103.    fprintf(ips,"         1.0 setgray fill\n");
  104.    fprintf(ips,"         grestore\n");
  105.    fprintf(ips,"         stroke } def\n");
  106.  
  107.    fprintf(ips,"/markH { %6.2f %6.2f rmoveto\n",-0.50*d,-0.22*d);
  108.    fprintf(ips,"         %6.2f %6.2f rlineto\n",      d,    0.0);
  109.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
  110.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
  111.    fprintf(ips,"         gsave\n");
  112.    fprintf(ips,"         0.5 setgray fill\n");
  113.    fprintf(ips,"         grestore\n");
  114.    fprintf(ips,"         stroke } def\n");
  115.  
  116.    fprintf(ips,"/markI { %6.2f %6.2f rmoveto\n",-0.50*d,-0.22*d);
  117.    fprintf(ips,"         %6.2f %6.2f rlineto\n",      d,    0.0);
  118.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
  119.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
  120.    fprintf(ips,"         gsave\n");
  121.    fprintf(ips,"         0.0 setgray fill\n");
  122.    fprintf(ips,"         grestore\n");
  123.    fprintf(ips,"         stroke } def\n");
  124.  
  125.    fprintf(ips,"/markJ { %6.2f %6.2f rmoveto\n",-0.50*d, 0.22*d);
  126.    fprintf(ips,"         %6.2f %6.2f rlineto\n",      d,    0.0);
  127.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
  128.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
  129.    fprintf(ips,"         gsave\n");
  130.    fprintf(ips,"         1.0 setgray fill\n");
  131.    fprintf(ips,"         grestore\n");
  132.    fprintf(ips,"         stroke } def\n");
  133.  
  134.    fprintf(ips,"/markK { %6.2f %6.2f rmoveto\n",-0.50*d, 0.22*d);
  135.    fprintf(ips,"         %6.2f %6.2f rlineto\n",      d,    0.0);
  136.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
  137.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
  138.    fprintf(ips,"         gsave\n");
  139.    fprintf(ips,"         0.5 setgray fill\n");
  140.    fprintf(ips,"         grestore\n");
  141.    fprintf(ips,"         stroke } def\n");
  142.  
  143.    fprintf(ips,"/markL { %6.2f %6.2f rmoveto\n",-0.50*d, 0.22*d);
  144.    fprintf(ips,"         %6.2f %6.2f rlineto\n",      d,    0.0);
  145.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
  146.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
  147.    fprintf(ips,"         gsave\n");
  148.    fprintf(ips,"         0.0 setgray fill\n");
  149.    fprintf(ips,"         grestore\n");
  150.    fprintf(ips,"         stroke } def\n");
  151.  
  152.    fprintf(ips,"/markM { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
  153.    fprintf(ips,"         %6.2f %6.2f rlineto\n", 0.0,   d);
  154.    fprintf(ips,"         %6.2f %6.2f rmoveto\n",-d/2,-d/2);
  155.    fprintf(ips,"         %6.2f %6.2f rlineto\n",   d, 0.0);
  156.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2, 0.0);
  157.    fprintf(ips,"         currentpoint %f 0 360 arc \n",d/2);
  158.    fprintf(ips,"         gsave\n");
  159.    fprintf(ips,"         1.0 setgray fill\n");
  160.    fprintf(ips,"         grestore\n");
  161.    fprintf(ips,"         stroke } def\n");
  162.  
  163.    fprintf(ips,"/markN { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
  164.    fprintf(ips,"         %6.2f %6.2f rlineto\n", 0.0,   d);
  165.    fprintf(ips,"         %6.2f %6.2f rmoveto\n",-d/2,-d/2);
  166.    fprintf(ips,"         %6.2f %6.2f rlineto\n",   d, 0.0);
  167.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2, 0.0);
  168.    fprintf(ips,"         currentpoint %f 0 360 arc \n",d/2);
  169.    fprintf(ips,"         gsave\n");
  170.    fprintf(ips,"         0.5 setgray fill\n");
  171.    fprintf(ips,"         grestore\n");
  172.    fprintf(ips,"         stroke } def\n");
  173.  
  174.    fprintf(ips,"/markO { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
  175.    fprintf(ips,"         %6.2f %6.2f rlineto\n", 0.0,   d);
  176.    fprintf(ips,"         %6.2f %6.2f rmoveto\n",-d/2,-d/2);
  177.    fprintf(ips,"         %6.2f %6.2f rlineto\n",   d, 0.0);
  178.    fprintf(ips,"         %6.2f %6.2f rlineto\n",-d/2, 0.0);
  179.    fprintf(ips,"         currentpoint %f 0 360 arc \n",d/2);
  180.    fprintf(ips,"         gsave\n");
  181.    fprintf(ips,"         0.0 setgray fill\n");
  182.    fprintf(ips,"         grestore\n");
  183.    fprintf(ips,"         stroke } def\n");
  184.  
  185.    fprintf(ips,"/markP { %6.2f %6.2f rmoveto\n",-d/2,-d/2);
  186.    fprintf(ips,"         %6.2f %6.2f rlineto\n",   d,   d);
  187.    fprintf(ips,"         %6.2f %6.2f rmoveto\n",  -d, 0.0);
  188.    fprintf(ips,"         %6.2f %6.2f rlineto\n",   d,  -d);
  189.    fprintf(ips,"         stroke } def\n");
  190.  
  191.    fprintf(ips,"/markQ { %6.2f %6.2f rmoveto\n",-0.5,0.0);
  192.    fprintf(ips,"         %6.2f %6.2f rlineto\n", 1.0,0.0);
  193.    fprintf(ips,"         stroke } def\n");
  194.  
  195.    /* print the time */
  196. #ifdef GS_OK
  197.    get_localtime(time);
  198.    fprintf(ips,"/Times-Bold findfont\n");
  199.    fprintf(ips,"10 scalefont setfont\n");
  200.    fprintf(ips,"%6.2f %6.2f moveto ",30.0,750.0);
  201.    fprintf(ips,"(%s) show\n",time);
  202. #endif
  203. }
  204.  
  205. /* draw the toplabel and the z-axis */
  206. axesps(ips)
  207. FILE *ips;
  208. {
  209.    xyzdata  transform_point();
  210.    extern   double xmin, ymin, zmin, xmax, ymax, zmax;
  211.    xyzdata  point[4], newpt[4];
  212.    double   minx;
  213.    int      i, mini;
  214.  
  215.    pxmin = 1.0*PSMIN;
  216.    pymin = 1.0*PSMIN;
  217.    pxmax = scale*PSMAX;
  218.    pymax = scale*PSMAX;
  219.  
  220.    /* Top Label */
  221. #ifdef GS_OK
  222.    fprintf(ips,"/Times-Bold findfont\n");
  223.    fprintf(ips,"defFontSizeTop scalefont setfont\n");
  224.    fprintf(ips,"  %6.2f %6.2f moveto ",0.5*(pxmax+pxmin),pymax+25*scale);
  225.    fprintf(ips,"(%s) UPJ CEJ show\n",toplabel);
  226. #endif
  227.    /*
  228.     * choose which z-axis to draw
  229.     * There are 4 lines on the z-axis containing the 4 points below
  230.     */
  231.    point[0].x = xmin;   point[0].y = ymin;   point[0].z = zmin;
  232.    point[1].x = xmin;   point[1].y = ymax;   point[1].z = zmin;
  233.    point[2].x = xmax;   point[2].y = ymin;   point[2].z = zmin;
  234.    point[3].x = xmax;   point[3].y = ymax;   point[3].z = zmin;
  235.  
  236.    /* transform the 4 points */
  237.    for (i=0; i<4; i++)
  238.       newpt[i] = transform_point(point[i],view_transfo);
  239.  
  240.    /*
  241.     * The line drawn will contain the smallest x-value of the
  242.     * 4 points decribed above (on the zplane)
  243.     */
  244.    minx = newpt[0].x; mini = 0;
  245.    for (i=0; i<4; i++)
  246.       if (newpt[i].x < minx) {
  247.          minx = newpt[i].x;
  248.          mini = i;
  249.       }
  250.  
  251.    /* draw the z-axis */
  252.    if (mini == 0)
  253.       drawPS_zaxis(ips,xmin,ymin,zmin,xmin,ymin,zmax);
  254.    else if (mini == 1)
  255.       drawPS_zaxis(ips,xmin,ymax,zmin,xmin,ymax,zmax);
  256.    else if (mini == 2)
  257.       drawPS_zaxis(ips,xmax,ymin,zmin,xmax,ymin,zmax);
  258.    else if (mini == 3)
  259.       drawPS_zaxis(ips,xmax,ymax,zmin,xmax,ymax,zmax);
  260.  
  261.    /* draw the back planes now */
  262.    back_axesPS(ips);
  263. }
  264.  
  265. /* draw the axes that are further from the viewer */
  266. back_axesPS(ips)
  267. FILE *ips;
  268. {
  269.    /* Draw the plane intersecting x-axis */
  270.    drawPS_back_xplane(ips);
  271.  
  272.    /* Draw the plane intersecting y-axis */
  273.    drawPS_back_yplane(ips);
  274.  
  275.    /* Draw the plane intersecting z-axis */
  276.    drawPS_back_zplane(ips);
  277. }
  278.  
  279. /* draw the axes that are closer to the viewer */
  280. front_axesPS(ips)
  281. FILE *ips;
  282. {
  283.    /* Draw the plane intersecting x-axis */
  284.    drawPS_front_xplane(ips);
  285.  
  286.    /* Draw the plane intersecting y-axis */
  287.    drawPS_front_yplane(ips);
  288.  
  289.    /* Draw the plane intersecting z-axis */
  290.    drawPS_front_zplane(ips);
  291. }
  292.  
  293. /* Draw the axis - parallel to X */
  294. drawPS_xaxis(ips,xa,ya,za,xb,yb,zb)
  295. FILE *ips;
  296. double xa,ya,za,xb,yb,zb;
  297. {
  298.    xyzdata  midpoint();
  299.    xyzdata  transform_point();
  300.    double   find_angle();
  301.    char     *sprintf(), *strcpy();
  302.    extern   double   xmin, ymin, zmin, xmax, ymax, zmax;
  303.    xyzdata  midpt;
  304.    int      i;
  305.    char     text[100];
  306.    double   angle, xtmp, ratio, dl;
  307.  
  308.    /*
  309.     * xa = xmin    xb = xmax
  310.     * ya = yb = (ymin ? ymax)
  311.     * za = zb = (zmin ? zmax)
  312.     */
  313.  
  314.    /* midpoint of the line */
  315.    dl = (ya == ymin) ? -0.3*(ymax-ymin) : 0.3*(ymax-ymin);
  316.    midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
  317.    angle = find_angle(xa,ya,za,xb,yb,zb);
  318.  
  319.    /* X-axis Label */
  320. #ifdef GS_OK
  321.    fprintf(ips,"/Times-Bold findfont\n");
  322.    fprintf(ips,"defFontSizeSide scalefont setfont\n");
  323.    fprintf(ips,"/Xlabel {");
  324.    fprintf(ips,"0 0 moveto ");
  325.    fprintf(ips,"(%s) BOJS CEJ show } def\n",xlabel);
  326.    fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
  327.    fprintf(ips,"%6.2f rotate\n  Xlabel\n  %6.2f rotate\n",angle,-angle); 
  328.    fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
  329. #endif
  330.    /* Tick Marks on the X-axis */
  331.    /* Draw the tick marks */
  332.    for (i=0; i<=xticks; i++) {
  333.       ratio = i/(double)xticks;
  334.       xtmp  = xa + (xb-xa)*ratio;
  335.       draw_PSline(ips,xtmp,ya,za,xtmp,ya+0.5*dl,za,2);
  336.       midpt.x = xtmp;
  337.       midpt.y = ya+0.6*dl;
  338.       midpt.z = za;
  339.       midpt = transform_point(midpt,view_transfo);
  340.       sprintf(text,"%.3g",xtmp);
  341.  
  342. #ifdef GS_OK
  343.       fprintf(ips,"/Times-Roman findfont\n");
  344.       fprintf(ips,"defFontSizeAxes scalefont setfont\n");
  345.       fprintf(ips,"/label {");
  346.       fprintf(ips,"0 0 moveto ");
  347.       fprintf(ips,"(%s) BOJA CEJ show } def\n",text);
  348.       fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
  349.       /*
  350.       fprintf(ips,"%6.2f rotate\nlabel\n  %6.2f rotate\n",angle,-angle); 
  351.       */
  352.       fprintf(ips,"label\n"); 
  353.       fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
  354. #endif
  355.    }
  356. }
  357.  
  358. /* Draw the axis - parallel to Y */
  359. drawPS_yaxis(ips,xa,ya,za,xb,yb,zb)
  360. FILE *ips;
  361. double xa,ya,za,xb,yb,zb;
  362. {
  363.    xyzdata  midpoint();
  364.    xyzdata  transform_point();
  365.    char     *strcpy();
  366.    extern   double   xmin, ymin, zmin, xmax, ymax, zmax;
  367.    xyzdata  midpt;
  368.    int      i;
  369.    char     text[100];
  370.    double   angle, ytmp, ratio, dl;
  371.  
  372.    /*
  373.     * xa = xb = (xmin ? xmax)
  374.     * ya = ymin    yb = ymax
  375.     * za = zb = (zmin ? zmax)
  376.     */
  377.  
  378.    /* midpoint of the line */
  379.    dl = (xa == xmin) ? -0.3*(xmax-xmin) : 0.3*(xmax-xmin);
  380.    midpt = midpoint(xa+dl,ya,za,xb+dl,yb,zb,0.5);
  381.    angle = find_angle(xa,ya,za,xb,yb,zb);
  382.  
  383.    /* Y-axis Label */
  384. #ifdef GS_OK
  385.    fprintf(ips,"/Times-Bold findfont\n");
  386.    fprintf(ips,"defFontSizeSide scalefont setfont\n");
  387.    fprintf(ips,"/Ylabel {");
  388.    fprintf(ips,"0 0 moveto ");
  389.    fprintf(ips,"(%s) BOJS CEJ show } def\n",ylabel);
  390.    fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
  391.    fprintf(ips,"%6.2f rotate\n  Ylabel\n  %6.2f rotate\n",angle,-angle); 
  392.    fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
  393. #endif
  394.  
  395.    /* Draw the tick marks */
  396.    for (i=0; i<=yticks; i++) {
  397.       ratio = i/(double)yticks;
  398.       ytmp  = ya + (yb-ya)*ratio;
  399.       draw_PSline(ips,xa,ytmp,za,xa+0.5*dl,ytmp,za,2);
  400.       midpt.x = xa + 0.6*dl;
  401.       midpt.y = ytmp;
  402.       midpt.z = za;
  403.       midpt = transform_point(midpt,view_transfo);
  404.       sprintf(text,"%.3g",ytmp);
  405.  
  406. #ifdef GS_OK
  407.       fprintf(ips,"/Times-Roman findfont\n");
  408.       fprintf(ips,"defFontSizeAxes scalefont setfont\n");
  409.       fprintf(ips,"/label {");
  410.       fprintf(ips,"0 0 moveto ");
  411.       fprintf(ips,"(%s) BOJA CEJ show } def\n",text);
  412.       fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
  413.       /*
  414.       fprintf(ips,"%6.2f rotate\nlabel\n  %6.2f rotate\n",angle,-angle); 
  415.       */
  416.       fprintf(ips,"label\n"); 
  417.       fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
  418. #endif
  419.    }
  420. }
  421.  
  422. /* Draw the axis - parallel to Z */
  423. drawPS_zaxis(ips,xa,ya,za,xb,yb,zb)
  424. FILE *ips;
  425. double xa,ya,za,xb,yb,zb;
  426. {
  427.    xyzdata  midpoint();
  428.    xyzdata  transform_point();
  429.    char     *strcpy();
  430.    extern   double   xmin, ymin, zmin, xmax, ymax, zmax;
  431.    xyzdata  midpt;
  432.    int      i;
  433.    char     text[100];
  434.    double   ztmp, ratio, dl;
  435.  
  436.    /*
  437.     * xa = xb = (xmin ? xmax)
  438.     * ya = yb = (ymin ? ymax)
  439.     * za = zmin    zb = zmax
  440.     */
  441.  
  442.    /* midpoint of the line */
  443.    dl = (ya == ymin) ? -0.3*(ymax-ymin) : 0.3*(ymax-ymin);
  444.    midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
  445.  
  446.    /* Z-axis Label */
  447. #ifdef GS_OK
  448.    fprintf(ips,"/Times-Bold findfont\n");
  449.    fprintf(ips,"defFontSizeSide scalefont setfont\n");
  450.    fprintf(ips,"/Zlabel {");
  451.    fprintf(ips,"0 0 moveto ");
  452.    fprintf(ips,"(%s) UPJ CEJ show } def\n",zlabel);
  453.    fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
  454.    fprintf(ips,"90 rotate\n  Zlabel\n  -90 rotate\n"); 
  455.    fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
  456. #endif
  457.    /* Draw the tick marks */
  458.    for (i=0; i<=zticks; i++) {
  459.       ratio = i/(double)zticks;
  460.       ztmp  = za + (zb-za)*ratio;
  461.       draw_PSline(ips,xa,ya,ztmp,xa,ya+0.5*dl,ztmp,2);
  462.       midpt.x = xa;
  463.       midpt.y = ya+0.6*dl;
  464.       midpt.z = ztmp;
  465.       midpt = transform_point(midpt,view_transfo);
  466.       sprintf(text,"%.3g",ztmp);
  467.  
  468. #ifdef GS_OK
  469.       fprintf(ips,"/Times-Roman findfont\n");
  470.       fprintf(ips,"defFontSizeAxes scalefont setfont\n");
  471.       fprintf(ips,"/label {");
  472.       fprintf(ips,"0 0 moveto ");
  473.       fprintf(ips,"(%s) UPJ CEJ show } def\n",text);
  474.       fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
  475.       fprintf(ips,"90 rotate\nlabel\n  -90 rotate\n"); 
  476.       fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
  477. #endif
  478.    }
  479. }
  480.  
  481. /* draw the back x-plane */
  482. drawPS_back_xplane(ips)
  483. FILE *ips;
  484. {
  485.    xyzdata transform_point();
  486.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  487.    xyzdata point1, point2, point[5], newpt[5];
  488.    int     i;
  489.  
  490.    /* 2 planes intersecting the x-axis */
  491.    point1.x = xmin + 0.0*(xmax-xmin);
  492.    point1.y = ymin + 0.5*(ymax-ymin);
  493.    point1.z = zmin + 0.5*(zmax-zmin);
  494.    point1   = transform_point(point1,view_transfo);
  495.    point2.x = xmin + 1.0*(xmax-xmin);
  496.    point2.y = ymin + 0.5*(ymax-ymin);
  497.    point2.z = zmin + 0.5*(zmax-zmin);
  498.    point2   = transform_point(point2,view_transfo);
  499.  
  500.    if (point1.z > point2.z) {
  501.       /* draw the lesser - point2 contains xmax */
  502.       point[0].x = xmax;  point[0].y = ymin;  point[0].z = zmin;
  503.       point[1].x = xmax;  point[1].y = ymin;  point[1].z = zmax;
  504.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  505.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  506.       /* repeat point 1 */
  507.       point[4].x = xmax;  point[4].y = ymin;  point[4].z = zmin;
  508.    } else {
  509.       /* draw the lesser - point1 contains xmin */
  510.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  511.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  512.       point[2].x = xmin;  point[2].y = ymax;  point[2].z = zmax;
  513.       point[3].x = xmin;  point[3].y = ymax;  point[3].z = zmin;
  514.       /* repeat point 1 */
  515.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  516.    }
  517.  
  518.    /* rescale the points */
  519.    for (i=0; i<5; i++) {
  520.       newpt[i] = transform_point(point[i],view_transfo);
  521.    }
  522.  
  523.    /* draw and fill the polygon */
  524.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  525.    for (i=1; i<5; i++) 
  526.        fprintf(ips,"  %8.2f %8.2f lineto\n",newpt[i].x,newpt[i].y);
  527.    fprintf(ips,"closepath\n 1.00 setgray fill\n 0.0 setgray\n");
  528.  
  529.    /* draw the polygon outline */
  530.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  531.    for (i=1; i<5; i++) 
  532.        fprintf(ips,"  %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
  533. }
  534.  
  535. /* draw the back y-plane */
  536. drawPS_back_yplane(ips)
  537. FILE *ips;
  538. {
  539.    xyzdata transform_point();
  540.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  541.    xyzdata point1, point2, point[5], newpt[5];
  542.    int     i;
  543.  
  544.    /* 2 planes intersecting the x-axis */
  545.    point1.x = xmin + 0.5*(xmax-xmin);
  546.    point1.y = ymin + 0.0*(ymax-ymin);
  547.    point1.z = zmin + 0.5*(zmax-zmin);
  548.    point1   = transform_point(point1,view_transfo);
  549.    point2.x = xmin + 0.5*(xmax-xmin);
  550.    point2.y = ymin + 1.0*(ymax-ymin);
  551.    point2.z = zmin + 0.5*(zmax-zmin);
  552.    point2   = transform_point(point2,view_transfo);
  553.  
  554.    if (point1.z > point2.z) {
  555.       /* draw the lesser - point2 contains ymax */
  556.       point[0].x = xmin;  point[0].y = ymax;  point[0].z = zmin;
  557.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  558.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  559.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  560.       /* repeat point 1 */
  561.       point[4].x = xmin;  point[4].y = ymax;  point[4].z = zmin;
  562.    } else {
  563.       /* draw the lesser - point1 contains ymin */
  564.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  565.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  566.       point[2].x = xmax;  point[2].y = ymin;  point[2].z = zmax;
  567.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  568.       /* repeat point 1 */
  569.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  570.    }
  571.  
  572.    /* rescale the points */
  573.    for (i=0; i<5; i++) 
  574.       newpt[i] = transform_point(point[i],view_transfo);
  575.  
  576.    /* draw and fill the polygon */
  577.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  578.    for (i=1; i<5; i++) 
  579.        fprintf(ips,"  %8.2f %8.2f lineto\n",newpt[i].x,newpt[i].y);
  580.    fprintf(ips,"closepath\n 1.00 setgray fill\n 0.0 setgray\n");
  581.  
  582.    /* draw the polygon outline */
  583.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  584.    for (i=1; i<5; i++) 
  585.        fprintf(ips,"  %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
  586. }
  587.  
  588. /* draw the back z-plane */
  589. drawPS_back_zplane(ips)
  590. FILE *ips;
  591. {
  592.    xyzdata transform_point();
  593.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  594.    xyzdata point1, point2, point[5], newpt[5];
  595.    double  ztmp, miny;
  596.    int     i, mini;
  597.  
  598.    /* 2 planes intersecting the z-axis */
  599.    point1.x = xmin + 0.5*(xmax-xmin);
  600.    point1.y = ymin + 0.5*(ymax-ymin);
  601.    point1.z = zmin + 0.0*(zmax-zmin);
  602.    point1   = transform_point(point1,view_transfo);
  603.    point2.x = xmin + 0.5*(xmax-xmin);
  604.    point2.y = ymin + 0.5*(ymax-ymin);
  605.    point2.z = zmin + 1.0*(zmax-zmin);
  606.    point2   = transform_point(point2,view_transfo);
  607.  
  608.    if (point1.z > point2.z) {
  609.       /* draw the lesser - point2 contains zmax */
  610.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmax;
  611.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  612.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  613.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmax;
  614.       /* repeat point 1 */
  615.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmax;
  616.    } else {
  617.       /* draw the lesser - point1 contains zmin */
  618.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  619.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmin;
  620.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmin;
  621.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  622.       /* repeat point 1 */
  623.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  624.    }
  625.  
  626.    /* rescale the points */
  627.    for (i=0; i<5; i++) 
  628.       newpt[i] = transform_point(point[i],view_transfo);
  629.  
  630.    /* draw and fill the polygon */
  631.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  632.    for (i=1; i<5; i++) 
  633.        fprintf(ips,"  %8.2f %8.2f lineto\n",newpt[i].x,newpt[i].y);
  634.    fprintf(ips,"closepath\n 1.00 setgray fill\n 0.0 setgray\n");
  635.  
  636.    /* draw the polygon outline */
  637.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  638.    for (i=1; i<5; i++) 
  639.        fprintf(ips,"  %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
  640.  
  641.    /*
  642.     * The line drawn will contain the smallest y-value of the
  643.     * 4 points on the z-plane
  644.     */
  645.    miny = newpt[0].y; mini = 0;
  646.    for (i=0; i<4; i++)
  647.       if (newpt[i].y < miny) {
  648.          miny = newpt[i].y;
  649.          mini = i;
  650.       }
  651.    ztmp = (point1.z > point2.z) ? zmax : zmin;
  652.  
  653.    /* draw the x-axis first */
  654.    if (mini == 0 || mini == 3)
  655.       drawPS_xaxis(ips,xmin,ymin,ztmp,xmax,ymin,ztmp);
  656.    else if (mini == 1 || mini == 2)
  657.       drawPS_xaxis(ips,xmin,ymax,ztmp,xmax,ymax,ztmp);
  658.  
  659.    /* draw the y-axis first */
  660.    if (mini == 0 || mini == 1)
  661.       drawPS_yaxis(ips,xmin,ymin,ztmp,xmin,ymax,ztmp);
  662.    else if (mini == 2 || mini == 3)
  663.       drawPS_yaxis(ips,xmax,ymin,ztmp,xmax,ymax,ztmp);
  664. }
  665.  
  666. /* draw the front x-plane */
  667. drawPS_front_xplane(ips)
  668. FILE *ips;
  669. {
  670.    xyzdata transform_point();
  671.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  672.    xyzdata point1, point2, point[5], newpt[5];
  673.    int     i;
  674.  
  675.    /* 2 planes intersecting the x-axis */
  676.    point1.x = xmin + 0.0*(xmax-xmin);
  677.    point1.y = ymin + 0.5*(ymax-ymin);
  678.    point1.z = zmin + 0.5*(zmax-zmin);
  679.    point1   = transform_point(point1,view_transfo);
  680.    point2.x = xmin + 1.0*(xmax-xmin);
  681.    point2.y = ymin + 0.5*(ymax-ymin);
  682.    point2.z = zmin + 0.5*(zmax-zmin);
  683.    point2   = transform_point(point2,view_transfo);
  684.  
  685.    if (point1.z < point2.z) {
  686.       /* draw the greater - point2 contains xmax */
  687.       point[0].x = xmax;  point[0].y = ymin;  point[0].z = zmin;
  688.       point[1].x = xmax;  point[1].y = ymin;  point[1].z = zmax;
  689.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  690.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  691.       /* repeat point 1 */
  692.       point[4].x = xmax;  point[4].y = ymin;  point[4].z = zmin;
  693.    } else {
  694.       /* draw the greater - point1 contains xmin */
  695.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  696.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  697.       point[2].x = xmin;  point[2].y = ymax;  point[2].z = zmax;
  698.       point[3].x = xmin;  point[3].y = ymax;  point[3].z = zmin;
  699.       /* repeat point 1 */
  700.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  701.    }
  702.  
  703.    /* rescale the points */
  704.    for (i=0; i<5; i++) 
  705.       newpt[i] = transform_point(point[i],view_transfo);
  706.  
  707.    /* draw the polygon outline */
  708.    linetypps(ips,10);
  709.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  710.    for (i=1; i<5; i++) 
  711.        fprintf(ips,"  %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
  712.    linetypps(ips,0);
  713. }
  714.  
  715. /* draw the front y-plane */
  716. drawPS_front_yplane(ips)
  717. FILE *ips;
  718. {
  719.    xyzdata transform_point();
  720.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  721.    xyzdata point1, point2, point[5], newpt[5];
  722.    int     i;
  723.  
  724.    /* 2 planes intersecting the x-axis */
  725.    point1.x = xmin + 0.5*(xmax-xmin);
  726.    point1.y = ymin + 0.0*(ymax-ymin);
  727.    point1.z = zmin + 0.5*(zmax-zmin);
  728.    point1   = transform_point(point1,view_transfo);
  729.    point2.x = xmin + 0.5*(xmax-xmin);
  730.    point2.y = ymin + 1.0*(ymax-ymin);
  731.    point2.z = zmin + 0.5*(zmax-zmin);
  732.    point2   = transform_point(point2,view_transfo);
  733.  
  734.    if (point1.z < point2.z) {
  735.       /* draw the greater - point2 contains ymax */
  736.       point[0].x = xmin;  point[0].y = ymax;  point[0].z = zmin;
  737.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  738.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  739.       point[3].x = xmax;  point[3].y = ymax;  point[3].z = zmin;
  740.       /* repeat point 1 */
  741.       point[4].x = xmin;  point[4].y = ymax;  point[4].z = zmin;
  742.    } else {
  743.       /* draw the greater - point1 contains ymin */
  744.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  745.       point[1].x = xmin;  point[1].y = ymin;  point[1].z = zmax;
  746.       point[2].x = xmax;  point[2].y = ymin;  point[2].z = zmax;
  747.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  748.       /* repeat point 1 */
  749.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  750.    }
  751.  
  752.    /* rescale the points */
  753.    for (i=0; i<5; i++) 
  754.       newpt[i] = transform_point(point[i],view_transfo);
  755.  
  756.    /* draw the polygon outline */
  757.    linetypps(ips,10);
  758.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  759.    for (i=1; i<5; i++) 
  760.        fprintf(ips,"  %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
  761.    linetypps(ips,0);
  762. }
  763.  
  764. /* draw the front z-plane */
  765. drawPS_front_zplane(ips)
  766. FILE *ips;
  767. {
  768.    xyzdata transform_point();
  769.    extern  double xmin, xmax, ymin, ymax, zmin, zmax;
  770.    xyzdata point1, point2, point[5], newpt[5];
  771.    int     i;
  772.  
  773.    /* 2 planes intersecting the z-axis */
  774.    point1.x = xmin + 0.5*(xmax-xmin);
  775.    point1.y = ymin + 0.5*(ymax-ymin);
  776.    point1.z = zmin + 0.0*(zmax-zmin);
  777.    point1   = transform_point(point1,view_transfo);
  778.    point2.x = xmin + 0.5*(xmax-xmin);
  779.    point2.y = ymin + 0.5*(ymax-ymin);
  780.    point2.z = zmin + 1.0*(zmax-zmin);
  781.    point2   = transform_point(point2,view_transfo);
  782.  
  783.    if (point1.z < point2.z) {
  784.       /* draw the greater - point2 contains zmax */
  785.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmax;
  786.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmax;
  787.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmax;
  788.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmax;
  789.       /* repeat point 1 */
  790.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmax;
  791.    } else {
  792.       /* draw the greater - point1 contains zmin */
  793.       point[0].x = xmin;  point[0].y = ymin;  point[0].z = zmin;
  794.       point[1].x = xmin;  point[1].y = ymax;  point[1].z = zmin;
  795.       point[2].x = xmax;  point[2].y = ymax;  point[2].z = zmin;
  796.       point[3].x = xmax;  point[3].y = ymin;  point[3].z = zmin;
  797.       /* repeat point 1 */
  798.       point[4].x = xmin;  point[4].y = ymin;  point[4].z = zmin;
  799.    }
  800.  
  801.    /* rescale the points */
  802.    for (i=0; i<5; i++) 
  803.       newpt[i] = transform_point(point[i],view_transfo);
  804.  
  805.    /* draw the polygon outline */
  806.    linetypps(ips,10);
  807.    fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
  808.    for (i=1; i<5; i++) 
  809.        fprintf(ips,"  %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
  810.    linetypps(ips,0);
  811. }
  812.  
  813. draw_PSline(ips,x1, y1, z1, x2, y2, z2, ithk)
  814. FILE *ips;
  815. double x1, y1, z1, x2, y2, z2;
  816. int ithk;
  817. {
  818.    xyzdata point1, point2, newpt1, newpt2;
  819.    xyzdata transform_point();
  820.    double  px1, py1, px2, py2;
  821.  
  822.    point1.x = x1;
  823.    point1.y = y1;
  824.    point1.z = z1;
  825.  
  826.    point2.x = x2;
  827.    point2.y = y2;
  828.    point2.z = z2;
  829.  
  830.    newpt1 = transform_point(point1,view_transfo);
  831.    newpt2 = transform_point(point2,view_transfo);
  832.  
  833.    px1 = newpt1.x;
  834.    py1 = newpt1.y;
  835.    px2 = newpt2.x;
  836.    py2 = newpt2.y;
  837.  
  838.    /* draw the line */
  839.    fprintf(ips,"newpath\n  %6.2f %6.2f moveto\n",px1,py1);
  840.    fprintf(ips,"  %6.2f %6.2f lineto\n",px2,py2);
  841.    fprintf(ips,"closepath\n%6.2f setlinewidth\nstroke\n",ithk*scale);
  842. }
  843.  
  844. double find_angle(x1, y1, z1, x2, y2, z2)
  845. double x1, y1, z1, x2, y2, z2;
  846. {
  847.    xyzdata pt1, pt2, newpt1, newpt2, vect;
  848.    xyzdata transform_point(), normalize_vector();
  849.    double theta;
  850.  
  851.    pt1.x = x1;  pt1.y = y1;  pt1.z = z1;
  852.    pt2.x = x2;  pt2.y = y2;  pt2.z = z2;
  853.  
  854.    newpt1 = transform_point(pt1,view_transfo);
  855.    newpt2 = transform_point(pt2,view_transfo);
  856.  
  857.    if (newpt1.x>newpt2.x) {
  858.       vect.x = newpt1.x - newpt2.x;
  859.       vect.y = newpt1.y - newpt2.y;
  860.    } else {
  861.       vect.x = newpt2.x - newpt1.x;
  862.       vect.y = newpt2.y - newpt1.y;
  863.    }
  864.    vect.z = 0.0;
  865.    vect = normalize_vector(vect);
  866.    theta = acos(vect.x);
  867.    if (vect.y < 0.0) theta = -1.0*theta;
  868.    theta = theta*180.0/3.14159;
  869.    return(theta);
  870. }
  871.  
  872. linetypps(ips,line)
  873. FILE *ips;
  874. int line; 
  875. {
  876.    line = line % PS_LIN;
  877.  
  878.    switch (line) {
  879.    case 0 : fprintf(ips,"[] 0 setdash\n"); break;
  880.    case 1 : fprintf(ips,"[4 2] 0 setdash\n"); break;
  881.    case 2 : fprintf(ips,"[6 2 4 2] 0 setdash\n"); break;
  882.    case 3 : fprintf(ips,"[8 2] 0 setdash\n"); break;
  883.    case 4 : fprintf(ips,"[9 6 3 6] 0 setdash\n"); break;
  884.    case 5 : fprintf(ips,"[4 4] 0 setdash\n"); break;
  885.    case 6 : fprintf(ips,"[6 2 2 2] 0 setdash\n"); break;
  886.    case 7 : fprintf(ips,"[18 6] 0 setdash\n"); break;
  887.    case 8 : fprintf(ips,"[2 2 2 6] 0 setdash\n"); break;
  888.    case 9 : fprintf(ips,"[6 10] 0 setdash\n"); break;
  889.    case 10: fprintf(ips,"[0.5 2] 0 setdash\n"); break;
  890.    default: fprintf(ips,"[] 0 setdash\n"); break;
  891.    }
  892. }
  893.  
  894. endgrps(ips)
  895. FILE *ips;
  896. {
  897.         fprintf(ips,"showpage\n");
  898.         fclose(ips);
  899.         /* Close the file */
  900. }
  901.  
  902. plotps(ips)
  903. FILE *ips;
  904. {
  905.    char    mkr_to_char();
  906.    xyzdata transform_point();
  907.  
  908.    extern int line,marker;
  909.    extern int linechange,markerchange;
  910.    extern int hiddenline, quick_sort;
  911.    extern int linetype[MAXTYPE],markertype[MAXTYPE];
  912.    extern segmptr segmhead;
  913.  
  914.    char    charmkr;
  915.    int     kl,km;
  916.    segmptr S;
  917.    nodeptr Nd;
  918.    xyzdata point,newpt;
  919.  
  920.    /* reset the linewidth */
  921.    fprintf(ips,"%6.2f setlinewidth\n",0.5*scale);
  922.  
  923.    if (hiddenline == ON) {
  924.       /* sort the mesh */
  925.       if (quick_sort)
  926.          do_quick_sort();
  927.       else
  928.          bubble_sort();
  929.    }
  930.  
  931.    kl = linetype[0];
  932.    km = markertype[0];
  933.    S  = segmhead;
  934.    for ( ; S!=NULL; S=S->next) {
  935.       /* plot markers */
  936.       if (marker==ON) { 
  937.          km = km % PS_MKR;
  938.          charmkr = mkr_to_char(km);
  939.          linetypps(ips,0);
  940.          fprintf(ips,"newpath");
  941.          Nd = S->head;
  942.          for ( ; Nd!=NULL; Nd=Nd->next) {
  943.             point.x = Nd->x;
  944.             point.y = Nd->y;
  945.             point.z = Nd->z;
  946.             newpt   = transform_point(point,view_transfo);
  947.             fprintf(ips,"%8.2f %8.2f moveto mark%1c\n",newpt.x,newpt.y,charmkr);
  948.          }
  949.       }
  950.  
  951.       /* plot the points - filling the polygon comes first */
  952.       if (line == ON && hiddenline == ON) {
  953.          Nd = S->head;
  954.          point.x = Nd->x;
  955.          point.y = Nd->y;
  956.          point.z = Nd->z;
  957.          newpt   = transform_point(point,view_transfo);
  958.          fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt.x,newpt.y);
  959.          Nd = Nd->next;
  960.          for ( ; Nd!=NULL; Nd=Nd->next)  {
  961.             point.x = Nd->x;
  962.             point.y = Nd->y;
  963.             point.z = Nd->z;
  964.             newpt   = transform_point(point,view_transfo);
  965.             fprintf(ips,"  %8.2f %8.2f lineto\n",newpt.x,newpt.y);
  966.          }
  967.          fprintf(ips,"closepath\n 0.99 setgray fill\n 0.0 setgray\n");
  968.       }
  969.  
  970.       /* plot the points */
  971.       if (line == ON) {
  972.          linetypps(ips,kl);
  973.          Nd = S->head;
  974.          point.x = Nd->x;
  975.          point.y = Nd->y;
  976.          point.z = Nd->z;
  977.          newpt   = transform_point(point,view_transfo);
  978.          fprintf(ips,"newpath\n  %8.2f %8.2f moveto\n",newpt.x,newpt.y);
  979.          Nd = Nd->next;
  980.          for ( ; Nd!=NULL; Nd=Nd->next)  {
  981.             point.x = Nd->x;
  982.             point.y = Nd->y;
  983.             point.z = Nd->z;
  984.             newpt   = transform_point(point,view_transfo);
  985.             fprintf(ips,"  %8.2f %8.2f MoveDraw\n",newpt.x,newpt.y);
  986.          }
  987.       }
  988.       if (  linechange == ON) kl++;
  989.       if (markerchange == ON) km++;
  990.    }
  991.    /* draw the front planes */
  992.    front_axesPS(ips);
  993. }
  994.  
  995.  
  996. char mkr_to_char(num)
  997. int num;
  998. {
  999.     char ch;
  1000.  
  1001.     switch (num) {
  1002.     case  0 : ch = 'A'; break;
  1003.     case  1 : ch = 'B'; break;
  1004.     case  2 : ch = 'C'; break;
  1005.     case  3 : ch = 'D'; break;
  1006.     case  4 : ch = 'E'; break;
  1007.     case  5 : ch = 'F'; break;
  1008.     case  6 : ch = 'G'; break;
  1009.     case  7 : ch = 'H'; break;
  1010.     case  8 : ch = 'I'; break;
  1011.     case  9 : ch = 'J'; break;
  1012.     case 10 : ch = 'K'; break;
  1013.     case 11 : ch = 'L'; break;
  1014.     case 12 : ch = 'M'; break;
  1015.     case 13 : ch = 'N'; break;
  1016.     case 14 : ch = 'O'; break;
  1017.     case 15 : ch = 'P'; break;
  1018.     case 16 : ch = 'Q'; break;
  1019.     default : ch = 'A'; break;
  1020.     }
  1021.     return(ch);
  1022. }
  1023.  
  1024.