Solving triangles
(Back)
Email the author:Paolo Bonzini
The program solves any kind of triangle. It asks the number of known sides (anything but
1 and 2 is interpreted as three known sides). It is quite versatile, but you should study
the code to avoid losing time, because it makes some assumptions on how the sides and
angles that you give are called.
Note that I don't use sine theorem to get angles except when I have to, because arc-sine
might answer negative values; instead arc-cosine does not.
Program. Note: lowercase letters can be found under VARS/H/B; cos-1 means arc-cosine,
i.e. 2ndF/cos, and sin-1 means arc-sine; \ means square root; PiR means PI (2ndF/VARS)
followed by radians symbol (MATH/E/4).
Print "SIDES"
Input S
Input A
If S=1 Goto ONE
Input B
If S=2 Goto TWO
Input C
Print "CAB"
Print cos-1 ((B^2+C^2-A^2)/2BC)
Print "BCA"
Print cos-1 ((B^2-C^2+A^2)/2AB)
Print "ABC"
Print cos-1 ((A^2+C^2-B^2)/2AC)
End
Label ONE
Print "1=ACB, ABC KNOWN"
Print "2=CAB, ABC KNOWN"
Input S
Input D
Input E
PiR-D-E=>F
Print "3rd ANGLE"
Print F
If S=1 Goto ONE1
F=>D
PiR-D-E=>F
Label ONE1
Print "b"
Print Asin E/sin F
Print "c"
Print Asin D/sin F
End
Label TWO
Print "KNOWN ANGLE:"
Print "1=INCLUDED"
Print "2=OPPOSITE b"
Input S
Input F
If S=1 Goto TWO1
sin-1 (Asin F/B)=>D
If D>0 Goto ANGOK
D+PiR=>D
Label ANGOK
Gosub TWO2
Wait
PiR-D=>D
Gosub TWO2
End
Label TWO2
PiR-D-F=>E
Print "CAB"
Print D
Print "BCA"
Print E
Print "c"
Print Bsin E/sin F
Return
Label TWO1
\(A^2+B^2-2ABcos F)=>C
Print "ABC"
Print cos-1 ((A^2+C^2-B^2)/2AC)
Print "CAB"
Print cos-1 ((B^2+C^2-A^2)/2BC)
Print "c"
Print C
End