- SSS Triangle Solver
- 09 Apr 2015 11:28:57 am
- Last edited by Ekyl on 13 Jun 2019 03:22:46 pm; edited 1 time in total
Never work on an SSS triangle again!
I've created a program to solve any triangle given its three sides.
Using the law of cosines and the law of sines, this program will output the angles of any triangle.
Code:
I've created a program to solve any triangle given its three sides.
Using the law of cosines and the law of sines, this program will output the angles of any triangle.
Code:
"The SSS
"Triangle Solver!
"Made By
"Erica DiGiulio
//Get variables
Input "Side a=",A
Input "Side b=",B
Input "Side c=",C
//Testing if the triangle is valid
If A+B<=C or A+C<=B or B+C<=A or A<=0 or B<=0 or C<=0
Then
Disp " "
Disp "Not a valid"
Disp "Triangle"
Stop
End
//Testing for equilateral triangles
If A=B and B=C
Then
Disp " "
Disp "All angles are"
Disp "60^^o"
Stop
End
//Testing for isosceles trianges
If A=B or A=C or B=C
Then
Goto 3
Else
Goto 4
End
//Isosceles solver
Lbl 3
If A=B
Then
cos^-1(((C/2)/A)->H
H->G
180-(H+G)->I
End
If A=C
Then
cos^-1(((B/2)/A)->I
I->G
180-(I+G)->H
End
If C=B
Then
cos^-1(((A/2)/C)->H
H->G
180-(H+I)->G
End
Goto 42
//Testing for longest side
Lbl 4
If A>B and A>C
Then
Goto 6
Else
Goto 5
End
Lbl 5
If B>C and B>A
Then
Goto 7
Else
Goto 8
End
//Calculating angles
//Variables will be saved ABC->GHI and then will be converted back
Lbl 6
cos^-1(((B^^2+C^^2-A^^2)/(2BC))->G
sin^-1(((B/A)*(sin(G))->H
180-(G+H)->I
Goto 42
Lbl 7
cos^-1(((A^^2+C^^2-B^^2)/(2AC))->H
sin^-1(((A/B)*(sin(H))->G
180-(G+H)->I
Goto 42
Lbl 8
cos^-1(((A^^2+B^^2-C^^2)/(2AB))->I
sin^-1(((A/C)*(sin(I))->G
180-(I+G)->H
Goto 42
//Display the answer
Lbl 42
round(G,2)->A
round(H,2)->B
round(I,2)->C
Disp " "
ClrHome
Output(2,2,"Angle A: ")
Output(2,11,A)
Output(3,2,"Angle B: ")
Output(3,11,B)
Output(4,2,"Angle C: ")
Output(4,11,C)
Disp " "
Disp " "
Disp " "
Disp " "
Disp " "
Stop