Skip to content
Snippets Groups Projects
Commit 9ac6fb3e authored by Sepehr Bayat's avatar Sepehr Bayat
Browse files

Update TriangleADT.py

parent 5dc5a0b8
No related branches found
No related tags found
No related merge requests found
...@@ -24,16 +24,15 @@ class Triangle: ...@@ -24,16 +24,15 @@ class Triangle:
# @return The sides of the triangle # @return The sides of the triangle
def sides(self): def sides(self):
seq = [0,0,0] seq = [0,0,0]
self.seq[0] = self.__a.dist(self.__b) seq[0] = self.__a.dist(self.__b)
self.seq[1] = self.__a.dist(self.__c) seq[1] = self.__a.dist(self.__c)
self.seq[2] = self.__b.dist(self.__c) seq[2] = self.__b.dist(self.__c)
return seq; return seq;
## @brief Inequality theorem ## @brief Inequality theorem
# @return the existence of a triangle # @return the existence of a triangle
def inequality_theorem(self): def inequality_theorem(self):
seq = self.sides() 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]):
if (self.seq[0] +self.seq[1] > self.seq[2] and self.seq[0]+self.seq[2] > self.seq[1] and self.seq[1]+self.seq[2] >self.seq[1]):
return True; return True;
elif (self.__a.xcoord()==self.__b.xcoord()==self.__c.xcoord() or self.__a.ycoord()==self.__b.ycoord()==self.__c.ycoord()): elif (self.__a.xcoord()==self.__b.xcoord()==self.__c.xcoord() or self.__a.ycoord()==self.__b.ycoord()==self.__c.ycoord()):
return False; return False;
...@@ -43,19 +42,17 @@ class Triangle: ...@@ -43,19 +42,17 @@ class Triangle:
## @brief perimeter ## @brief perimeter
# @return the perimeter of the triangle # @return the perimeter of the triangle
def perimeter_of_triangle(self): def perimeter_of_triangle(self):
seq = self.sides()
if self.inequality_theorem(): if self.inequality_theorem():
return self.seq[0]+self.seq[1]+self.seq[2] return self.sides()[0]+self.sides()[1]+self.sides()[2]
else: else:
print("You can't have a triangle with the points") print("You can't have a triangle with the points")
## @brief area ## @brief area
# @return the area of the triangle # @return the area of the triangle
def area_of_triangle(self): def area_of_triangle(self):
seq = self.sides()
if self.inequality_theorem(): if self.inequality_theorem():
P = (self.seq[0]+self.seq[1]+self.seq[2])/2 P = (self.sides()[0]+self.sides()[1]+self.sides()[2])/2
return sqrt(P*(P-self.seq[0])*(P-self.seq[1])*(P-self.seq[2])) return sqrt(P*(P-self.sides()[0])*(P-self.sides()[1])*(P-self.sides()[2]))
else: else:
print("You can't have a triangle with the points") print("You can't have a triangle with the points")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment