## @file TriangleADT.py # @author Sepehr # @brief Provides the Triangle CLass for Perimeter Area and existence of triangle # @date 25 Jan 2018 from pointT import * ##@brief An ADT that respresents a 2D point class Triangle: ## @brief Triangle constructor # @details Initializes a Triangle with three points a,b,c # @param a One side of triangle # @param b One side of triangle # @param c One side of triangle def __init__(self, p1, p2,p3): self.__a = p1 self.__b = p2 self.__c = p3 ## @brief Gets the sides # @return The sides of the triangle def sides(self): seq = [0,0,0] seq[0] = self.__a.dist(self.__b) seq[1] = self.__a.dist(self.__c) seq[2] = self.__b.dist(self.__c) return seq; ## @brief Inequality theorem # @return the existence of a triangle def inequality_theorem(self): if (self.sides()[0] +self.sides()[1] > self.sides()[2] and self.sides()[0]+self.sides()[2] > self.sides()[1] and self.sides()[1]+self.sides()[2] >self.sides()[1]): return True; elif (self.__a.xcoord()==self.__b.xcoord()==self.__c.xcoord() or self.__a.ycoord()==self.__b.ycoord()==self.__c.ycoord()): return False; else: return False; ## @brief perimeter # @return the perimeter of the triangle def perimeter_of_triangle(self): if self.inequality_theorem(): return self.sides()[0]+self.sides()[1]+self.sides()[2] else: print("You can't have a triangle with the points") ## @brief area # @return the area of the triangle def area_of_triangle(self): if self.inequality_theorem(): P = (self.sides()[0]+self.sides()[1]+self.sides()[2])/2 return sqrt(P*(P-self.sides()[0])*(P-self.sides()[1])*(P-self.sides()[2])) else: print("You can't have a triangle with the points")