I put together a program in Python to use the law of cosines to figure out missing sides or angles in a triangle. The portion of the program that calculates the missing angle for a side-side-side triangle goes like so:
usedegrees = True
opptheta = 4
sideb = 8
sidec = 9
asqrd = opptheta**2
bsqrd = sideb**2
csqrd = sidec**2
costheta = (bsqrd+csqrd-asqrd)/(2.0*sideb*sidec)
if usedegrees:
print degrees(acos(costheta))
else:
print acos(costheta)
It was calculating incorrectly when I assigned the costheta
with (bsqrd+csqrd-asqrd)/(2*sideb*sidec)
(The costheta
variable output 0
).
So my question is, is why did the change of the 2
to 2.0
in the law of cosines formula fix the bug and make costheta
have an output the program could work with to perform the calculation?