Replies: 1 comment
|
Pretty solid triangle calculator. One thing though - what happens if someone types in numbers that can't actually form a triangle? Like 1, 2, 10? The acos will blow up with a domain error. Might wanna check that a+b>c and all that before running the math. Also the median formula looks off, pretty sure it should be sqrt((2b²+2c²-a²)/4) not what's there. Could be wrong tho, been a while since I did this stuff. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
import math
a,b,c=float(input("a(unit)=")),float(input("b(unit)=")),float(input("c(unit)="))
print("\n")
A=math.acos((b2+c2-a2)/(2bc))
B=math.acos((c2+a2-b2)/(2ca))
C=math.acos((a2+b2-c**2)/(2ab))
s=(a+b+c)/2
Area=math.pow(s*(s-a)(s-b)(s-c),0.5)
Out_r=a/math.sin(A)/2
In_r=(a+b-c)/2*math.tan(C/2)
Ex_r_a=a/(math.tan(B/2)+math.tan(C/2))
Ex_r_b=b/(math.tan(C/2)+math.tan(A/2))
Ex_r_c=c/(math.tan(A/2)+math.tan(B/2))
Med_a=math.pow((2*(cc+bb)-aa)/4,.5)
Med_b=math.pow((2(cc+aa)-bb)/4,.5)
Med_c=math.pow((2(aa+bb)-c*c)/4,.5)
Bisec_A=2Area/(amath.cos((B-C)/2))
Bisec_B=2Area/(bmath.cos((C-A)/2))
Bisec_C=2Area/(cmath.cos((A-B)/2))
print("A=",A180/math.pi,"°")
print("B=",B180/math.pi,"°")
print("C=",C*180/math.pi,"°","\n")
print("Circumference=",s*2," unit")
print("Area=",Area," sq.unit","\n")
print("h(a)=",Area2/a," unit")
print("h(b)=",Area2/b," unit")
print("h(c)=",Area*2/c," unit","\n")
print("Median(a)=",Med_a," unit")
print("Median(b)=",Med_b," unit")
print("Median(c)=",Med_c," unit","\n")
print("Bisector(A)=",Bisec_A," unit")
print("Bisector(B)=",Bisec_B," unit")
print("Bisector(C)=",Bisec_C," unit","\n")
print("Outradius=",Out_r," unit")
print("Inradius=",In_r," unit")
print("Extraradius(a)=",Ex_r_a," unit")
print("Extraradius(b)=",Ex_r_b," unit")
print("Extraradius(c)=",Ex_r_c," unit","\n")
if (a+b<=c or b+c<=a or c+a<b or c+a<=b):
print("This is Not a Triangle")
elif a==b and b==c:
print("Equilateral Triangle")
elif (a==b and b!=c or b==c and c!=a or c==a and a!=b):
print("Isosceles Triangle")
elif a!=b and b!=c:
print("Scalene Triangle","\n")
if (A==math.pi/2 or B==math.pi/2 or C==math.pi/2):
print("Right Triangle")
elif(A>math.pi/2 or B>math.pi/2 or C>math.pi/2):
print("Obtuse Triangle")
else:
print("Acute Triangle")
All reactions