\START92\ \COMMENT= \NAME=trisolve \FILE=TRISOLVE.89P trisolve() Prgm \(C)\ Rob "Astro" Bauer \(C)\ rbauer@tekro.com (send questions/bugs) \(C)\ 16 NOV 2003 \(C)\ Copyleft (C) 2003 \(C)\ 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+cline\->\cline endif if b \!=\ 0 then Output cline,1, "B: " & string(b) 10+cline\->\cline endif if c \!=\ 0 then Output cline,1, "C: " & string(c) 10+cline\->\cline endif if aa \!=\ 0 then Output cline,1, "\/_\a: " & string(aa) 10+cline\->\cline endif if ab \!=\ 0 then Output cline,1, "\/_\b: " & string(ab) 10+cline\->\cline endif if ac \!=\ 0 then Output cline,1, "\/_\c: " & string(ac) 10+cline\->\cline endif EndPrgm ClrIO setMode("Exact/Approx","APPROXIMATE") Local pValue1,pValue2,pValue3,tripart1,tripart2,tripart3,A,B,C,aa,ab,ac,tritype,key,target,found 0\->\A 0\->\B 0\->\C 0\->\aa 0\->\ab 0\->\ac ""\->\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 \(C)\ 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\^-1\((a^2-(b^2+c^2))/(\(-)\2*b*c))\->\aa cos\^-1\((b^2-(a^2+c^2))/(\(-)\2*a*c))\->\ab cos\^-1\((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)) \(C)\ Output 40,1, "Area: " & string(garea(aa,ab)) \(C)\ Output 50,1, "Area: " & string(garea(aa,ac)) EndIf If tritype = "AAS" or tritype = "ASA" or tritype = "SAA" then 0\->\sidea 0\->\sideb 0\->\sidec 0\->\anglea 0\->\angleb 0\->\anglec If aa = 0 then 180-ab-ac\->\aa aa\->\anglea endif If ab = 0 then 180-aa-ac\->\ab ab\->\angleb endif If ac = 0 then 180-ab-aa\->\ac ac\->\anglec endif if a = 0 and b = 0 then (c*sin(ab))/sin(ac)\->\b (c*sin(aa))/sin(ac)\->\a a\->\sidea b\->\sideb endif if a = 0 and c = 0 then (b*sin(ac))/sin(ab)\->\c (b*sin(aa))/sin(ab)\->\a a\->\sidea c\->\sidec endif if c = 0 and b = 0 then (a*sin(ab))/sin(aa)\->\b (a*sin(ac))/sin(aa)\->\c c\->\sidec b\->\sideb endif sresult(sidea,sideb,sidec,anglea,angleb,anglec,0) Output 30,1, "Perimeter: " & string(gperim(a,b,c)) \(C)\ Output 40,1, "Area: " & string(garea(aa,ab)) \(C)\ 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 0\->\sidea 0\->\sideb 0\->\sidec 0\->\anglea 0\->\angleb 0\->\anglec 0\->\found 0\->\aa2 0\->\ab2 0\->\ac2 If aa \!=\ 0 then aa\->\target endif If ab \!=\ 0 then ab\->\target endif If ac \!=\ 0 then ac\->\target endif \(C)\ 2 sides and 1 angle if aa \!=\ 0 and a \!=\ 0 and ab = 0 and b \!=\ 0 then sin\^-1\(b*sin(aa)/a)\->\ab ab\->\angleb ab\->\found 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\^-1\(c*sin(aa)/a)\->\ac ac\->\anglec ac\->\found 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\^-1\(a*sin(ab)/b)\->\aa aa\->\anglea aa\->\found 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\^-1\(c*sin(ab)/b)\->\ac ac\->\anglec ac\->\found 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\^-1\(b*sin(ac)/c)\->\ab ab\->\angleb ab\->\found 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\^-1\(a*sin(ac)/c)\->\aa aa\->\anglea aa\->\found if (180-aa)+target < 180 then (180-aa)\->\aa2 endif endif if aa = 0 and ab \!=\ 0 and ac \!=\ 0 then 180-ab-ac\->\aa aa\->\anglea endif if ab = 0 and aa \!=\ 0 and ac \!=\ 0 then 180-aa-ac\->\ab ab\->\angleb endif if ac = 0 and ab \!=\ 0 and aa \!=\ 0 then 180-ab-aa\->\ac ac\->\anglec endif if aa \!=\ 0 and a = 0 then \root\(b^2+c^2-2*b*c*cos(aa))\->\a a\->\sidea endif if ab \!=\ 0 and b = 0 then \root\(a^2+c^2-2*a*c*cos(ab))\->\b b\->\sideb endif if ac \!=\ 0 and c = 0 then \root\(a^2+b^2-2*a*b*cos(ac))\->\c c\->\sidec endif \(C)\ 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\^-1\((b^2+c^2-a^2)/(2*b*c))\->\aa aa\->\anglea EndIf if ab = 0 and c \!=\ 0 and a \!=\ 0 and b \!=\ 0 Then cos\^-1\((a^2-b^2+c^2)/(2*a*c))\->\ab ab\->\angleb EndIf if ac = 0 and c \!=\ 0 and a \!=\ 0 and b \!=\ 0 Then cos\^-1\((a^2+b^2-c^2)/(2*b*a))\->\ac ac\->\anglec 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-target\->\ab2 endif if anglec \!=\ 0 then 180-aa2-target\->\ac2 endif endif if ab2 \!=\ 0 then if anglea \!=\ 0 then 180-ab2-target\->\aa2 endif if anglec \!=\ 0 then 180-ab2-target\->\ac2 endif endif if anglec \!=\ 0 then if anglea \!=\ 0 then 180-ac2-target\->\aa2 endif if angleb \!=\ 0 then 180-ac2-target\->\ab2 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 \STOP92\