// dat_2d_3d.java read and scale Utah graphics .dat // convert 2d tri .dat to 3d tri .dat for .stl // input shape_tritri_py3.dat make triangles on a base import java.io.*; public class dat_2d_3d { boolean debug = true; int pts, pt, k; datread DR; // = new datread(filename); // defines data structures int num_points = 0; // set from datread int num_polys = 0; // set from datread double xyz[][] = new double[2000][3]; double xyp[][] = new double[2000][2]; // previous points positive int new_points = 0; int polys[] = new int[8000]; int new_polys = 0; int nk = 0; double x1,y1, x2,y2, x3,y3, x4, y4, x5, y5, x6, y6; double x7,y7, x8,y8, x9,y9, x10, y10, x11, y11, x12, y12; double xc, yc, dx1, dy1, dx2, dy2, dx3, dy3; double dx4, dy4, dx5, dy5, dx6, dy6; int np, ps, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12; double z1 = 20.0; // top tri double z2 = 10.0; // base top, bot tri double z3 = 0.0; // base bottom double dd = 10.0; // inside double xoff = 300.0; // make all x positive for .dat .stl double yoff = 250.0; // make all y positive void make_base() { int p1k, p2k, p3k; System.out.println("make_3dtri k="+k); np = DR.data_polys[k++]; p1k = DR.data_polys[k++]; p2k = DR.data_polys[k++]; p3k = DR.data_polys[k++]; System.out.println("p1="+p1+" p2="+p2+" p3="+p3); x1 = xyp[p1k-1][0]; y1 = xyp[p1k-1][1]; p1 = new_points + 1; xyz[new_points][0] = x1; xyz[new_points][1] = y1; xyz[new_points][2] = z2; new_points++; System.out.println("x1="+x1+" y1="+y1); x2 = xyp[p2k-1][0]; y2 = xyp[p2k-1][1]; p2 = new_points + 1; xyz[new_points][0] = x2; xyz[new_points][1] = y2; xyz[new_points][2] = z2; new_points++; System.out.println("x2="+x2+" y2="+y2); x3 = xyp[p3k-1][0]; y3 = xyp[p3k-1][1]; p3 = new_points + 1; xyz[new_points][0] = x3; xyz[new_points][1] = y3; xyz[new_points][2] = z2; new_points++; System.out.println("x3="+x3+" y3="+y3); // at z3 p4 = new_points + 1; xyz[new_points][0] = x1; xyz[new_points][1] = y1; xyz[new_points][2] = z3; new_points++; p5 = new_points + 1; xyz[new_points][0] = x2; xyz[new_points][1] = y2; xyz[new_points][2] = z3; new_points++; p6 = new_points + 1; xyz[new_points][0] = x3; xyz[new_points][1] = y3; xyz[new_points][2] = z3; new_points++; // sides polys[nk++] = 3; polys[nk++] = p1; polys[nk++] = p2; polys[nk++] = p5; polys[nk++] = 3; polys[nk++] = p5; polys[nk++] = p4; polys[nk++] = p1; polys[nk++] = 3; polys[nk++] = p2; polys[nk++] = p3; polys[nk++] = p6; polys[nk++] = 3; polys[nk++] = p6; polys[nk++] = p5; polys[nk++] = p2; polys[nk++] = 3; polys[nk++] = p3; polys[nk++] = p1; polys[nk++] = p4; polys[nk++] = 3; polys[nk++] = p4; polys[nk++] = p6; polys[nk++] = p3; } // end make base void make_3dtri() // most definitions global { int p1k, p2k, p3k; System.out.println("make_3dtri k="+k); np = DR.data_polys[k++]; p1k = DR.data_polys[k++]; p2k = DR.data_polys[k++]; p3k = DR.data_polys[k++]; System.out.println("p1="+p1+" p2="+p2+" p3="+p3); x1 = xyp[p1k-1][0]; y1 = xyp[p1k-1][1]; p1 = new_points + 1; xyz[new_points][0] = x1; xyz[new_points][1] = y1; xyz[new_points][2] = z1; new_points++; System.out.println("x1="+x1+" y1="+y1); x2 = xyp[p2k-1][0]; y2 = xyp[p2k-1][1]; p2 = new_points + 1; xyz[new_points][0] = x2; xyz[new_points][1] = y2; xyz[new_points][2] = z1; new_points++; System.out.println("x2="+x2+" y2="+y2); x3 = xyp[p3k-1][0]; y3 = xyp[p3k-1][1]; p3 = new_points + 1; xyz[new_points][0] = x3; xyz[new_points][1] = y3; xyz[new_points][2] = z1; new_points++; System.out.println("x3="+x3+" y3="+y3); System.out.println("make_insidetri"); xc = (x1 + x2 + x3)/3.0; // triangle inside yc = (y1 + y2 + y3)/3.0; System.out.println("xc="+xc+" yc="+yc); dx1 = x1 - xc; dy1 = y1 - yc; dx2 = x2 - xc; dy2 = y2 - yc; dx3 = x3 - xc; dy3 = y3 - yc; if(dx1<0.0) {dx1 = -dd;} else {dx1=dd;} if(dy1<0.0) {dy1 = -dd;} else {dy1=dd;} if(dx2<0.0) {dx2 = -dd;} else {dx2=dd;} if(dy2<0.0) {dy2 = -dd;} else {dy2=dd;} if(dx3<0.0) {dx3 = -dd;} else {dx3=dd;} if(dy3<0.0) {dy3 = -dd;} else {dy3=dd;} if((x1 < x2 && x2 < x3) || (x3 < x2 && x2 < x1)) { dx2 = 0.0; dy2 = -2.0*dd; dx1 = 2.0*dx1; dx3 = 2.0*dx3; } // adj System.out.println("dx1="+dx1+" dy1="+dy1); System.out.println("dx2="+dx2+" dy2="+dy2); System.out.println("dx3="+dx3+" dy3="+dy3); x4 = x1 - dx1; y4 = y1 - dy1; System.out.println("x4="+x4+" y4="+y4+" z4="+z1); p4 = new_points + 1; xyz[new_points][0] = x4; xyz[new_points][1] = y4; xyz[new_points][2] = z1; new_points++; x5 = x2 - dx2; y5 = y2 - dy2; System.out.println("x5="+x5+" y5="+y5+" z5="+z1); p5 = new_points + 1; xyz[new_points][0] = x5; xyz[new_points][1] = y5; xyz[new_points][2] = z1; new_points++; x6 = x3 - dx3; y6 = y3 - dy3; System.out.println("x6="+x6+" y6="+y6+" z6="+z1); p6 = new_points + 1; xyz[new_points][0] = x6; xyz[new_points][1] = y6; xyz[new_points][2] = z1; new_points++; // at z2 p7 = new_points + 1; xyz[new_points][0] = x1; xyz[new_points][1] = y1; xyz[new_points][2] = z2; new_points++; p8 = new_points + 1; xyz[new_points][0] = x2; xyz[new_points][1] = y2; xyz[new_points][2] = z2; new_points++; p9 = new_points + 1; xyz[new_points][0] = x3; xyz[new_points][1] = y3; xyz[new_points][2] = z2; new_points++; p10 = new_points + 1; xyz[new_points][0] = x4; xyz[new_points][1] = y4; xyz[new_points][2] = z2; new_points++; p11 = new_points + 1; xyz[new_points][0] = x5; xyz[new_points][1] = y5; xyz[new_points][2] = z2; new_points++; p12 = new_points + 1; xyz[new_points][0] = x6; xyz[new_points][1] = y6; xyz[new_points][2] = z2; new_points++; System.out.println("make 6tri z1 "); polys[nk++] = 3; polys[nk++] = p1; polys[nk++] = p2; polys[nk++] = p5; polys[nk++] = 3; polys[nk++] = p5; polys[nk++] = p4; polys[nk++] = p1; polys[nk++] = 3; polys[nk++] = p2; polys[nk++] = p3; polys[nk++] = p6; polys[nk++] = 3; polys[nk++] = p6; polys[nk++] = p5; polys[nk++] = p2; polys[nk++] = 3; polys[nk++] = p3; polys[nk++] = p1; polys[nk++] = p4; polys[nk++] = 3; polys[nk++] = p4; polys[nk++] = p6; polys[nk++] = p3; // make 6 tri z2 polys[nk++] = 3; polys[nk++] = p7; polys[nk++] = p8; polys[nk++] = p11; polys[nk++] = 3; polys[nk++] = p11; polys[nk++] = p10; polys[nk++] = p7; polys[nk++] = 3; polys[nk++] = p8; polys[nk++] = p9; polys[nk++] = p12; polys[nk++] = 3; polys[nk++] = p12; polys[nk++] = p11; polys[nk++] = p8; polys[nk++] = 3; polys[nk++] = p9; polys[nk++] = p7; polys[nk++] = p10; polys[nk++] = 3; polys[nk++] = p10; polys[nk++] = p12; polys[nk++] = p9; // sides polys[nk++] = 3; polys[nk++] = p1; polys[nk++] = p2; polys[nk++] = p8; polys[nk++] = 3; polys[nk++] = p8; polys[nk++] = p7; polys[nk++] = p1; polys[nk++] = 3; polys[nk++] = p2; polys[nk++] = p3; polys[nk++] = p9; polys[nk++] = 3; polys[nk++] = p9; polys[nk++] = p8; polys[nk++] = p2; polys[nk++] = 3; polys[nk++] = p3; polys[nk++] = p1; polys[nk++] = p7; polys[nk++] = 3; polys[nk++] = p7; polys[nk++] = p9; polys[nk++] = p3; // inside polys[nk++] = 3; polys[nk++] = p4; polys[nk++] = p5; polys[nk++] = p11; polys[nk++] = 3; polys[nk++] = p11; polys[nk++] = p10; polys[nk++] = p4; polys[nk++] = 3; polys[nk++] = p5; polys[nk++] = p6; polys[nk++] = p12; polys[nk++] = 3; polys[nk++] = p12; polys[nk++] = p11; polys[nk++] = p5; polys[nk++] = 3; polys[nk++] = p6; polys[nk++] = p4; polys[nk++] = p10; polys[nk++] = 3; polys[nk++] = p10; polys[nk++] = p12; polys[nk++] = p6; } // end make_3dtri public dat_2d_3d(String filename, String fileout) { System.out.println("dat_2d_3d.java running"); System.out.println("datread.java reading "+filename); 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 points"); for(int i=0; i