//VelocityPlot1.java draw a contour plot // data input nx ny first line // x y z many lines smallest x first // followed by smallest y to largest import java.awt.*; import java.awt.event.*; import java.io.*; import java.*; public class VelocityPlot1 extends Frame { int ncont = 9; // contour lines zz normalized double dzz = 1.0/(ncont+1); // first is dzz Color cont_color[] = {Color.black, Color.gray, Color.magenta, Color.cyan, Color.blue, Color.green, Color.yellow, Color.orange, Color.red}; int width=800, height=800; double u1, u2, v1, v2; // velocity vector double xx[]; double yy[]; double zz[]; double uu[]; double vv[]; int n_input; double xmin, xmax, ymin, ymax, zmin, zmax, umin, umax, vmin, vmax; int nxx=0, nyy=0, nxy=0; // index i*nxx+j int n=0; boolean connect; boolean debug = true; double Pi = 4.0*Math.atan(1.0); VelocityPlot1() { setTitle("VelocityPlot1"); try{ read_data(); } catch(IOException exception) { } setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); n=0; connect=false; this.addMouseListener (new mousePressHandler()); repaint(); } // end VelocityPlot1 class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { int x, y, z, b; x = e.getX(); y = e.getY(); b = e.getButton(); if(b==3 && n>0) { connect=true; } requestFocus(); System.out.println("at x="+x+" y="+y+" b="+b); // debug print repaint(); } } // end mousePressHandler int scalex(double a) { return (int)((double)(width-20)*a)+10; } // end scalex int scaley(double a) { return (int)((double)(height-60)*(a))+50; } // end scaley public void paint(Graphics g) { double x1, y1, x2, y2, z11, z12; double u1, v1, u2, v2, u3, v3, u4, v4; double a, a3, a4, du, dv; double z, nearz; boolean pt1, pt2; String fstring; g.setColor(Color.black); for(int i=0; i x2,y1 // | // v+ // | // v // x1,y2 x2,y2 u1 = x1; v1 = y1; u2 = u1 + uu[i*nyy+j]/30.0; v2 = v1 + vv[i*nyy+j]/30.0; g.drawLine(scalex(u1), scaley(v1), scalex(u2), scaley(v2)); a = Math.atan2(u2-u1,v2-v1); a3 = a + Pi/6.0; du = 0.01*Math.sin(a3); dv = 0.01*Math.cos(a3); u3 = u2 - du; v3 = v2 - dv; g.drawLine(scalex(u2), scaley(v2), scalex(u3), scaley(v3)); a4 = a - Pi/6.0; du = 0.01*Math.sin(a4); dv = 0.01*Math.cos(a4); u4 = u2 - du; v4 = v2 - dv; g.drawLine(scalex(u2), scaley(v2), scalex(u4), scaley(v4)); } // end j } // end i } // end paint void read_data() throws IOException // big ugly input method { try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input_line; double amount; int len; int index; int last; System.out.println("read_data running"); input_line = in.readLine(); // nxx nyy System.out.println("input: "+input_line); len = input_line.length(); index = 0; // nxx if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index,last)+ "| len="+(input_line.substring(index,last).length())); nxx = Integer.parseInt(input_line.substring(index,last)); System.out.println("nxx="+nxx); index = input_line.indexOf(' ',index); // nyy if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index+1,last)); nyy = Integer.parseInt(input_line.substring(index+1,last)); System.out.println("nyy="+nyy); nxy = nxx*nyy; System.out.println("about to allocate "+(5*(nxy+1))+" doubles"); xx = new double[nxy+1]; yy = new double[nxy+1]; zz = new double[nxy+1]; uu = new double[nxy+1]; vv = new double[nxy+1]; n_input = 0; // read data points, last index varies by 1 input_line = in.readLine(); // tested for short in 'while' while(input_line.length()>6) // exit on blank or short line { if(debug && n_input==0) System.out.println("input: "+input_line); len = input_line.length(); index = 0; // first x if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); xx[n_input] = amount; index = last+1; // second y if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); yy[n_input] = amount; index = last+1; // third z if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); zz[n_input] = amount; index = last+1; // fourth u if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); uu[n_input] = amount; index = last+1; // fifth v if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(last