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 >
Wrap
Text File
|
1992-01-15
|
35KB
|
1,024 lines
/*** plotps.c - for POSTSCRIPT plotting ***/
#include <stdio.h>
#include <strings.h>
#include <math.h>
#include "header.h"
initps(ips)
FILE *ips;
{
extern double scale;
char time[MAXCHAR];
float d;
d = 6*scale;
/* begin postscript output */
fprintf(ips,"%c!\n",'%');
#ifdef GS_OK
fprintf(ips,"/defFontSizeTop %6.2f def\n",25*scale);
fprintf(ips,"/defFontSizeSide %6.2f def\n",20*scale);
fprintf(ips,"/defFontSizeAxes %6.2f def\n",15*scale);
fprintf(ips,"/UPJ {} def\n");
fprintf(ips,"/MIJT {0 defFontSizeTop -2 div rmoveto} def\n");
fprintf(ips,"/BOJT {0 defFontSizeTop neg rmoveto} def\n");
fprintf(ips,"/MIJS {0 defFontSizeSide -2 div rmoveto} def\n");
fprintf(ips,"/BOJS {0 defFontSizeSide neg rmoveto} def\n");
fprintf(ips,"/MIJA {0 defFontSizeAxes -2 div rmoveto} def\n");
fprintf(ips,"/BOJA {0 defFontSizeAxes neg rmoveto} def\n");
fprintf(ips,"/LEJ {} def\n");
fprintf(ips,"/CEJ {dup stringwidth pop -2 div 0 rmoveto} def\n");
fprintf(ips,"/RIJ {dup stringwidth pop neg 0 rmoveto} def\n");
#endif
fprintf(ips,"/MoveDraw {lineto currentpoint stroke moveto} def\n");
fprintf(ips,"/markA { %6.2f %6.2f rmoveto\n",d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",0.0, d);
fprintf(ips," %6.2f %6.2f rlineto\n", -d,0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",0.0, -d);
fprintf(ips," %6.2f %6.2f rlineto\n", d,0.0);
fprintf(ips," gsave\n");
fprintf(ips," 1.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markB { %6.2f %6.2f rmoveto\n",d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",0.0, d);
fprintf(ips," %6.2f %6.2f rlineto\n", -d,0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",0.0, -d);
fprintf(ips," %6.2f %6.2f rlineto\n", d,0.0);
fprintf(ips," gsave\n");
fprintf(ips," 0.5 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markC { %6.2f %6.2f rmoveto\n",d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",0.0, d);
fprintf(ips," %6.2f %6.2f rlineto\n", -d,0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",0.0, -d);
fprintf(ips," %6.2f %6.2f rlineto\n", d,0.0);
fprintf(ips," gsave\n");
fprintf(ips," 0.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markD { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d/2, d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2, d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d/2,-d/2);
fprintf(ips," gsave\n");
fprintf(ips," 1.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markE { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d/2, d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2, d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d/2,-d/2);
fprintf(ips," gsave\n");
fprintf(ips," 0.5 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markF { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d/2, d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2, d/2);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d/2,-d/2);
fprintf(ips," gsave\n");
fprintf(ips," 0.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markG { %6.2f %6.2f rmoveto\n",-0.50*d,-0.22*d);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
fprintf(ips," gsave\n");
fprintf(ips," 1.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markH { %6.2f %6.2f rmoveto\n",-0.50*d,-0.22*d);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
fprintf(ips," gsave\n");
fprintf(ips," 0.5 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markI { %6.2f %6.2f rmoveto\n",-0.50*d,-0.22*d);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
fprintf(ips," gsave\n");
fprintf(ips," 0.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markJ { %6.2f %6.2f rmoveto\n",-0.50*d, 0.22*d);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
fprintf(ips," gsave\n");
fprintf(ips," 1.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markK { %6.2f %6.2f rmoveto\n",-0.50*d, 0.22*d);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
fprintf(ips," gsave\n");
fprintf(ips," 0.5 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markL { %6.2f %6.2f rmoveto\n",-0.50*d, 0.22*d);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d,-0.66*d);
fprintf(ips," %6.2f %6.2f rlineto\n",-0.50*d, 0.66*d);
fprintf(ips," gsave\n");
fprintf(ips," 0.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markM { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", 0.0, d);
fprintf(ips," %6.2f %6.2f rmoveto\n",-d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2, 0.0);
fprintf(ips," currentpoint %f 0 360 arc \n",d/2);
fprintf(ips," gsave\n");
fprintf(ips," 1.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markN { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", 0.0, d);
fprintf(ips," %6.2f %6.2f rmoveto\n",-d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2, 0.0);
fprintf(ips," currentpoint %f 0 360 arc \n",d/2);
fprintf(ips," gsave\n");
fprintf(ips," 0.5 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markO { %6.2f %6.2f rmoveto\n", 0.0,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", 0.0, d);
fprintf(ips," %6.2f %6.2f rmoveto\n",-d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n",-d/2, 0.0);
fprintf(ips," currentpoint %f 0 360 arc \n",d/2);
fprintf(ips," gsave\n");
fprintf(ips," 0.0 setgray fill\n");
fprintf(ips," grestore\n");
fprintf(ips," stroke } def\n");
fprintf(ips,"/markP { %6.2f %6.2f rmoveto\n",-d/2,-d/2);
fprintf(ips," %6.2f %6.2f rlineto\n", d, d);
fprintf(ips," %6.2f %6.2f rmoveto\n", -d, 0.0);
fprintf(ips," %6.2f %6.2f rlineto\n", d, -d);
fprintf(ips," stroke } def\n");
fprintf(ips,"/markQ { %6.2f %6.2f rmoveto\n",-0.5,0.0);
fprintf(ips," %6.2f %6.2f rlineto\n", 1.0,0.0);
fprintf(ips," stroke } def\n");
/* print the time */
#ifdef GS_OK
get_localtime(time);
fprintf(ips,"/Times-Bold findfont\n");
fprintf(ips,"10 scalefont setfont\n");
fprintf(ips,"%6.2f %6.2f moveto ",30.0,750.0);
fprintf(ips,"(%s) show\n",time);
#endif
}
/* draw the toplabel and the z-axis */
axesps(ips)
FILE *ips;
{
xyzdata transform_point();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
xyzdata point[4], newpt[4];
double minx;
int i, mini;
pxmin = 1.0*PSMIN;
pymin = 1.0*PSMIN;
pxmax = scale*PSMAX;
pymax = scale*PSMAX;
/* Top Label */
#ifdef GS_OK
fprintf(ips,"/Times-Bold findfont\n");
fprintf(ips,"defFontSizeTop scalefont setfont\n");
fprintf(ips," %6.2f %6.2f moveto ",0.5*(pxmax+pxmin),pymax+25*scale);
fprintf(ips,"(%s) UPJ CEJ show\n",toplabel);
#endif
/*
* choose which z-axis to draw
* There are 4 lines on the z-axis containing the 4 points below
*/
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmin;
point[2].x = xmax; point[2].y = ymin; point[2].z = zmin;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* transform the 4 points */
for (i=0; i<4; i++)
newpt[i] = transform_point(point[i],view_transfo);
/*
* The line drawn will contain the smallest x-value of the
* 4 points decribed above (on the zplane)
*/
minx = newpt[0].x; mini = 0;
for (i=0; i<4; i++)
if (newpt[i].x < minx) {
minx = newpt[i].x;
mini = i;
}
/* draw the z-axis */
if (mini == 0)
drawPS_zaxis(ips,xmin,ymin,zmin,xmin,ymin,zmax);
else if (mini == 1)
drawPS_zaxis(ips,xmin,ymax,zmin,xmin,ymax,zmax);
else if (mini == 2)
drawPS_zaxis(ips,xmax,ymin,zmin,xmax,ymin,zmax);
else if (mini == 3)
drawPS_zaxis(ips,xmax,ymax,zmin,xmax,ymax,zmax);
/* draw the back planes now */
back_axesPS(ips);
}
/* draw the axes that are further from the viewer */
back_axesPS(ips)
FILE *ips;
{
/* Draw the plane intersecting x-axis */
drawPS_back_xplane(ips);
/* Draw the plane intersecting y-axis */
drawPS_back_yplane(ips);
/* Draw the plane intersecting z-axis */
drawPS_back_zplane(ips);
}
/* draw the axes that are closer to the viewer */
front_axesPS(ips)
FILE *ips;
{
/* Draw the plane intersecting x-axis */
drawPS_front_xplane(ips);
/* Draw the plane intersecting y-axis */
drawPS_front_yplane(ips);
/* Draw the plane intersecting z-axis */
drawPS_front_zplane(ips);
}
/* Draw the axis - parallel to X */
drawPS_xaxis(ips,xa,ya,za,xb,yb,zb)
FILE *ips;
double xa,ya,za,xb,yb,zb;
{
xyzdata midpoint();
xyzdata transform_point();
double find_angle();
char *sprintf(), *strcpy();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
xyzdata midpt;
int i;
char text[100];
double angle, xtmp, ratio, dl;
/*
* xa = xmin xb = xmax
* ya = yb = (ymin ? ymax)
* za = zb = (zmin ? zmax)
*/
/* midpoint of the line */
dl = (ya == ymin) ? -0.3*(ymax-ymin) : 0.3*(ymax-ymin);
midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
angle = find_angle(xa,ya,za,xb,yb,zb);
/* X-axis Label */
#ifdef GS_OK
fprintf(ips,"/Times-Bold findfont\n");
fprintf(ips,"defFontSizeSide scalefont setfont\n");
fprintf(ips,"/Xlabel {");
fprintf(ips,"0 0 moveto ");
fprintf(ips,"(%s) BOJS CEJ show } def\n",xlabel);
fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
fprintf(ips,"%6.2f rotate\n Xlabel\n %6.2f rotate\n",angle,-angle);
fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
#endif
/* Tick Marks on the X-axis */
/* Draw the tick marks */
for (i=0; i<=xticks; i++) {
ratio = i/(double)xticks;
xtmp = xa + (xb-xa)*ratio;
draw_PSline(ips,xtmp,ya,za,xtmp,ya+0.5*dl,za,2);
midpt.x = xtmp;
midpt.y = ya+0.6*dl;
midpt.z = za;
midpt = transform_point(midpt,view_transfo);
sprintf(text,"%.3g",xtmp);
#ifdef GS_OK
fprintf(ips,"/Times-Roman findfont\n");
fprintf(ips,"defFontSizeAxes scalefont setfont\n");
fprintf(ips,"/label {");
fprintf(ips,"0 0 moveto ");
fprintf(ips,"(%s) BOJA CEJ show } def\n",text);
fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
/*
fprintf(ips,"%6.2f rotate\nlabel\n %6.2f rotate\n",angle,-angle);
*/
fprintf(ips,"label\n");
fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
#endif
}
}
/* Draw the axis - parallel to Y */
drawPS_yaxis(ips,xa,ya,za,xb,yb,zb)
FILE *ips;
double xa,ya,za,xb,yb,zb;
{
xyzdata midpoint();
xyzdata transform_point();
char *strcpy();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
xyzdata midpt;
int i;
char text[100];
double angle, ytmp, ratio, dl;
/*
* xa = xb = (xmin ? xmax)
* ya = ymin yb = ymax
* za = zb = (zmin ? zmax)
*/
/* midpoint of the line */
dl = (xa == xmin) ? -0.3*(xmax-xmin) : 0.3*(xmax-xmin);
midpt = midpoint(xa+dl,ya,za,xb+dl,yb,zb,0.5);
angle = find_angle(xa,ya,za,xb,yb,zb);
/* Y-axis Label */
#ifdef GS_OK
fprintf(ips,"/Times-Bold findfont\n");
fprintf(ips,"defFontSizeSide scalefont setfont\n");
fprintf(ips,"/Ylabel {");
fprintf(ips,"0 0 moveto ");
fprintf(ips,"(%s) BOJS CEJ show } def\n",ylabel);
fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
fprintf(ips,"%6.2f rotate\n Ylabel\n %6.2f rotate\n",angle,-angle);
fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
#endif
/* Draw the tick marks */
for (i=0; i<=yticks; i++) {
ratio = i/(double)yticks;
ytmp = ya + (yb-ya)*ratio;
draw_PSline(ips,xa,ytmp,za,xa+0.5*dl,ytmp,za,2);
midpt.x = xa + 0.6*dl;
midpt.y = ytmp;
midpt.z = za;
midpt = transform_point(midpt,view_transfo);
sprintf(text,"%.3g",ytmp);
#ifdef GS_OK
fprintf(ips,"/Times-Roman findfont\n");
fprintf(ips,"defFontSizeAxes scalefont setfont\n");
fprintf(ips,"/label {");
fprintf(ips,"0 0 moveto ");
fprintf(ips,"(%s) BOJA CEJ show } def\n",text);
fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
/*
fprintf(ips,"%6.2f rotate\nlabel\n %6.2f rotate\n",angle,-angle);
*/
fprintf(ips,"label\n");
fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
#endif
}
}
/* Draw the axis - parallel to Z */
drawPS_zaxis(ips,xa,ya,za,xb,yb,zb)
FILE *ips;
double xa,ya,za,xb,yb,zb;
{
xyzdata midpoint();
xyzdata transform_point();
char *strcpy();
extern double xmin, ymin, zmin, xmax, ymax, zmax;
xyzdata midpt;
int i;
char text[100];
double ztmp, ratio, dl;
/*
* xa = xb = (xmin ? xmax)
* ya = yb = (ymin ? ymax)
* za = zmin zb = zmax
*/
/* midpoint of the line */
dl = (ya == ymin) ? -0.3*(ymax-ymin) : 0.3*(ymax-ymin);
midpt = midpoint(xa,ya+dl,za,xb,yb+dl,zb,0.5);
/* Z-axis Label */
#ifdef GS_OK
fprintf(ips,"/Times-Bold findfont\n");
fprintf(ips,"defFontSizeSide scalefont setfont\n");
fprintf(ips,"/Zlabel {");
fprintf(ips,"0 0 moveto ");
fprintf(ips,"(%s) UPJ CEJ show } def\n",zlabel);
fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
fprintf(ips,"90 rotate\n Zlabel\n -90 rotate\n");
fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
#endif
/* Draw the tick marks */
for (i=0; i<=zticks; i++) {
ratio = i/(double)zticks;
ztmp = za + (zb-za)*ratio;
draw_PSline(ips,xa,ya,ztmp,xa,ya+0.5*dl,ztmp,2);
midpt.x = xa;
midpt.y = ya+0.6*dl;
midpt.z = ztmp;
midpt = transform_point(midpt,view_transfo);
sprintf(text,"%.3g",ztmp);
#ifdef GS_OK
fprintf(ips,"/Times-Roman findfont\n");
fprintf(ips,"defFontSizeAxes scalefont setfont\n");
fprintf(ips,"/label {");
fprintf(ips,"0 0 moveto ");
fprintf(ips,"(%s) UPJ CEJ show } def\n",text);
fprintf(ips,"%6.2f %6.2f translate\n",midpt.x,midpt.y);
fprintf(ips,"90 rotate\nlabel\n -90 rotate\n");
fprintf(ips,"%6.2f %6.2f translate\n",-midpt.x,-midpt.y);
#endif
}
}
/* draw the back x-plane */
drawPS_back_xplane(ips)
FILE *ips;
{
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.0*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 1.0*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z > point2.z) {
/* draw the lesser - point2 contains xmax */
point[0].x = xmax; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmax; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmax; point[4].y = ymin; point[4].z = zmin;
} else {
/* draw the lesser - point1 contains xmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmin; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmin; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++) {
newpt[i] = transform_point(point[i],view_transfo);
}
/* draw and fill the polygon */
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f lineto\n",newpt[i].x,newpt[i].y);
fprintf(ips,"closepath\n 1.00 setgray fill\n 0.0 setgray\n");
/* draw the polygon outline */
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
}
/* draw the back y-plane */
drawPS_back_yplane(ips)
FILE *ips;
{
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.0*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 1.0*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z > point2.z) {
/* draw the lesser - point2 contains ymax */
point[0].x = xmin; point[0].y = ymax; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymax; point[4].z = zmin;
} else {
/* draw the lesser - point1 contains ymin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymin; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++)
newpt[i] = transform_point(point[i],view_transfo);
/* draw and fill the polygon */
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f lineto\n",newpt[i].x,newpt[i].y);
fprintf(ips,"closepath\n 1.00 setgray fill\n 0.0 setgray\n");
/* draw the polygon outline */
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
}
/* draw the back z-plane */
drawPS_back_zplane(ips)
FILE *ips;
{
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt[5];
double ztmp, miny;
int i, mini;
/* 2 planes intersecting the z-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.0*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 1.0*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z > point2.z) {
/* draw the lesser - point2 contains zmax */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmax;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmax;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmax;
} else {
/* draw the lesser - point1 contains zmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmin;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmin;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++)
newpt[i] = transform_point(point[i],view_transfo);
/* draw and fill the polygon */
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f lineto\n",newpt[i].x,newpt[i].y);
fprintf(ips,"closepath\n 1.00 setgray fill\n 0.0 setgray\n");
/* draw the polygon outline */
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
/*
* The line drawn will contain the smallest y-value of the
* 4 points on the z-plane
*/
miny = newpt[0].y; mini = 0;
for (i=0; i<4; i++)
if (newpt[i].y < miny) {
miny = newpt[i].y;
mini = i;
}
ztmp = (point1.z > point2.z) ? zmax : zmin;
/* draw the x-axis first */
if (mini == 0 || mini == 3)
drawPS_xaxis(ips,xmin,ymin,ztmp,xmax,ymin,ztmp);
else if (mini == 1 || mini == 2)
drawPS_xaxis(ips,xmin,ymax,ztmp,xmax,ymax,ztmp);
/* draw the y-axis first */
if (mini == 0 || mini == 1)
drawPS_yaxis(ips,xmin,ymin,ztmp,xmin,ymax,ztmp);
else if (mini == 2 || mini == 3)
drawPS_yaxis(ips,xmax,ymin,ztmp,xmax,ymax,ztmp);
}
/* draw the front x-plane */
drawPS_front_xplane(ips)
FILE *ips;
{
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.0*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 1.0*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z < point2.z) {
/* draw the greater - point2 contains xmax */
point[0].x = xmax; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmax; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmax; point[4].y = ymin; point[4].z = zmin;
} else {
/* draw the greater - point1 contains xmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmin; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmin; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++)
newpt[i] = transform_point(point[i],view_transfo);
/* draw the polygon outline */
linetypps(ips,10);
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
linetypps(ips,0);
}
/* draw the front y-plane */
drawPS_front_yplane(ips)
FILE *ips;
{
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt[5];
int i;
/* 2 planes intersecting the x-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.0*(ymax-ymin);
point1.z = zmin + 0.5*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 1.0*(ymax-ymin);
point2.z = zmin + 0.5*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z < point2.z) {
/* draw the greater - point2 contains ymax */
point[0].x = xmin; point[0].y = ymax; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymax; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymax; point[4].z = zmin;
} else {
/* draw the greater - point1 contains ymin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymin; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymin; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++)
newpt[i] = transform_point(point[i],view_transfo);
/* draw the polygon outline */
linetypps(ips,10);
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
linetypps(ips,0);
}
/* draw the front z-plane */
drawPS_front_zplane(ips)
FILE *ips;
{
xyzdata transform_point();
extern double xmin, xmax, ymin, ymax, zmin, zmax;
xyzdata point1, point2, point[5], newpt[5];
int i;
/* 2 planes intersecting the z-axis */
point1.x = xmin + 0.5*(xmax-xmin);
point1.y = ymin + 0.5*(ymax-ymin);
point1.z = zmin + 0.0*(zmax-zmin);
point1 = transform_point(point1,view_transfo);
point2.x = xmin + 0.5*(xmax-xmin);
point2.y = ymin + 0.5*(ymax-ymin);
point2.z = zmin + 1.0*(zmax-zmin);
point2 = transform_point(point2,view_transfo);
if (point1.z < point2.z) {
/* draw the greater - point2 contains zmax */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmax;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmax;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmax;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmax;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmax;
} else {
/* draw the greater - point1 contains zmin */
point[0].x = xmin; point[0].y = ymin; point[0].z = zmin;
point[1].x = xmin; point[1].y = ymax; point[1].z = zmin;
point[2].x = xmax; point[2].y = ymax; point[2].z = zmin;
point[3].x = xmax; point[3].y = ymin; point[3].z = zmin;
/* repeat point 1 */
point[4].x = xmin; point[4].y = ymin; point[4].z = zmin;
}
/* rescale the points */
for (i=0; i<5; i++)
newpt[i] = transform_point(point[i],view_transfo);
/* draw the polygon outline */
linetypps(ips,10);
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt[0].x,newpt[0].y);
for (i=1; i<5; i++)
fprintf(ips," %8.2f %8.2f MoveDraw\n",newpt[i].x,newpt[i].y);
linetypps(ips,0);
}
draw_PSline(ips,x1, y1, z1, x2, y2, z2, ithk)
FILE *ips;
double x1, y1, z1, x2, y2, z2;
int ithk;
{
xyzdata point1, point2, newpt1, newpt2;
xyzdata transform_point();
double px1, py1, px2, py2;
point1.x = x1;
point1.y = y1;
point1.z = z1;
point2.x = x2;
point2.y = y2;
point2.z = z2;
newpt1 = transform_point(point1,view_transfo);
newpt2 = transform_point(point2,view_transfo);
px1 = newpt1.x;
py1 = newpt1.y;
px2 = newpt2.x;
py2 = newpt2.y;
/* draw the line */
fprintf(ips,"newpath\n %6.2f %6.2f moveto\n",px1,py1);
fprintf(ips," %6.2f %6.2f lineto\n",px2,py2);
fprintf(ips,"closepath\n%6.2f setlinewidth\nstroke\n",ithk*scale);
}
double find_angle(x1, y1, z1, x2, y2, z2)
double x1, y1, z1, x2, y2, z2;
{
xyzdata pt1, pt2, newpt1, newpt2, vect;
xyzdata transform_point(), normalize_vector();
double theta;
pt1.x = x1; pt1.y = y1; pt1.z = z1;
pt2.x = x2; pt2.y = y2; pt2.z = z2;
newpt1 = transform_point(pt1,view_transfo);
newpt2 = transform_point(pt2,view_transfo);
if (newpt1.x>newpt2.x) {
vect.x = newpt1.x - newpt2.x;
vect.y = newpt1.y - newpt2.y;
} else {
vect.x = newpt2.x - newpt1.x;
vect.y = newpt2.y - newpt1.y;
}
vect.z = 0.0;
vect = normalize_vector(vect);
theta = acos(vect.x);
if (vect.y < 0.0) theta = -1.0*theta;
theta = theta*180.0/3.14159;
return(theta);
}
linetypps(ips,line)
FILE *ips;
int line;
{
line = line % PS_LIN;
switch (line) {
case 0 : fprintf(ips,"[] 0 setdash\n"); break;
case 1 : fprintf(ips,"[4 2] 0 setdash\n"); break;
case 2 : fprintf(ips,"[6 2 4 2] 0 setdash\n"); break;
case 3 : fprintf(ips,"[8 2] 0 setdash\n"); break;
case 4 : fprintf(ips,"[9 6 3 6] 0 setdash\n"); break;
case 5 : fprintf(ips,"[4 4] 0 setdash\n"); break;
case 6 : fprintf(ips,"[6 2 2 2] 0 setdash\n"); break;
case 7 : fprintf(ips,"[18 6] 0 setdash\n"); break;
case 8 : fprintf(ips,"[2 2 2 6] 0 setdash\n"); break;
case 9 : fprintf(ips,"[6 10] 0 setdash\n"); break;
case 10: fprintf(ips,"[0.5 2] 0 setdash\n"); break;
default: fprintf(ips,"[] 0 setdash\n"); break;
}
}
endgrps(ips)
FILE *ips;
{
fprintf(ips,"showpage\n");
fclose(ips);
/* Close the file */
}
plotps(ips)
FILE *ips;
{
char mkr_to_char();
xyzdata transform_point();
extern int line,marker;
extern int linechange,markerchange;
extern int hiddenline, quick_sort;
extern int linetype[MAXTYPE],markertype[MAXTYPE];
extern segmptr segmhead;
char charmkr;
int kl,km;
segmptr S;
nodeptr Nd;
xyzdata point,newpt;
/* reset the linewidth */
fprintf(ips,"%6.2f setlinewidth\n",0.5*scale);
if (hiddenline == ON) {
/* sort the mesh */
if (quick_sort)
do_quick_sort();
else
bubble_sort();
}
kl = linetype[0];
km = markertype[0];
S = segmhead;
for ( ; S!=NULL; S=S->next) {
/* plot markers */
if (marker==ON) {
km = km % PS_MKR;
charmkr = mkr_to_char(km);
linetypps(ips,0);
fprintf(ips,"newpath");
Nd = S->head;
for ( ; Nd!=NULL; Nd=Nd->next) {
point.x = Nd->x;
point.y = Nd->y;
point.z = Nd->z;
newpt = transform_point(point,view_transfo);
fprintf(ips,"%8.2f %8.2f moveto mark%1c\n",newpt.x,newpt.y,charmkr);
}
}
/* plot the points - filling the polygon comes first */
if (line == ON && hiddenline == ON) {
Nd = S->head;
point.x = Nd->x;
point.y = Nd->y;
point.z = Nd->z;
newpt = transform_point(point,view_transfo);
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt.x,newpt.y);
Nd = Nd->next;
for ( ; Nd!=NULL; Nd=Nd->next) {
point.x = Nd->x;
point.y = Nd->y;
point.z = Nd->z;
newpt = transform_point(point,view_transfo);
fprintf(ips," %8.2f %8.2f lineto\n",newpt.x,newpt.y);
}
fprintf(ips,"closepath\n 0.99 setgray fill\n 0.0 setgray\n");
}
/* plot the points */
if (line == ON) {
linetypps(ips,kl);
Nd = S->head;
point.x = Nd->x;
point.y = Nd->y;
point.z = Nd->z;
newpt = transform_point(point,view_transfo);
fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",newpt.x,newpt.y);
Nd = Nd->next;
for ( ; Nd!=NULL; Nd=Nd->next) {
point.x = Nd->x;
point.y = Nd->y;
point.z = Nd->z;
newpt = transform_point(point,view_transfo);
fprintf(ips," %8.2f %8.2f MoveDraw\n",newpt.x,newpt.y);
}
}
if ( linechange == ON) kl++;
if (markerchange == ON) km++;
}
/* draw the front planes */
front_axesPS(ips);
}
char mkr_to_char(num)
int num;
{
char ch;
switch (num) {
case 0 : ch = 'A'; break;
case 1 : ch = 'B'; break;
case 2 : ch = 'C'; break;
case 3 : ch = 'D'; break;
case 4 : ch = 'E'; break;
case 5 : ch = 'F'; break;
case 6 : ch = 'G'; break;
case 7 : ch = 'H'; break;
case 8 : ch = 'I'; break;
case 9 : ch = 'J'; break;
case 10 : ch = 'K'; break;
case 11 : ch = 'L'; break;
case 12 : ch = 'M'; break;
case 13 : ch = 'N'; break;
case 14 : ch = 'O'; break;
case 15 : ch = 'P'; break;
case 16 : ch = 'Q'; break;
default : ch = 'A'; break;
}
return(ch);
}