trisolve() Prgm Rob "Astro" Bauer rbauer@tekro.com (send questions/bugs) 16 NOV 2003 Copyleft (C) 2003 Copyleft is a general method for making a program free software and requiring all modified and extended versions of the program to be free software as well. local gperim Define gperim(a,b,c)=Func Return a+b+c EndFunc local garea Define garea(aangle,aside)=Func Return ((aside*sin(aangle)) * aside * .5) EndFunc local sresult Define sresult(a,b,c,aa,ab,ac,cline)=Prgm if a 0 then Output cline,1, "A: " & string(a) 10+clinecline endif if b 0 then Output cline,1, "B: " & string(b) 10+clinecline endif if c 0 then Output cline,1, "C: " & string(c) 10+clinecline endif if aa 0 then Output cline,1, "a: " & string(aa) 10+clinecline endif if ab 0 then Output cline,1, "b: " & string(ab) 10+clinecline endif if ac 0 then Output cline,1, "c: " & string(ac) 10+clinecline endif EndPrgm ClrIO setMode("Exact/Approx","APPROXIMATE") Local pValue1,pValue2,pValue3,tripart1,tripart2,tripart3,A,B,C,aa,ab,ac,tritype,key,target,found 0A 0B 0C 0aa 0ab 0ac ""tritype Dialog Title "Define Triangle Pieces" DropDown "Triangle Piece 1",{"Side A", "Side B", "Side C", "Angle a", "Angle b", "Angle c"},tripart1 Request "Value",pValue1,0 DropDown "Triangle Piece 2",{"Side A", "Side B", "Side C", "Angle a", "Angle b", "Angle c"},tripart2 Request "Value",pValue2,0 DropDown "Triangle Piece 3",{"Side A", "Side B", "Side C", "Angle a", "Angle b", "Angle c"},tripart3 Request "Value",pValue3,0 endDlog User hit Escape on the dialog box If ok = 0 then DispHome Stop EndIf If tripart1 = 1 Then expr(pValue1)A EndIf If tripart1 = 2 Then expr(pValue1)B EndIf If tripart1 = 3 Then expr(pValue1)C EndIf If tripart1 = 4 Then expr(pValue1)aa EndIf If tripart1 = 5 Then expr(pValue1)ab EndIf If tripart1 = 6 Then expr(pValue1)ac EndIf If tripart1 > 3 Then "A"tritype else "S"tritype EndIf If tripart2 = 1 Then expr(pValue2)A EndIf If tripart2 = 2 Then expr(pValue2)B EndIf If tripart2 = 3 Then expr(pValue2)C EndIf If tripart2 = 4 Then expr(pValue2)aa EndIf If tripart2 = 5 Then expr(pValue2)ab EndIf If tripart2 = 6 Then expr(pValue2)ac EndIf If tripart2 > 3 Then tritype & "A"tritype else tritype & "S"tritype EndIf If tripart3 = 1 Then expr(pValue3)A EndIf If tripart3 = 2 Then expr(pValue3)B EndIf If tripart3 = 3 Then expr(pValue3)C EndIf If tripart3 = 4 Then expr(pValue3)aa EndIf If tripart3 = 5 Then expr(pValue3)ab EndIf If tripart3 = 6 Then expr(pValue3)ac EndIf If tripart3 > 3 Then tritype & "A"tritype else tritype & "S"tritype EndIf if tripart1 < 4 and tripart2 < 4 and tripart3 < 4 THEN cos((a^2-(b^2+c^2))/(2*b*c))aa cos((b^2-(a^2+c^2))/(2*a*c))ab cos((c^2-(b^2+a^2))/(2*b*a))ac sresult(0,0,0,aa,ab,ac,0) Output 30,1, "Perimeter: " & string(gperim(a,b,c)) Output 40,1, "Area: " & string(garea(aa,ab)) Output 50,1, "Area: " & string(garea(aa,ac)) EndIf If tritype = "AAS" or tritype = "ASA" or tritype = "SAA" then 0sidea 0sideb 0sidec 0anglea 0angleb 0anglec If aa = 0 then 180-ab-acaa aaanglea endif If ab = 0 then 180-aa-acab abangleb endif If ac = 0 then 180-ab-aaac acanglec endif if a = 0 and b = 0 then (c*sin(ab))/sin(ac)b (c*sin(aa))/sin(ac)a asidea bsideb endif if a = 0 and c = 0 then (b*sin(ac))/sin(ab)c (b*sin(aa))/sin(ab)a asidea csidec endif if c = 0 and b = 0 then (a*sin(ab))/sin(aa)b (a*sin(ac))/sin(aa)c csidec bsideb endif sresult(sidea,sideb,sidec,anglea,angleb,anglec,0) Output 30,1, "Perimeter: " & string(gperim(a,b,c)) Output 40,1, "Area: " & string(garea(aa,ab)) Output 50,1, "Area: " & string(garea(aa,ac)) endif If tritype = "ASS" or tritype = "SSA" or tritype = "SAS" then local aa2,ab2,ac2,found,target,sidea,sideb,sidec,anglea,angleb,anglec 0sidea 0sideb 0sidec 0anglea 0angleb 0anglec 0found 0aa2 0ab2 0ac2 If aa 0 then aatarget endif If ab 0 then abtarget endif If ac 0 then actarget endif 2 sides and 1 angle if aa 0 and a 0 and ab = 0 and b 0 then sin(b*sin(aa)/a)ab abangleb abfound if (180-ab)+target < 180 then (180-ab)ab2 endif endif if aa 0 and a 0 and ac = 0 and c 0 then sin(c*sin(aa)/a)ac acanglec acfound if (180-ac)+target < 180 then (180-ac)ac2 endif endif if ab 0 and b 0 and aa = 0 and a 0 then sin(a*sin(ab)/b)aa aaanglea aafound if (180-aa)+target < 180 then (180-aa)aa2 endif endif if ab 0 and b 0 and ac = 0 and c 0 then sin(c*sin(ab)/b)ac acanglec acfound if (180-ac)+target < 180 then (180-ac)ac2 endif endif if ac 0 and c 0 and ab = 0 and b 0 then sin(b*sin(ac)/c)ab abangleb abfound if (180-ab)+target < 180 then (180-ab)ab2 endif endif if ac 0 and c 0 and aa = 0 and a 0 then sin(a*sin(ac)/c)aa aaanglea aafound if (180-aa)+target < 180 then (180-aa)aa2 endif endif if aa = 0 and ab 0 and ac 0 then 180-ab-acaa aaanglea endif if ab = 0 and aa 0 and ac 0 then 180-aa-acab abangleb endif if ac = 0 and ab 0 and aa 0 then 180-ab-aaac acanglec endif if aa 0 and a = 0 then (b^2+c^2-2*b*c*cos(aa))a asidea endif if ab 0 and b = 0 then (a^2+c^2-2*a*c*cos(ab))b bsideb endif if ac 0 and c = 0 then (a^2+b^2-2*a*b*cos(ac))c csidec endif At this point, we should have all 3 sides - just need angles now if aa = 0 and c 0 and a 0 and b 0 Then cos((b^2+c^2-a^2)/(2*b*c))aa aaanglea EndIf if ab = 0 and c 0 and a 0 and b 0 Then cos((a^2-b^2+c^2)/(2*a*c))ab abangleb EndIf if ac = 0 and c 0 and a 0 and b 0 Then cos((a^2+b^2-c^2)/(2*b*a))ac acanglec EndIf if target+found < 180 and (180-found) + target < 180 then sresult(sidea,sideb,sidec,anglea,angleb,anglec,0) if aa2 0 then if angleb 0 then 180-aa2-targetab2 endif if anglec 0 then 180-aa2-targetac2 endif endif if ab2 0 then if anglea 0 then 180-ab2-targetaa2 endif if anglec 0 then 180-ab2-targetac2 endif endif if anglec 0 then if anglea 0 then 180-ac2-targetaa2 endif if angleb 0 then 180-ac2-targetab2 endif endif if sidea 0 then (c*sin(aa2))/sin(ac)sidea endif if sidea 0 then (a*sin(ab2))/sin(aa)sidea endif if sidec 0 then (a*sin(ac2))/sin(aa)sidec endif sresult(sidea,sideb,sidec,aa2,ab2,ac2,40) Output 30,1, "Perimeter: " & string(gperim(a,b,c)) else sresult(sidea,sideb,sidec,anglea,angleb,anglec,0) Output 30,1, "Perimeter: " & string(gperim(a,b,c)) endif EndIf Loop getKey()key while key=0 getKey()key EndWhile if key = 46 then Disp "" Disp "Coder: Rob Bauer" Disp "16 November 2003" Disp "Solve any 3 missing" Disp "triangle parts" Disp "" elseif key = 13 then trisolve() else DispHome Stop endif EndLoop EndPrgm