'h1blib.bas - jackord@kw.igs.net - revised 10 Sep 02 - Liberty Basic v3.01 ' hanging chain (n mass points on an n+1 segment string) ' chain length = 400, n = 64 ' support separation: horizontal 240, vertical 120 ' the string tension and angle at the left support are varied ' to bring the end of the string to the right support ' the analytic curve is a catenary (with integer constants) ' Initialize Window nomainwin button#1, "Vary", [vr], UL, 60, 5, 40, 20 button#1, "Anal", [an], UL, 110, 5, 40, 20 WindowWidth=310 ' pixel scale 0-300 WindowHeight=269 ' pixel scale 0-240 UpperLeftX=100: UpperLeftY=100 open "Catenary" for graphics_nsb as #1 ' no slide bars #1 "trapclose [quit]" gosub [pin] [waitHere] wait [pin] ' Initial screen #1 "cls ; down ; color red ; place 10 10 ; circle 5" #1 "place 250 130 ; circle 5 ; color blue" n=64: d=400/(n+1): phi=0-6000: pi=4*atn(1): tns=48: dtns=2 show=1: gosub [hit] #1 "color white ; backcolor white ; place 160 5 ; boxfilled 260 25 ; color black" #1 "\\Dev = "; using("##.##", s) return [vr] gosub [pin] while s>.1 ' Vary initial tesion tns=tns+dtns: ss=s: gosub [ang] ' ...and angle if s>ss then dtns=0-dtns/2 scan wend ' ...to reach support #1 "color red": gosub [hit] goto [waitHere] [an] gosub [pin] a=152: c=69: b=27-c ' Catenary constants x=(250-a)/c: y=(10-a)/c y=c/2*(exp(x)-exp(0-x)-exp(y)+exp(0-y)) #1 "color white ; backcolor white ; place 160 5 ; boxfilled 260 25 ; color black" #1 "\\Length = "; int(y) ' Catenary length #1 "color red" for i=10 to 250 ' Plot catenary x=(i-a)/c: y=b+c/2*(exp(x)+exp(0-x)): y1=240-int(y) if i=10 then #1 "place "; i; " "; y1 else #1 "goto "; i; " "; y1 end if next i goto [waitHere] [ang] ' Find optimum angle show=0: dph=0-256: gosub [hit] while abs(dph)>1 phi=phi+dph: so=s: gosub [hit] if s>so then dph=0-dph/2 wend phi=phi+2*dph: show=1: #1 "color blue" : gosub [hit] #1 "color white ; backcolor white ; place 160 5 ; boxfilled 260 25 ; color black" #1 "\\Dev = "; using("##.##", s) return [hit] ' Trace out string x=10: y=10: q=phi*pi/18000: t=tns ' First angle & tension tn=tan(q): tc=t*cos(q) x=x+d*cos(q): y=y-d*sin(q) if show=1 then #1 "line 10 10 "; int(x); " "; int(y) for i=1 to n ' Loop tn=tn+1/tc: q=atn(tn): t=tc/cos(q) ' Next angle & tension x=x+d*cos(q): y=y-d*sin(q) if show=1 then #1 "goto "; int(x); " "; int(y) next i s=((x-250)*(x-250)+(y-130)*(y-130))^.5 ' Deviation return [quit] close #1 end