I'm trying to find out the angle of the triangle in the following, I know it should be 90 degrees, however I don't know how to actually calculate it in the following:
Here's what I've tried:
angle = math.cos(7/9.899)
angleToDegrees = math.degrees(angle)
returns: 43.XX
What am I doing wrong?
s = (a + b + c) / 2. # calculate the area. area = (s*(s-a)*(s-b)*(s-c)) ** 0.5. print('The area of the triangle is %0.2f' %area)
It's a little more compicated than that. You need to use the law of cosines
>>> A = 7
>>> B = 7
>>> C = 9.899
>>> from math import acos, degrees
>>> degrees(acos((A * A + B * B - C * C)/(2.0 * A * B)))
89.99594878743945
This is accurate to 4 significant figures. If you provide a more precise value of C, you get a more accurate result.
>>> C=9.899494936611665
>>> degrees(acos((A * A + B * B - C * C)/(2.0 * A * B)))
90.0
You can use this also.
print(str(int(round(math.degrees(math.atan2(x,y)))))+'°')
This accepts two inputs as two heights of the triangle and you can get the output angle in proper degree format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With