-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangles.py
More file actions
34 lines (23 loc) · 836 Bytes
/
triangles.py
File metadata and controls
34 lines (23 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import math
class Point:
def __init__(self, x=0.0, y=0.0):
self.__x = x
self.__y = y
def getx(self):
return self.__x
def gety(self):
return self.__y
def distance_from_xy(self, x, y):
return math.hypot(abs(self.__x - x), abs(self.__y - y))
def distance_from_point(self, point):
return self.distance_from_xy(point.getx(), point.gety())
class Triangle:
def __init__(self, vertice1, vertice2, vertice3):
self.__vertices = [vertice1, vertice2, vertice3]
def perimeter(self):
per = 0
for i in range(3):
per += self.__vertices[i].distance_from_point(self.__vertices[(i + 1) % 3])
return per
triangle = Triangle(Point(0, 0), Point(1, 0), Point(0, 1))
print(triangle.perimeter())