-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
71 lines (56 loc) · 1.55 KB
/
helper.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 20 14:11:37 2018
@author: ashwin
"""
congurent = []
class coordinate(object):
"""
coordinate class for easy storing of points
"""
def __init__(self,x,y):
self.x = x
self.y = y
def distance(self,other):
dx = self.x - other.x
dy = self.y - other.y
return (dx**2 + dy**2)**0.5
def __str__(self):
return "<%s,%s>"%(self.x, self.y)
def __repr__(self):
return "<%s,%s>"%(self.x, self.y)
class triangle(object):
"""
class triangle which keeps a record of sides
"""
def __init__(self,p1,p2,p3):
self.p1 = p1
self.p2 = p2
self.p3 = p3
def __str__(self):
return "Triangle(%s,%s,%s)"%(self.p1, self.p2, self.p3)
def __repr__(self):
return "Triangle(%s,%s,%s)"%(self.p1, self.p2, self.p3)
def sides(self):
s = []
s.append(self.p1.distance(self.p2))
s.append(self.p2.distance(self.p3))
s.append(self.p3.distance(self.p1))
s.sort()
return s
def ispossibletriangle(triang):
"""
This checks given any triangle object as input weather it is a valid triangle or not
"""
sp = triang.sides()
if sp[0] < sp[1] + sp[2]:
return True
else:
return False
def cong(t1,t2):
"""
t1 and t2 are two triangle objects , it appends the result of congurent triangles
"""
if t1.sides() == t2.sides():
congurent.append([t1,t2])