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

Update TriangleADT.py

parent 0c3b4728
No related branches found
No related tags found
No related merge requests found
...@@ -19,20 +19,21 @@ class Triangle: ...@@ -19,20 +19,21 @@ class Triangle:
self.__a = p1 self.__a = p1
self.__b = p2 self.__b = p2
self.__c = p3 self.__c = p3
self.seq = [0,0,0]
self.sides() self.sides()
## @brief Gets the sides ## @brief Gets the sides
# @return The sides of the triangle # @return The sides of the triangle
def sides(self): def sides(self):
self.AB = pointT.dist(self.__b,self.__b) self.seq[0] = pointT.dist(self.__b,self.__b)
self.AC = pointT.dist(self.__a,self.__c) self.seq[1] = pointT.dist(self.__a,self.__c)
self.BC = pointT.dist(self.__b,self.__c) self.seq[2] = pointT.dist(self.__b,self.__c)
## @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):
self.sides() self.sides()
if (self.AB +self.AC > self.BC and self.AB+self.BC > self.AC and self.AC+self.BC >self.AB): 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,7 +44,7 @@ class Triangle: ...@@ -43,7 +44,7 @@ class Triangle:
# @return the perimeter of the triangle # @return the perimeter of the triangle
def perimeter_of_triangle(self): def perimeter_of_triangle(self):
if self.inequality_theorem(): if self.inequality_theorem():
return self.AB+self.AC+self.BC return self.seq[0]+self.seq[1]+self.seq[2]
else: else:
print("You can't have a triangle with the points") print("You can't have a triangle with the points")
...@@ -51,8 +52,8 @@ class Triangle: ...@@ -51,8 +52,8 @@ class Triangle:
# @return the area of the triangle # @return the area of the triangle
def area_of_triangle(self): def area_of_triangle(self):
if self.inequality_theorem(): if self.inequality_theorem():
P = (self.AB+self.AC+self.BC)/2 P = (self.seq[0]+self.seq[1]+self.seq[2])/2
return sqrt(P*(P-self.AB)*(P-self.AC)*(P-self.BC)) return sqrt(P*(P-self.seq[0])*(P-self.seq[1])*(P-self.seq[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.
Please register or to comment