// plot4dp.java projection of X, Y, Z, T axis onto x, y screen //Notation: x is left and right. // y is up and down // z is forward and back // t is in and out (a fourth spacial dimension) // //There are 24 "2D faces" shown in cube.dat4 // sphere4D_16.dat4 // //screen x = w * ((pp.x/pp.w)-xmin)/(xmax-xmin) ? //screen y = h * ((pp.y/pp.w)-ymin)/(ymax-ymin) ? import java.io.*; import java.util.*; import java.text.*; import java.awt.*; import java.awt.event.*; public class plot4dp extends Frame { // screen data int width = 600; int height = 600; // scene data double xmin=0.0, xmax=0.0, ymin=0.0, ymax=0.0; double zmin=0.0, zmax=0.0, tmin=0.0, tmax=0.0; double xoff, xsca, yoff, ysca, zsca, tsca; double siz, ang1, xzf, yzf; int x1, y1, x2, y2; // file data xxx.dat4 String filename; int nvert = 0, ivert = 0; int nface = 0, iface = 0; int npts= 0, ipts = 0; double vert[][] = new double[1000][4]; int pts[] = new int[2000]; int face[][] = new int[2000][4]; // should be 3 or 4 public plot4dp(String file_name) // constructor { System.out.println("plot4dp.java running on "+file_name); filename = file_name; read_data(file_name); for(int i=0; ixmax) xmax=vert[i][0]; if(vert[i][1]ymax) ymax=vert[i][1]; if(vert[i][2]zmax) zmax=vert[i][2]; if(vert[i][3]tmax) tmax=vert[i][3]; } xsca = xmax-xmin; ysca = ymax-ymin; zsca = zmax-zmin; tsca = tmax-tmin; for(int i=0; i9) {g.setColor(Color.gray); return; } switch(i) { case 0: g.setColor(Color.black); break; case 1: g.setColor(new Color(188,143,143)); break; // Color.pink); brown case 2: g.setColor(Color.red); break; case 3: g.setColor(Color.orange); break; case 4: g.setColor(Color.yellow); break; case 5: g.setColor(Color.green); break; case 6: g.setColor(Color.blue); break; case 7: g.setColor(Color.magenta); break; case 8: g.setColor(Color.cyan); break; case 9: g.setColor(Color.gray); break; } } // end set_color class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { requestFocus(); System.out.println("exit"); repaint(); System.exit(0); } } void read_data(String filename) { String input_line; int ntok; StringTokenizer T; String token[] = new String[20]; boolean debug = false; try { FileReader fin = new FileReader(filename); BufferedReader file_in = new BufferedReader(fin); System.out.println("read_data reading "+filename); input_line = file_in.readLine(); while(input_line != null) { if(debug) System.out.println(input_line); T = new StringTokenizer(input_line," "); ntok=0; while(T.hasMoreTokens()) { token[ntok]=T.nextToken(); if(debug) System.out.println("token["+ntok+"]=|"+token[ntok]+"|"); if(token[0].equals("#")) break; if(nvert==0) { nvert = Integer.parseInt(token[0]); if(debug) System.out.println("nvert="+nvert); ntok++; continue; } if(nface==0 && ntok==1) { nface = Integer.parseInt(token[1]); if(debug) System.out.println("nface="+nface); break; } if(ivert3) break; vert[ivert][ntok] = Double.parseDouble(token[ntok]); if(ntok==3) { ivert++; break;} } else { if(ntok==0) { npts = Integer.parseInt(token[0]); pts[iface] = npts; ipts = 0; ntok++; continue; } face[iface][ipts] = Integer.parseInt(token[ntok]); ipts++; if(ipts==npts) {iface++; break;} } // System.out.println("int="+Integer.parseInt(token[0])); // System.out.println("dbl="+Double.parseDouble(token[ntok])); // if(token[0].equals("start")) ntok++; // can "break" if number known, rest of line is comment } input_line = file_in.readLine(); } file_in.close(); System.out.println("finished read_data"); System.out.println("nvert="+nvert+", ivert="+ivert+ ", nface="+nface+", iface="+iface); } catch(FileNotFoundException exception) { System.out.println(filename+" not found"); } catch(Exception exception) // catches all exceptions { System.out.println("java read_data input-file"); } } // end read_data public static void main (String[] args) { String file_name = args[0]; new plot4dp(file_name); System.out.println("plot4dp.java finished"); } } // end class plot4dp