/* * h6a.java - revised 19 Apr 05 - width 433, height 361 * @author jackord@kw.igs.net * central force motion: apsidal angle integral */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class h6a extends Applet implements ActionListener { int kk=0; int norbit=1; int orbit=0; // Declarations double c=0; double dr=0; double [] dtheta=new double[1001]; String b1s="-2"; Button b1=new Button(b1s); String b2s="-1"; Button b2=new Button(b2s); String b3s="+1"; Button b3=new Button(b3s); String b4s="Orbit"; Button b4=new Button(b4s); public void init() { setLayout(new FlowLayout(FlowLayout.LEFT)); add(b1); add(b2); add(b3); add(b4); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); setBackground(new Color(211, 211, 211)); } public void paint(Graphics g) { double a, b, cf, e, en, x, y, ya, yb, yc, l, l2; double r, theta, z1, z2; int x1, y1, x2, y2; int np=1000; cf=5; g.setFont(new Font("TimesRoman", Font.PLAIN, 14)); g.setColor(Color.black); g.drawRect(0, 0, 432, 360); if (kk==2) { g.setColor(Color.green); g.fillArc(206, 170, 21, 21, 0, 360); g.setColor(Color.black); g.drawArc(206, 170, 20, 20, 0, 360); g.setColor(Color.red); g.drawArc(36, 0, 360, 360, 0, 360); x1=(int)(180*(1.2-c)); y1=(int)(180*(1-c)); g.drawArc(x1, y1, (int)(2*c*180+.5), (int)(2*c*180+.5), 0, 360); g.setColor(Color.blue); } else { g.drawString("Force Law Power", 0, 45); g.drawLine(216, 180, 432, 180); g.drawLine(216, 0, 216, 360); } if (kk==2) { // Plot Orbit r=1; theta=0; x1=396; y1=180; for (int j=1; j<=norbit; j=j+1) { for (int i=1; i<=np; i=i+1) { r=r-dr; theta=theta+dtheta[i]; x2=(int)(180*(1.2+r*Math.cos(theta))); y2=(int)(180*(1-r*Math.sin(theta))); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } for (int i=np; i>=1; i=i-1) { r=r+dr; theta=theta+dtheta[i]; x2=(int)(180*(1.2+r*Math.cos(theta))); y2=(int)(180*(1-r*Math.sin(theta))); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } } kk=0; orbit=0; } if (kk!=0) { g.setColor(Color.green); // Plot Energy Diagram l=.488; l2=l*l/2; x=1.2; y=l2/x/x; x1=432; y1=(int)(180*(1-y/cf)); do { x=x-.002; y=l2/x/x; x2=(int)(180*(1.2+x)); y2=(int)(180*(1-y/cf)); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } while (y-cf)&&(x>0)); g.setColor(Color.blue); x=1.2; y=l2/x/x+v(x); x1=432; y1=(int)(180*(1-y/cf)); do { x=x-.002; y=l2/x/x+v(x); x2=(int)(180*(1.2+x)); y2=(int)(180*(1-y/cf)); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } while (ye) { // Bisection Algorithm c=(a+b)/2; yc=l2/c/c+v(c); if (yc>en) { a=c; } else { b=c; } } x1=(int)(180*(1.2+c)); g.drawLine(x1, 180, x1, y1); g.drawLine(396, 180, 396, y1); // Show Apsides theta=0; z1=0; dr=(1-c)/np; // Find Apsidal Angle for (int i=1; i