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

Add new file

parent 8cf00d93
No related branches found
No related tags found
No related merge requests found
## @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
self.sides()
## @brief Gets the sides
# @return The sides of the triangle
def sides(self):
self.AB = pointT.dist(self.__b,self.__b)
self.AC = pointT.dist(self.__a,self.__c)
self.BC = pointT.dist(self.__b,self.__c)
## @brief Inequality theorem
# @return the existence of a triangle
def inequality_theorem(self):
self.sides()
if (self.AB +self.AC > self.BC and self.AB+self.BC > self.AC and self.AC+self.BC >self.AB):
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.AB+self.AC+self.BC
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.AB+self.AC+self.BC)/2
return sqrt(P*(P-self.AB)*(P-self.AC)*(P-self.BC))
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