/* * fglf.java - revised 8 Apr 05 - width 451, height 141 * effect of wind on a golfball hit at 100 mph at a 37 degree elevation * (a) no wind, (b) 10 mph headwind, (c) 10 mph tailwind, (d) 10 mph crosswind * @author jackord@kw.igs.net */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class fglf extends Applet implements ActionListener { int kk=0; double tf, xf, ax, ay; // Global variables String b1s="Wind"; Button b1=new Button(b1s); public void init() { setBackground(new Color(211, 211, 211)); // Light Gray Background add(b1); b1.addActionListener(this); } public void hit(double vx, double vy) { // Hit the ball double x, y, dvx, dvy, t, dt; t=0; x=0; y=0; dt=.01; acc(vx, vy); dvx=ax*dt; dvy=ay*dt; vx=vx+dvx/2; vy=vy+dvy/2; do { // Feynman loop t=t+dt; x=x+vx*dt; y=y+vy*dt; acc(vx+dvx/2, vy+dvy/2); dvx=ax*dt; dvy=ay*dt; vx=vx+dvx; vy=vy+dvy; } while (y>0); xf=x-vx*y/vy; tf=t-y/vy; // Return xf, tf } public void acc(double ux, double uy) { // Newton's Law double u; double gr=9.8; double vt=33.7; u = Math.sqrt(ux*ux+uy*uy)*gr/vt/vt; ax=-u*ux; ay=-u*uy-gr; } public void paint(Graphics g) { // Paint double vb=44.7; double vw=4.47; double v; int x1, y1; g.drawRect(0, 0, 450, 140); g.drawLine(10, 70, 440, 70); hit(.8*vb, .6*vb); // No wind x1=8+(int)(4*xf+.5); g.drawString("xf="+xf+" tf="+tf, 40, 40); g.setColor(Color.green); g.fillArc(x1-60, 70-60, 120, 120, 0, 360); g.setColor(Color.red); g.fillArc(x1-5, 70-5, 10, 10, 0, 360); g.fillArc(8-5, 70-5, 10, 10, 0, 360); if (kk==1) { hit(.8*vb+vw, .6*vb); // Headwind x1=8+(int)(4*(xf-vw*tf)+.5); g.fillArc(x1-5, 70-5, 10, 10, 0, 360); g.drawString("xf="+(xf-vw*tf)+" tf="+tf, 40, 60); hit(.8*vb-vw, .6*vb); // Tailwind x1=8+(int)(4*(xf+vw*tf)+.5); g.fillArc(x1-5, 70-5, 10, 10, 0, 360); g.drawString("xf="+(xf+vw*tf)+" tf="+tf, 40, 80); v=Math.sqrt(.64*vb*vb+vw*vw); // Crosswind hit(v, .6*vb); x1=8+(int)(4*(xf*.8*vb/v)+.5); y1=(int)(4*(vw*tf-xf*vw/v)+.5); g.fillArc(x1-5, 70-y1-5, 10, 10, 0, 360); g.fillArc(x1-5, 70+y1-5, 10, 10, 0, 360); } } public void actionPerformed(ActionEvent e) { // Button String tst; tst=e.getActionCommand(); if (b1s.equals(tst)) { kk=1; repaint(); } } }