// gear8.java compile javac -cp . gear8.java // execute java -cp . gear8 # writes gear8d3.dat // reads gear8.dat write gear8t.dat // comes with center hole 8 points, make triangles // there are 16 points in each tooth, 192, 1, 2, ... 16 // 17, 18, ... 32 // 33, 34, ... 48 // ... 113, 114, ... 128 // hole 129, 130, ... 136 --- to 1, 16, 17, ... 128 3 triangles bot // 273, 274, ... 280 -- 145, 160, 161, ... 272 top // tooth center 137, 138, ... 144 bot z=0 // 281, 282, ... 288 not outside top z=10 public class gear8 { int numteeth = 8; int ptteeth = 8*16; // then numteeth for tooth centers, numteeth for hole double xyz[][] = new double[2*(144+8)][3]; // 144+ 8+ new tooth center points double xyzt[][] = new double[2*(144+8)][3]; // top points for gear8tt.dat int polyst[] = new int[4*(144+8)]; // top polys for gear8tt.dat int num_points = 136; // coming in int num_polys = 136; // coming in int new_points = 0; // 128 + 8 tooth center last int new_polys = 0; // 128 + 2*8 triangles int newt_polys = 0; int newt_points = 0; int oldpolys[] = new int[3*144]; // just 2 1 2 int polys[] = new int[8*(144+8+144)]; // 2 to 3 pt, top, hole, outer String filename = "gear8.dat"; // datread String filetri = "gear8t.dat"; // datwrite triangles String filetrit = "gear8tt.dat"; // datwrite top z=10 String fileout = "gear8d3.dat"; // datwrite 3D datread DR; double g8[][] = new double[8][3]; // for new tooth centers double r = 0.0; double rc = 18.766; // from gear8.dat node 2 double x = 0.0; double y = 0.0; double z = 0.0; double Pi = Math.PI; int k = 0; int pt = 0; int pts = 0; int pt2 = 0; int pt3 = 0; int pt4 = 0; int pc; int ptc = 137; // first added point tooth center int ptz = 129; // hole double ang = 0.0; double dang = Pi/4.0; // numteeth/2 double xmin, xmax, ymin, ymax, zmin, zmax; public gear8() { System.out.println("gear8,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 128 1 145 1 145 272 polys[k++] = 3; polys[k++] = 128; polys[k++] = 1; polys[k++] = 145; 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++] = 145; polys[k++] = 272; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); System.out.println("outside hole 129-136 273-280"); // outside hole 129-136 273-280 pt = 129; pt2 = 273; for(int i=0; i<7; 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 136 129 280 129 272 280 polys[k++] = 3; polys[k++] = 136; polys[k++] = 129; polys[k++] = 280; System.out.println("polys["+(k-4)+"]="+polys[k-4]+" "+polys[k-3]+" "+polys[k-2]+" "+polys[k-1]); polys[k++] = 3; polys[k++] = 129; polys[k++] = 272; polys[k++] = 280; 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("gear8.java ends"); } public static void main (String[] args) { new gear8(); // filenames built in } } // end gear8.java