/* volume_dat.c compute the volume of a single closed .dat graphics figure */ /* compile with datread.c */ #include #include #include #include "datread.h" #undef abs #define abs(x) ((x)<0.0?(-(x)):(x)) float znormal(int n, float x[], float y[], float z[], float *area); static int num_points; /* for datread */ static int num_polys; static dpts * data_points; static int * data_verts; static float size = 1.0; /* auto scale */ static char filename[100] = "cube1.dat"; static int status = -1; static int debug = 0; int main(int argc, char * argv[]) { float area, avgz, vol, dvol, minz, znorm, tarea; float offs; int i, j, k, npts, iv; float x[10], y[10], z[10]; /* max 10 points in polygon */ if(argc>1) { strcpy(filename,argv[1]); } printf("volume_dat.c reading %s \n", filename); status = datread(filename, &data_points, &num_points, &data_verts, &num_polys, &size); printf("status=%d, size=%g\n", status, size); datccw(&data_points, &num_points, &data_verts, &num_polys); if(debug) datprint(data_points, num_points, data_verts, num_polys); vol = 0.0; /* total volume */ tarea = 0.0; /* total area */ offs = 10.0; /* z's must be positive */ k = 0; for(i=0; ioffs && znorm<0.0) printf("upper normal is negative \n"); if(debug) if(avgz0.0) printf("lower normal is positive \n"); } printf("\nfinal total area = %g, total volume = %g \n\n", tarea, vol); return 0; } /* end main of volume_dat.c */ float znormal(int n, float x[], float y[], float z[], float *area) { float ax, ay, az, bx, by, bz, nx, ny, nz, ss; float cx, cy, cz, sss, sstot, ssstot; int i; sstot = 0.0; ssstot = 0.0; for(i=2; i0.0001) printf("bad area ss=%g, sss=%g \n", sstot, ssstot); *area = sstot; return nz; } /* end znormal */