/* Program to generate wireframe model of 3D objects Niels Lund, September 1998 Modified for parameter file input 'net_work.txt'. August 2004 */ /* Each object in the model is defined by a number of generator lines which are rotated around an axis to form the object. The generator lines can consist of up to 9 straight line segments defined by points in the arrays h[10] and ra[10]. Cylinders and cones are produced by using many generators (defined by ), the subroutine call used is: pointnum = calpoint(nmax, imax, pointnum); (pointnum is a running index for the points in the wireframe model) A simple box can be described by a generator consisting of a single straight line defined by two points (imax=2), repeated four times (nmax=4). To make boxes with rectangular cross section use the subroutine: pointnum = calrect(dx, dy, pointnum); The resulting wireframe model is output to the file: 'wirefram.dat' */ #include #include #include #include int calpoint(int, int, int); int calrect(double, double, int); double inerti(int, int, int); int datain(int *type, int *imax, double h[], double r[], double *z_mount, double *r_mount, double *wgt, double *z_cg, int *nmax_i); FILE *out1, *out2, *mhfil; double dir_matrix[3][3], displ[3], xw[3], xb[2000][3], h[12], ra[12]; double geo_pos[20][3], geo_size[20][3], weights[20], cg[3]; double pi = 3.141593; int pointnum, linenum, facenum, elem; main(int argc, char *argv[]) { double dx, dy, mkg, msum, msum_x, msum_y, msum_z, z_cg, z_mount, r_mount; double xmnt, ymnt, zmnt, Ixx, Iyy, Izz, ri[12]; double mean_r; int i, nmax, imax, nmax_c, status, type, nmax_i; char s[256], alfil[200]; pointnum = 1; linenum = 0; facenum = 0; elem = 0; msum = msum_x = msum_y = msum_z = 0.0L; Ixx = Iyy = Izz = 0.0L; nmax_c = 15; if (argc>2) nmax_c = atoi(argv[2]); if (nmax_c > 90) nmax_c = 90; out1 = fopen("wirefram.dat","wt") ; /* Output file */ if ( out1 == NULL ) { printf("File opening error on output file 'wireframe.dat'!\n") ; exit(0) ; } fprintf(out1, "# Wireframe model for 'ThreeD.class' JAVA program\n"); fprintf(out1, "# Niels Lund. August 2004\n"); out2 = fopen("temp.lin","wt") ; /* temporary file */ if ( out1 == NULL ) { printf("File opening error on temporary file\n") ; exit(0) ; } if (argc>1) { mhfil = fopen(argv[1], "rt"); strcpy(alfil, argv[1]); } else { sprintf(alfil, "net_gen.txt"); mhfil = fopen("net_gen.txt", "rt"); } if (mhfil == NULL) { printf("No input file found! (%s)\n", alfil); exit(0); } next_elem: nmax_i = 0; status = datain(&type, &imax, h, ri, &z_mount, &r_mount, &weights[elem], &z_cg, &nmax_i); printf("status: %2d\n", status); if (status < 0) return(0); if (status > 1) goto complete; printf("%2d type: %1d, imax: %2d, z_mount: %5.1lf, r_mount: %5.1lf, weight: %5.1lf, z_cg: %5.1lf\n", elem, type, imax, z_mount, r_mount, weights[elem], z_cg); printf("%2d displacement: %7.4lf %7.4lf %7.4lf\n", elem, displ[0], displ[1], displ[2]); printf("%2d X dir. cosines: %7.4lf %7.4lf %7.4lf\n", elem, dir_matrix[0][0], dir_matrix[0][1], dir_matrix[0][2]); printf("%2d Y dir. cosines: %7.4lf %7.4lf %7.4lf\n", elem, dir_matrix[1][0], dir_matrix[1][1], dir_matrix[1][2]); printf("%2d Z dir. cosines: %7.4lf %7.4lf %7.4lf\n", elem, dir_matrix[2][0], dir_matrix[2][1], dir_matrix[2][2]); geo_pos[elem][0] = displ[0] + z_cg * dir_matrix[0][2]; geo_pos[elem][1] = displ[1] + z_cg * dir_matrix[1][2]; geo_pos[elem][2] = displ[2] + z_cg * dir_matrix[2][2]; mkg = weights[elem]; if (type == 1) { /* cylindrical elements */ if (nmax_i > 0) nmax = nmax_i; else nmax = nmax_c; mean_r = 0.0; geo_size[elem][0] = abs(h[0] - h[imax-1]) / 2.0; for (i=1; i 2)) { printf("Bad input data: (type not 1[cylinder] or 2[box]) %s\n", mhline); return(-1); } if (*imax > 12) { printf("Bad input data: (imax > 12) %s\n", mhline); return(-1); } } if (n==2) {sscanf(mhline, "%d %lf %lf", &n, z_mount, r_mount); } if (n==3) { sscanf(mhline, "%d %lf %lf %lf",&n, &dum0, &dum1, &dum2); displ[0] = dum0; displ[1] = dum1; displ[2] = dum2; } if (n==4) { sscanf(mhline, "%d %lf %lf %lf",&n, &dum0, &dum1, &dum2); dir_matrix[0][0] = dum0; dir_matrix[0][1] = dum1; dir_matrix[0][2] = dum2; } if (n==5) { sscanf(mhline, "%d %lf %lf %lf",&n, &dum0, &dum1, &dum2); dir_matrix[1][0] = dum0; dir_matrix[1][1] = dum1; dir_matrix[1][2] = dum2; } if (n==6) { sscanf(mhline, "%d %lf %lf %lf",&n, &dum0, &dum1, &dum2); dir_matrix[2][0] = dum0; dir_matrix[2][1] = dum1; dir_matrix[2][2] = dum2; } if (n==7) sscanf(mhline, "%d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &n, &h[0], &h[1], &h[2], &h[3], &h[4], &h[5], &h[6], &h[7], &h[8], &h[9], &h[10], &h[11]); if (n==8) sscanf(mhline, "%d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &n, &r[0], &r[1], &r[2], &r[3], &r[4], &r[5], &r[6], &r[7], &r[8], &r[9], &r[10], &r[11]); if (n==9) sscanf(mhline, "%d %lf %lf", &n, wgt, z_cg); if (n==10) sscanf(mhline, "%d %d", &n, nmax_i); if (n == 99) return(0); if ((n > 10) || (n < 0)) { printf("Bad input data: (line_identifier outside range 0 to 10). %s\n", mhline); return(-1); } } q_end: return(2); }