// gear16.java compile javac -cp . gear16.java 2D to3D new z=10.0 // execute java -cp . gear16 writes gear16d3.java // reads gear16.dat // comes with center hole 16 points, make triangles // there are 16 points in each tooth, 256, 1, 2, ... 16 // 17, 18, ... 32 // 33, 34, ... 48 // ... 241, 242, ... 256 bot z=0 // 289, 504, 505, ...544 top z=10 // hole 257, 258, ... 272 --- to 1, 16, 17, 204 3 triangles bot // 545, 546, ... 560 top // tooth center 273, 274, ... 288 bot // 561, 562, ... 576 top public class gear16 { int numteeth = 16; int ptteeth = 16*16; double xyz[][] = new double[2*(288+16)][3]; // 288+16 layer plus outside double xyzt[][] = new double[2*(288+16)][3]; // 288+16 layer plus outside int polyst[] = new int[4*4*(288+32)]; int num_points = 272; // coming in from gear16.dat 1..272 outline // 257..272 hole int num_polys = 272; // coming in from gear16.dat int num_tpoints = 0; // for gear16t.dat + 16 tooth centers int num_tpoly = 0; // computed int new_points = 0; // computed int new_polys = 0; // computed int newt_polys = 0; int newt_points = 0; int oldpolys[] = new int[3*272]; // just 2 1 2 int polys[] = new int[4*4*(288+32)]; // 3 1 2 , double times 2 for outside String filename = "gear16.dat"; // datread String filetri = "gear16t.dat"; // datwrite triangles String filetrit = "gear16tt.dat"; // datwrite top z=10 String fileout = "gear16d3.dat"; // datwrite top and bottom 3D datread DR; double g16[][] = new double[16][3]; // for new center points double r = 0.0; double rc = 28.5345; // gear16.dat tooth 2 int pc = 273; // first of numteeth tooth centers double rd = 0.0; double x = 0.0; double y = 0.0; double z = 10.0; double Pi = Math.PI; double ang = 0.0; double dang = Pi/8.0; // numteeth/2 of tooth centers int k = 0; int kn = 0; int pt = 0; int pt2 = 0; int pt3 = 0; int pt4 = 0; int pt5 = 0; int pts = 0; int ptc = 273; // first added point 273 ? int ptz = 273; // tooth center double xmin, xmax, ymin, ymax, zmin, zmax; public gear16() { System.out.println("gear16.java running"); DR = new datread(filename); // defines data structures num_points = DR.num_points; num_polys = DR.num_polys; System.out.println("num_points="+DR.num_points+ ", num_polys="+DR.num_polys); System.out.println("print vertices"); xmin = DR.data_points[0].x; xmax = DR.data_points[0].x; ymin = DR.data_points[0].y; ymax = DR.data_points[0].y; zmin = DR.data_points[0].z; zmax = DR.data_points[0].z; for(int i=0; i3 && i<125) System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); polys[k++] = 3; polys[k++] = pt+1; polys[k++] = pt2+1; polys[k++] = pt2; if(i>3 && i<125) System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); pt = pt+1; pt2 = pt2+1; } // end i then 256 1 544 1 289 544 polys[k++] = 3; polys[k++] = 256; polys[k++] = 1; polys[k++] = 544; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); polys[k++] = 3; polys[k++] = 1; polys[k++] = 289; polys[k++] = 544; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); System.out.println("outside hole 257-272 545-560"); // outside hole 257-272 545-560 pt = 257; pt2 = 545; for(int i=0; i<15; i++) // one less { polys[k++] = 3; polys[k++] = pt; polys[k++] = pt+1; polys[k++] = pt2; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); polys[k++] = 3; polys[k++] = pt+1; polys[k++] = pt2+1; polys[k++] = pt2; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); pt = pt+1; pt2 = pt2+1; } // end i then 272 545 560 272 257 545 polys[k++] = 3; polys[k++] = 272; polys[k++] = 545; polys[k++] = 560; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); polys[k++] = 3; polys[k++] = 272; polys[k++] = 257; polys[k++] = 545; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); new_polys = k/4; System.out.println("new_polys="+new_polys+" k="+k); System.out.println("datwrite "+fileout+" new_points="+new_points+ " new_polys="+new_polys); new datwrite(fileout, xyz, new_points, polys, new_polys); System.out.println("datwrite wrote "+fileout); System.out.println("gear16.java ends"); } public static void main (String[] args) { new gear16(); // filenames built in } } // end gear16.java