' fglflib.bas - jackord@kw.igs.net - revised 13 Oct 05 - Liberty Basic v4.01 ' 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 ' Initialize Window nomainwin button#1, "Wind", [wind], UL, 5, 5, 50, 20 WindowWidth=460 ' pixel scale 0-450 WindowHeight=169 ' pixel scale 0-140 UpperLeftX=100: UpperLeftY=100: kk=0: rr=0 open "Windy golf" for graphics_nsb as #1 #1 "trapclose [quit]" #1 "down ; color black; line 10 70 440 70" vb=44.7: vw=4.47: gr=9.8: vt=33.7: dt=.01 ' Constants vx=.8*vb: vz=.6*vb: gosub [hit] ' No wind x1=8+int(4*xf+.5) #1 "color green ; backcolor green ; place "; x1; " 70 ; circlefilled 60" #1 "color red ; backcolor red ; place "; x1; " 70 ; circlefilled 5" #1 "place 8 70 ; circlefilled 5" #1 "place 30 55 ; color black ; backcolor white" #1 "\No Wind X = "; using("##.##", xf); " m T = "; using("#.##", tf); " s" [waitHere] wait [wind] vx=.8*vb+vw: vz=.6*vb: gosub [hit] ' Headwind xf=xf-vw*tf: x1=8+int(4*xf+.5) #1 "color red ; backcolor red ; place "; x1; " 70 ; circlefilled 5" #1 "place 30 90 ; color black ; backcolor white" #1 "\Headwind X = "; using("##.##", xf); " m T = "; using("#.##", tf); " s" vx=.8*vb-vw: vz=.6*vb: gosub [hit] ' Tailwind xf=xf+vw*tf: x1=8+int(4*xf+.5) #1 "color red ; backcolor red ; place "; x1; " 70 ; circlefilled 5" #1 "place 30 110 ; color black ; backcolor white" #1 "\Tailwind X = "; using("###.##", xf); " m T = "; using("#.##", tf); " s" v=sqr(.64*vb*vb+vw*vw): vx=v: vz=.6*vb: gosub [hit] ' Crosswind yf=vw*tf-xf*vw/v: xf=xf*.8*vb/v x1=8+int(4*xf+.5): y1=int(4*yf+.5) #1 "color red ; backcolor red ; place "; x1; " "; 70-y1: #1 "circlefilled 5" #1 "color red ; backcolor red ; place "; x1; " "; 70+y1: #1 "circlefilled 5" #1 "place 30 130 ; color black ; backcolor white" #1 "\Crosswind X = "; using("##.##", xf); " m T = "; using("#.##", tf); " s Y = "; using("#.##", yf); " m" goto [waitHere] [hit] ' Hit the ball t=0: x=0: z=0: dvx=0: dvz=0 gosub [acc]: dvx=ax*dt: dvz=az*dt: vx=vx+dvx/2: vz=vz+dvz/2 while z>=0 ' Feynman loop t=t+dt: x=x+vx*dt: z=z+vz*dt gosub [acc]: dvx=ax*dt: dvz=az*dt: vx=vx+dvx: vz=vz+dvz wend xf=x-vx*z/vz: tf=t-z/vz ' Return xf, tf return [acc] ' Newton's Law ux=vx+dvx/2: uz=vz+dvz/2: u=sqr(ux*ux+uz*uz)*gr/vt/vt ax=0-ux*u: az=0-uz*u-gr return [quit] close #1 end