I need help with this programming assignment. I haven\'t gotten any right respon
ID: 3706219 • Letter: I
Question
I need help with this programming assignment. I haven't gotten any right responses so far. It is to be done in Python programming language.
P.S. Please adhere to all of the detailed requirements and instructions. Your help will be most appreciated. Thanks
So one of the previous responses to this question did not adhere to the requirements which was to create the seperate code three distinct python files XXmain.py, XXtriangles.py & XXpoints.py.
PLEASE WRITE THE CODE AS THREE DISTINCT PROGRAMS; WITH THE TRIANGLES AND POINTS INPUTTED INTO THE MAIN PROGRAM. THANKS!
Essentially the XXpoints.py will create a point object when given 2 values. These will be stored in the attributes named x and y. There will be two methods: getX and getY. There will be no “setters”; points will only be created with a constructor that receives an x and a y value.
and the XXtriangles.py will create a triangle object when given 3 point objects. Its attributes will be these three points, which can be retrieved with the “getter” getVertices, which will return a list of three points. It will also, within the constructor, determine the three side lengths and store those as side1, side2, and side3. (This means that the method sideLength can be in the constructor.) These values can be retrieved with the “getter” getSides, which will return a list of the three floats.
XXpoints.py and XXtriangles needs to implemented in the XXmain.py to produce the final output XXoutput6.txt from the input file input6.txt.
Also please use the value of epsilon in the file to be 0.0001 when evaluating features (VERY IMPORTANT)
THANKS
The main program will be named XXProg4.py. The file with the functions will be named XXtriFun.py. (XX, of course, represents your initials.) The list now contains only valid triangles. Go through the list and, for each triangle, if the data is valid, report on the following (see sample below). The output will be printed from the main program, not from within the functions. There will need to be three files submitted: XXmain.py, XXpoints.py and XXlriangles.py (VERY IMPORTANT List the vertices Length of the shortest side (2 decimal places) Perimeter (2 decimal places) Area (2 decimal places) Whether it is right, acute or obtuse Whether it is scalene, isosceles or equilateral (choose one only . . For XXpoints-py and XXtriangles.py use two classes(respectively): The point class will create a point object when given 2 values. These will be stored in the attributes named x and y. There will be two methods: getX and getY. There will be no "setters" points will only be created with a constructor that receives an x and a y value INPUT The main program will loop through a data file named input6.txt reading and processing each line of data. The data will be in this format The triangle class will create a triangle object when given 3 point objects. Its attributes will be these three points, which can be of three points. It will also, within the constructor, determine the three side lengths and store those as sidel, side2, and side3. (This means that the method sideLength can be in the constructor.) These values can be retrieved with the "getter" getSides, which will return a list of the three floats. retrieved with the " getter" getVertices, which will return a list X1 Y1 X2 Y2X3 Y3 It represents the )coordinates of the three vertices of a triangle, such as these: For each triangle, your program will first check to make sure each point is unique (no duplicates) and that the three points are not collinear 14 2.3 3.2 4.1 5.0 6.9 5 31 3.0 3. 1 OUTPUT ?Use an epsilon of 0.0001 when evaluating features. (VERY IMPORTANT) Your output file will be named XXoutput6.txt, following this format: Vertices: (14, 2.3), 3.2, 4.1), (5.0, 6.9) Shortest side is 255 Perimeter is 11.72 The triangle class will also include "ALL" of these methods, with the appropriate return value: Area is 0.90 Obtuse duplicatePts boolean collinear n indShortest float perimeter float float boolean boolean isosceles bn equilateral bln right acute obtuse The triangle objects which are created with be put into a list named myTriangles Once you have created the entire list (in other words, not as you create each triangle). you will first check to see if it is a "legal" triangle (are there duplicate or collinear points). If it is illegal, delete that triangle from the list and report the deletion to an output file. (Give the vertices and the reason. either duplicate points or collinear points.)Explanation / Answer
Using python3
1. XXpoints.py
class point(object):
def __init__(self, x, y):
self.x = x
self.y = y
def getX(self):
return self.x
def getY(self):
return self.y
2. XXtraingles.py
from math import sqrt
class triangle:
def __init__(self, p1, p2, p3):
self.p1 = p1
self.p2 = p2
self.p3 = p3
self.side1 = sideLength(p1, p2)
self.side2 = sideLength(p2, p3)
self.side3 = sideLength(p3, p1)
def getVertices(self):
return [self.p1, self.p2, self.p3]
def getSides(self):
return [self.side1, self.side2, self.side3]
def duplicatePts(self):
if((self.p1.x == self.p2.x) and (self.p1.y == self.p2.y)):
return True
if ((self.p1.x == self.p3.x) and (self.p1.y == self.p3.y)):
return True
if ((self.p3.x == self.p2.x) and (self.p3.y == self.p2.y)):
return True
return False
def collinear(self):
if self.area():
return False
else:
return True
def findShortest(self):
return round(min(self.getSides()), 2)
def perimeter(self):
return round(sum(self.getSides()), 2)
def area(self):
s = sum(self.getSides()) / 2
area = round(((s*(s-self.side1)*(s-self.side2)*(s-self.side3)) ** 0.5), 2)
return area
def right(self):
tr_type = typeObtuseRightAcute(self.side1, self.side2, self.side3)
if tr_type == "right":
return True
else:
return False
def acute(self):
tr_type = typeObtuseRightAcute(self.side1, self.side2, self.side3)
if tr_type == "acute":
return True
else:
return False
def obtuse(self):
tr_type = typeObtuseRightAcute(self.side1, self.side2, self.side3)
if tr_type == "obtuse":
return True
else:
return False
def scalene(self):
tri_type = typeScaleneIsoscelesEquilater(self.side1, self.side2, self.side3)
if tri_type == "scalene":
return True
else:
return False
def isosceles(self):
tri_type = typeScaleneIsoscelesEquilater(self.side1, self.side2, self.side3)
if tri_type == "isosceles":
return True
else:
return False
def equilateral(self):
tri_type = typeScaleneIsoscelesEquilater(self.side1, self.side2, self.side3)
if tri_type == "equilateral":
return True
else:
return False
def typeScaleneIsoscelesEquilater(side1, side2, side3):
totl_equal_sides = 0
if (side1 == side2):
totl_equal_sides += 1
if (side2 == side3):
totl_equal_sides += 1
if (side3 == side1):
totl_equal_sides += 1
if totl_equal_sides == 3:
return "equilateral"
elif totl_equal_sides == 2:
return "isosceles"
else:
return "scalene"
def typeObtuseRightAcute(side1, side2, side3):
epsilon = 0.0001
[var1, var2, largest] = sorted([side1, side2, side3])
if abs((largest) ** 2 - ((var1 ** 2 + (var2) ** 2))) < epsilon:
return "right"
elif (largest) ** 2 > ((var1 ** 2 + (var2) ** 2)):
return "obtuse"
else:
return "acute"
def sideLength(p1, p2):
length = sqrt((p2.x - p1.x)**2 + (p2.y - p1.y)**2)
return length
3. XXmain.py
from XXpoints import point
from XXtriangles import triangle
of = open(r'XXoutput6.txt', 'w')
f = open(r'input6.txt')
myTriangles = []
for line in f.readlines():
all_points = line.split(" ")
tri_points = []
for i in (0, 2, 4):
x = all_points[i]
y = all_points[i+1]
tri_points.append(point(float(x), float(y)))
myTriangles.append(triangle(*tri_points))
def get_vertices_in_string(tri):
vertices = ""
for p in tri.getVertices():
vertices += "({0}, {1}),".format(p.x, p.y)
return vertices[:-1]
valid_triangles = []
for each_tri in myTriangles:
if each_tri.duplicatePts():
of.write("Deleting triangle with points : {0} because it contain duplicate points. ".format(get_vertices_in_string(each_tri)))
continue
if each_tri.collinear():
of.write("Deleting triangle with points : {0} because points are collinear. ".format(get_vertices_in_string(each_tri)))
continue
valid_triangles.append(each_tri)
myTriangles = valid_triangles
for each_tri in myTriangles:
of.write(" Vertices: {0}".format(get_vertices_in_string(each_tri)))
of.write(" Shortest side is {0}".format(each_tri.findShortest()))
of.write(" Perimeter is {0}".format(each_tri.perimeter()))
of.write(" Area is {0}".format(each_tri.area()))
tri_type = None
if each_tri.scalene():
tri_type = "Scalene"
elif each_tri.isosceles():
tri_type = "Isosceles"
elif each_tri.equilateral():
tri_type = "Equilateral"
of.write(" {0}".format(tri_type))
tri_type = None
if each_tri.right():
tri_type = "Right"
elif each_tri.acute():
tri_type = "Acute"
elif each_tri.obtuse():
tri_type = "Obtuse"
of.write(" {0} ".format(tri_type))