/* * h1a.java - revised 18 Apr 05 - width 401, height 201 * the cycloid, the path that minimizes the transit time between points * in a uniform gravitational field * the particle is released from rest and is to reach a point 5 m below and * 25.6 m to the right of the release point * the trial path has 2^n linear segments where n increases from 0 to 8 * @author jackord@kw.igs.net */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class h1a extends Applet implements ActionListener { int kk=0; double gr=9.8; int dn; double [] y=new double[257]; String b1s="Vary Path"; Button b1=new Button(b1s); Image aim, bim; // Graphics buffers... Graphics agr, bgr; // ...for cycloid public void init() { add(b1); b1.addActionListener(this); setBackground(new Color(211, 211, 211)); } public void paint(Graphics g) { double a, b, c, fa, fb, fc, r, t, aa; int x1, y1, x2, y2, rr, del; bim=createImage(401, 201); // Initial screen bgr=bim.getGraphics(); bgr.setColor(Color.black); bgr.drawRect(0, 0, 400, 200); bgr.setColor(Color.red); bgr.fillArc(15, 35, 11, 11, 0, 360); bgr.drawArc(15, 35, 10, 10, 0, 360); bgr.fillArc(271, 85, 11, 11, 0, 360); bgr.drawArc(271, 85, 10, 10, 0, 360); bgr.setColor(Color.blue); dn=256; y[0]=0; y[256]=5; bgr.drawString("T(0) = "+(int)(10000*dt(0))/10000., 300, 35); a=Math.PI; fa=(1-Math.cos(a))/(a-Math.sin(a))-50./256; b=2*a; fb=(1-Math.cos(b))/(b-Math.sin(b))-50./256; while ((b-a)>.00001) { // Bisection algorithm c=(b+a)/2; fc=(1-Math.cos(c))/(c-Math.sin(c))-50./256; if (fc*fa>0) { a=c; fa=fc; } else { b=c; fb=fc; } } if (kk==0) { // Show initial screen g.drawImage(bim, 0, 0, null); g.setColor(Color.blue); g.drawLine(20, 40, 276, 90); } else { aim=createImage(401, 201); // Generate cycloid agr=aim.getGraphics(); c=(a+b)/2; r=y[256]/(1-Math.cos(c)); t=c*Math.sqrt(r/gr); bgr.setColor(Color.magenta); agr.setColor(Color.black); x1=20; y1=40; rr=(int)(10*r); del=10; long tt=System.currentTimeMillis(); // Initialize timing for (int i=1; i<=200; i=i+1) { aa=i*c/200; x2=20+(int)(10*r*(aa-Math.sin(aa))); y2=40+(int)(10*r*(1-Math.cos(aa))); bgr.drawLine(x1, y1, x2, y2); x1=20+(int)(10*r*aa); agr.drawImage(bim, 0, 0, null); agr.drawLine(x2, y2, x1, 40+rr); agr.drawArc(x1-rr, 40, 2*rr, 2*rr, 0, 360); agr.setColor(Color.red); agr.fillArc(x2-5, y2-5, 10, 10, 0, 360); agr.setColor(Color.blue); agr.drawLine(20, 40, 276, 90); agr.setColor(Color.black); g.drawImage(aim, 0, 0, null); x1=x2; y1=y2; tt=tt+del; while (System.currentTimeMillis()