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

Update TriangleADT.py

parent 8e6404d2
No related branches found
No related tags found
No related merge requests found
......@@ -19,21 +19,21 @@ class Triangle:
self.__a = p1
self.__b = p2
self.__c = p3
self.seq = [0,0,0]
self.sides()
## @brief Gets the sides
# @return The sides of the triangle
def sides(self):
self.seq[0] = PointT.dist(self.__b,self.__b)
self.seq[1] = PointT.dist(self.__a,self.__c)
self.seq[2] = PointT.dist(self.__b,self.__c)
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):
self.sides()
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]):
seq = self.sides()
if (seq[0] +seq[1] > seq[2] and seq[0]+seq[2] > seq[1] and seq[1]+seq[2] >seq[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;
......@@ -43,17 +43,19 @@ class Triangle:
## @brief perimeter
# @return the perimeter of the triangle
def perimeter_of_triangle(self):
seq = self.sides()
if self.inequality_theorem():
return self.seq[0]+self.seq[1]+self.seq[2]
return seq[0]+seq[1]+seq[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):
seq = self.sides()
if self.inequality_theorem():
P = (self.seq[0]+self.seq[1]+self.seq[2])/2
return sqrt(P*(P-self.seq[0])*(P-self.seq[1])*(P-self.seq[2]))
P = (seq[0]+seq[1]+seq[2])/2
return sqrt(P*(P-self.seq[0])*(P-seq[1])*(P-seq[2]))
else:
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