// test_spiral.java find minimum, plot slope // spiral(x,y) function included below import java.awt.*; import java.awt.event.*; public class test_spiral extends Frame { double xmin, xmax, ymin, ymax, zmin, zmax, atx, aty; int width = 620; int height = 670; double scale = 50.0; double xoff = 10.0; double yoff = 60.0; int n = 41; double xg[] = new double[n]; double yg[] = new double[n]; double zg[][] = new double[n][n]; public test_spiral() { System.out.println("test_spiral.java running"); setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); xmin = -6.0; xmax = 6.0; ymin = -6.0; ymax = 6.0; range(); System.out.println("xmin="+xmin+", xmax="+xmax+ ", ymin="+ymin+", ymax="+ymax); System.out.println("zmin="+zmin+", zmax="+zmax+ ",\n atx="+atx+", aty="+aty); } // end constructor test_spiral void range() { double x, y, z, xh, yh; xh = (xmax-xmin)/(double)(n-1); yh = (ymax-ymin)/(double)(n-1); z = spiral(xmin,ymin); zmin = z; zmax = z; atx = xmin; aty = ymin; for(int i=0; izmax) zmax = z; } } } // end range // spiral trough double spiral(double x, double y) // return z { double halfpi = 1.57079; double r, theta, tz; r = Math.sqrt(x*x+y*y); if(r < 0.001) theta = 0.0; else theta = Math.atan2(y,x); tz = theta/halfpi; if(tz < 0.0) tz = tz + 4.0; return 0.75*r + Math.sin((r+tz)*halfpi); } // end of spiral class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { requestFocus(); System.out.println("press"); // debug print repaint(); System.exit(0); } } public void paint(Graphics g) { double ax[] = new double[3]; double ay[] = new double[3]; double x, y, xp2, yp2, xp3, yp3, xp4, yp4; int ix, iy, ixp2, iyp2, ixp3, iyp3, ixp4, iyp4; double z1, z2; // draw a boundary g.drawRect(10, 45, width-20, height-55); g.drawString("test_spiral.java", 20, 60); g.drawString("xmin=-6.0,xmax=6.0, ymin=-6.0,ymax=6.0", 130, 60); g.drawString("arrow points downward slope", 420, 60); for(int i=1; i