/* * forb.java - revised 8 Apr 05 - width 401, height 301 * @author jackord@kw.igs.net */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class forb extends Applet implements ActionListener { int kk=0; // Declarations String bs="Plot"; Button b=new Button(bs); public void init() { setLayout(new FlowLayout(FlowLayout.LEFT)); add(b); b.addActionListener(this); setBackground(new Color(211, 211, 211)); } public void paint(Graphics g) { // Paint double G, M, GM, R, d, dcube, dmax, phi, phiv; double dt, v, t, x, y, vx, vy, xmin, ymax, sc; int x1, y1, x2, y2; xmin=-2E+07; ymax=1.5E+07; sc=1E-05; g.setColor(Color.black); g.drawRect(0, 0, 400, 300); g.setFont(new Font("TimesRoman", Font.PLAIN, 14)); R=6370000; x1=(int)(sc*(-R-xmin)); y1=(int)(sc*(ymax-R)); y2=(int)(2*sc*R); g.setColor(Color.green); g.fillArc(x1, y1, y2+1, y2+1, 0, 360); g.setColor(Color.black); g.drawArc(x1, y1, y2, y2, 0, 360); g.setColor(Color.blue); if (kk==1) { String ns; M=5.98E+24; G=6.672E-11; GM=G*M; d=R; dmax=R; dt=.1; v=9000; t=0; x=0; y=R; x1=(int)(sc*(x-xmin)); y1=(int)(sc*(ymax-y)); vx=v/Math.sqrt(2); vy=vx; vy=vy-GM/(R*R)*dt/2; do { t=t+dt; x=x+vx*dt; y=y+vy*dt; x2=(int)(sc*(x-xmin)); y2=(int)(sc*(ymax-y)); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; d=Math.sqrt(x*x+y*y); dcube=d*d*d; if (d>dmax) { dmax=d; } vx=vx-GM*x/dcube*dt; vy=vy-GM*y/dcube*dt; } while (d>R); v=Math.sqrt(vx*vx+vy*vy); phi=Math.atan(y/x)*180/Math.PI; phiv=Math.atan(vy/vx)*180/Math.PI-phi; if (phi<0) { ns="south"; } else { ns="north"; } g.setColor(Color.black); g.drawString("Lands at "+ns+" latitude "+(float)(Math.abs(phi))+" deg", 10, 45); g.drawString("with velocity "+(float)v+" m/s", 10, 60); g.drawString("at "+(float)phiv+" deg to the vertical", 10, 75); g.drawString("Flight time "+(float)(t/60)+" min", 10, 90); g.drawString("dmax = "+(float)(dmax/R)+" R", 10, 105); } kk=0; } public void actionPerformed(ActionEvent e) { String tst; tst=e.getActionCommand(); if (bs.equals(tst)) { kk=1; } repaint(); } }