Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #Александър Чаушев
  2. #16-Б / ИУ 7
  3. import math
  4.  
  5. xA = float (input("Type in X coordinates first point: "))
  6. yA = float (input("Type in Y coordinates first point: "))
  7. xB = float (input("Type in X coordinates second point: "))
  8. yB = float (input("Type in Y coordinates second point: "))
  9. xC = float (input("Type in X coordinates third point: "))
  10. yC = float (input("Type in Y coordinates third point: "))
  11.  
  12. AB = math.sqrt((xB-xA)**2 + (yB-yA)**2) #c
  13. AC = math.sqrt((xC-xA)**2 + (yC-yA)**2) #a
  14. BC = math.sqrt((xC-xB)**2 + (yC-yB)**2) #b
  15. cosA = (BC**2+AB**2-AC**2)/2*BC*AB
  16. cosB = (AC**2+AB**2-BC**2)/2*AC*AB
  17. cosC = (AC**2+BC**2-AB**2)/2*AC*BC
  18. p = (AB+AC+BC)/2
  19. list1 = [cosA, cosB, cosC]
  20.  
  21.  
  22. checkX = (xA - xC)/(xB - xC)
  23. checkY = (yA - yC)/(yB - yC)
  24.  
  25. if checkX == checkY:
  26. print("This is not a triangle!")
  27. else:
  28. print("AB: {:7g}".format(AB))
  29. print("AC: {:7g}".format(AC))
  30. print("BA: {:7g}".format(BC))
  31.  
  32. if max(list1) == cosA:
  33. Ha = (2/AC)*math.sqrt(p*(p-AC)*(p-BC)*(p-AB))
  34. print("Height: {:7g}".format(Ha))
  35. if max(list1) == cosB:
  36. Hb = (2/BC)*math.sqrt(p*(p-AC)*(p-BC)*(p-AB))
  37. print("Height: {:7g}".format(Hb))
  38. if max(list1) == cosC:
  39. Hc = (2/AB)*math.sqrt(p*(p-AC)*(p-BC)*(p-AB))
  40. print("Height: {:7g}".format(Hc))
  41.  
  42. if cosA < 0 and cosB > 0 and cosC > 0:
  43. print("triangle is Obtuse")
  44. elif cosB < 0 and cosC > 0 and cosA > 0:
  45. print("triangle is Obtuse")
  46. elif cosC < 0 and cosA > 0 and cosC > 0:
  47. print("triangle is Obtuse")
  48. else:
  49. print("triangle is not Obtuse")
  50.  
  51. xN = float (input("Type in X coordinates first point: "))
  52. yN = float (input("Type in Y coordinates first point: "))
  53.  
  54. sumA = xA + yA
  55. sumB = xB + yB
  56. sumC = xC + yC
  57. sumN = xN + yN
  58.  
  59. SumA1 = sumA - sumN
  60. SumB1 = sumB - sumN
  61. SumC1 = sumC - sumN
  62.  
  63.  
  64. if xA > xB and xA> xC:
  65. biggestX = xA
  66. if xB > xA and xB > xC:
  67. biggestX = xB
  68. if xC > xA and xC> xB:
  69. biggestX = xC
  70.  
  71. if yA > yB and yA > yC:
  72. smallestY = yA
  73. if yB > yA and yB > yC:
  74. biggestY = yB
  75. if yC > yB and yC> yA:
  76. biggestY = yC
  77.  
  78.  
  79. if xA < xB and xA < xC:
  80. smallestX = xA
  81. if xB < xA and xB < xC:
  82. smallestX = xB
  83. if xC < xA and xC < xB:
  84. smallestX = xC
  85.  
  86. if yA < yB and yA < yC:
  87. smallestY = yA
  88. if yB < yA and yB < yC:
  89. smallestY = yB
  90. if yC < yB and yC < yA:
  91. smallestY = yC
  92.  
  93.  
  94. if xN <= biggestX and xN >= smallestX and yN <= biggestY and yN >= smallestY:
  95. print("point N is in the Triangle")
  96. else:
  97. print("point N is not in the Triangle")
  98.  
  99. if SumA1 > SumB1 and SumA1 > SumC1:
  100. distanceA1 = math.sqrt((xN-xA)**2 + (yN-yA)**2)
  101. print("Distance to the farest point is: {:7g}".format(distanceA1))
  102. elif SumB1 > SumA1 and SumB1 > SumC1:
  103. distanceB1 = math.sqrt((xN-xB)**2 + (yN-yB)**2)
  104. print("Distance to the farest point is: {:7g}".format(distanceB1))
  105. elif SumC1 > SumB1 and SumC1 > SumA1:
  106. distanceC1 = math.sqrt((xN-xC)**2 + (yN-yC)**2)
  107. print("Distance to the farest point is: {:7g}".format(distanceC1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement