Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Александър Чаушев
- #16-Б / ИУ 7
- import math
- xA = float (input("Type in X coordinates first point: "))
- yA = float (input("Type in Y coordinates first point: "))
- xB = float (input("Type in X coordinates second point: "))
- yB = float (input("Type in Y coordinates second point: "))
- xC = float (input("Type in X coordinates third point: "))
- yC = float (input("Type in Y coordinates third point: "))
- AB = math.sqrt((xB-xA)**2 + (yB-yA)**2) #c
- AC = math.sqrt((xC-xA)**2 + (yC-yA)**2) #a
- BC = math.sqrt((xC-xB)**2 + (yC-yB)**2) #b
- cosA = (BC**2+AB**2-AC**2)/2*BC*AB
- cosB = (AC**2+AB**2-BC**2)/2*AC*AB
- cosC = (AC**2+BC**2-AB**2)/2*AC*BC
- p = (AB+AC+BC)/2
- list1 = [cosA, cosB, cosC]
- checkX = (xA - xC)/(xB - xC)
- checkY = (yA - yC)/(yB - yC)
- if checkX == checkY:
- print("This is not a triangle!")
- else:
- print("AB: {:7g}".format(AB))
- print("AC: {:7g}".format(AC))
- print("BA: {:7g}".format(BC))
- if max(list1) == cosA:
- Ha = (2/AC)*math.sqrt(p*(p-AC)*(p-BC)*(p-AB))
- print("Height: {:7g}".format(Ha))
- if max(list1) == cosB:
- Hb = (2/BC)*math.sqrt(p*(p-AC)*(p-BC)*(p-AB))
- print("Height: {:7g}".format(Hb))
- if max(list1) == cosC:
- Hc = (2/AB)*math.sqrt(p*(p-AC)*(p-BC)*(p-AB))
- print("Height: {:7g}".format(Hc))
- if cosA < 0 and cosB > 0 and cosC > 0:
- print("triangle is Obtuse")
- elif cosB < 0 and cosC > 0 and cosA > 0:
- print("triangle is Obtuse")
- elif cosC < 0 and cosA > 0 and cosC > 0:
- print("triangle is Obtuse")
- else:
- print("triangle is not Obtuse")
- xN = float (input("Type in X coordinates first point: "))
- yN = float (input("Type in Y coordinates first point: "))
- sumA = xA + yA
- sumB = xB + yB
- sumC = xC + yC
- sumN = xN + yN
- SumA1 = sumA - sumN
- SumB1 = sumB - sumN
- SumC1 = sumC - sumN
- if xA > xB and xA> xC:
- biggestX = xA
- if xB > xA and xB > xC:
- biggestX = xB
- if xC > xA and xC> xB:
- biggestX = xC
- if yA > yB and yA > yC:
- smallestY = yA
- if yB > yA and yB > yC:
- biggestY = yB
- if yC > yB and yC> yA:
- biggestY = yC
- if xA < xB and xA < xC:
- smallestX = xA
- if xB < xA and xB < xC:
- smallestX = xB
- if xC < xA and xC < xB:
- smallestX = xC
- if yA < yB and yA < yC:
- smallestY = yA
- if yB < yA and yB < yC:
- smallestY = yB
- if yC < yB and yC < yA:
- smallestY = yC
- if xN <= biggestX and xN >= smallestX and yN <= biggestY and yN >= smallestY:
- print("point N is in the Triangle")
- else:
- print("point N is not in the Triangle")
- if SumA1 > SumB1 and SumA1 > SumC1:
- distanceA1 = math.sqrt((xN-xA)**2 + (yN-yA)**2)
- print("Distance to the farest point is: {:7g}".format(distanceA1))
- elif SumB1 > SumA1 and SumB1 > SumC1:
- distanceB1 = math.sqrt((xN-xB)**2 + (yN-yB)**2)
- print("Distance to the farest point is: {:7g}".format(distanceB1))
- elif SumC1 > SumB1 and SumC1 > SumA1:
- distanceC1 = math.sqrt((xN-xC)**2 + (yN-yC)**2)
- print("Distance to the farest point is: {:7g}".format(distanceC1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement