// tetra_split1.java split simple tetra into 12 tetrahedrons // 11 vertex 48 triangles // reads .dat with 4 points, 4 triangular surfaces // writes .dat // // needs Matrix.determinant // needs datread.java compiled // needs datwrite.java compiled // // 4 input: 4 triangles // /\ 1 2 4 // / |\ * 11 center 1 2 4 // / | \ 2 3 4 // 7 * | * 10 midpoint 3 1 4 // / 6 | \ // /__*__|__ _\ output 8 tetrahedrons // 1 \ | / 3 1 5 6 7 not drawn. // \ *9 / 2 8 9 5 Each written // \ | / 3 10 6 8 as 4 triangles // 5 * | * 8 4 7 9 10 in .dat file. // \ |/ 5 6 7 11 // \/ 8 9 5 11 // 2 10 6 8 11 // 7 9 10 11 // 5 7 9 11 // 8 9 10 11 // 6 7 10 11 // 5 6 8 11 // public class tetra_split1 { int vert[][] = new int[65][3]; // triangle faces, 4 per tetra,index 1 offset int nvert = 0; int mnvert = 4; int ncntr = 8; double tv[][] = new double[22][3]; // x,y,z for vertices, 1 offset // 4 midpoints, center int ntv = 0; double points[][] = new double[65][3]; // x,y,z 0 offset double volume[] = new double[22]; double volumet = 0; double volumetot = 0; double area = 0.0; double vol4; int polys[] = new int[400]; // at least 4*vert int kp = 0; int jj = 0; int tet[][] = new int[49][4]; // 4 vert for each tetra int ntet = 0; datread DR; // = new datread(filename); // defines data structures int num_points = 0; // set from datread, reset for datwrite int num_polys = 0; // set from datread, reset for datwrite int new_points = 0; // 3 added for each poly (triangle) int new_polys = 0; // 1 changed and 3 added for each poly double xyz[][] = new double[22][3]; // x, y, z for output int newpts[] = new int[10000]; // 3, xyz1, xyz2, xyz3 for output public tetra_split1(String filein, String fileout) // .dat .dat { int kk, pt, pts; System.out.println("tetra_split1.java running"); System.out.println("datread.java reading "+filein); DR = new datread(filein); // 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"); for(int i=0; i3) jj = jj-4; polys[kp] = tet[i][jj]; kp++; } // end j } // end k } // end i // set up for datwrite points for(int i=1; i<=ntv; i++) { for(int j=0; j<3; j++) { points[i-1][j] = tv[i][j]; // make 0 offset } } // write 4 triangles for each tetrahedron new datwrite(fileout, points, ntv, polys, 4*ntet); System.out.println("tetra_split1.dat file written"); System.out.println("tetra_split1.java finished"); } // end tetra_split1 double d(int i, int j) // distance between vert i and vert j { double dist = 0.0; dist = Math.sqrt((tv[i][0]-tv[j][0])*(tv[i][0]-tv[j][0])+ (tv[i][1]-tv[j][1])*(tv[i][1]-tv[j][1])+ (tv[i][2]-tv[j][2])*(tv[i][2]-tv[j][2])); return dist; } double volume(int p1, int p2, int p3, int p4) { double A[][] = new double[3][3]; double vol1; A[0][0] = tv[p1][0]-tv[p4][0]; A[0][1] = tv[p1][1]-tv[p4][1]; A[0][2] = tv[p1][2]-tv[p4][2]; A[1][0] = tv[p2][0]-tv[p4][0]; A[1][1] = tv[p2][1]-tv[p4][1]; A[1][2] = tv[p2][2]-tv[p4][2]; A[2][0] = tv[p3][0]-tv[p4][0]; A[2][1] = tv[p3][1]-tv[p4][1]; A[2][2] = tv[p3][2]-tv[p4][2]; vol1 = Math.abs(Matrix.determinant(A)/6.0); return vol1; } // end volume of tetrahedron public static void main (String[] args) { new tetra_split1(args[0],args[1]); // .dat 8 points, .dat out } } // end tetra_split1.java