-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcongruent.py
70 lines (55 loc) · 1.72 KB
/
congruent.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 18 15:34:44 2018
@author: ashwin
keep a check on negative coordinates :/
"""
import itertools
import helper as hl
import matplotlib.pyplot as plt
points = []
triangles_all = []
triangles_possible = []
triangle_pairs = []
plot = []
# it takes the input from the user as points and store them as coordinate obejcts
for i in range(int(input())):
a,b = list(map(int,input().split()))
points.append(hl.coordinate(a,b))
triangles_all.extend(itertools.combinations(points, 3))
for points in triangles_all:
"""gives a list of all possible triangles"""
pl1 = points[0]
pl2 = points[1]
pl3 = points[2]
to = hl.triangle(pl1,pl2,pl3)
if hl.ispossibletriangle(to):
triangles_possible.append(to)
#gives combination of all possible triangles
triangle_pairs.extend(itertools.combinations(triangles_possible, 2))
#checks for congurency of triangles
for m in triangle_pairs:
tq1 = m[0]
tq2 = m[1]
hl.cong(tq1,tq2)
print('Congurent Triangles are',hl.congurent)
"""
coord = [[1,1], [2,1], [2,2], [1,2]]
coord.append(coord[0]) #repeat the first point to create a 'closed loop'
xs, ys = zip(*coord) #create lists of x and y values
plt.figure()
plt.plot(xs,ys)
"""
for u in hl.congurent:
a0 = [[u[0].p1.x,u[0].p1.y],[u[0].p2.x,u[0].p2.y],[u[0].p3.x,u[0].p3.y],[u[0].p1.x,u[0].p1.y]]
a1 = [[u[1].p1.x,u[1].p1.y],[u[1].p2.x,u[1].p2.y],[u[1].p3.x,u[1].p3.y],[u[1].p1.x,u[1].p1.y]]
if a0 not in plot:
plot.append(a0)
if a1 not in plot:
plot.append(a1)
for coord in plot:
xs, ys = zip(*coord) #create lists of x and y values
plt.figure('triangles')
plt.plot(xs,ys)
print('-----------',plot)