-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnecting_Points_0409.py
More file actions
143 lines (127 loc) · 5.75 KB
/
Connecting_Points_0409.py
File metadata and controls
143 lines (127 loc) · 5.75 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# CodeSkulptor runs Python programs in your browser.
# Click the upper left button to run this simple demo.
# CodeSkulptor is tested to run in recent versions of
# Chrome, Firefox, and Safari.
def abs_side(side):
if side < 0:
new_side = -1 - side
else:
new_side = side
return new_side
def num_of_connections_within_a_triangle(triangle, intersection):
num_of_connections = {}
a = intersection[abs_side(triangle[0])]
b = intersection[abs_side(triangle[1])]
c = intersection[abs_side(triangle[2])]
num_of_connections[(triangle[0], triangle[1])] = (a + b - c)/2
num_of_connections[(triangle[2], triangle[0])] = (a + c - b)/2
num_of_connections[(triangle[1], triangle[2])] = (b + c - a)/2
return num_of_connections
def leaving_position(enteringp, triangle, intersection):
"Enter a point; return the position at which it leaves the triangle."
"The three sides of the triangle must be arranged in counterclockwise order."
noc = num_of_connections_within_a_triangle(triangle, intersection)
for i in range(0, 3):
if triangle[i] == enteringp[0]:
sidea = triangle[(i+1)%3]
sideb = triangle[(i-1)%3]
side = triangle[i]
"Now consider all the possible situations. i.e., the possible orientations of the sides."
if side < 0:
if enteringp[1] < noc[(side, sidea)]:
if sidea < 0:
pos = intersection[abs_side(sidea)] - enteringp[1] - 1
else:
pos = enteringp[1]
leavingp = (sidea, pos)
else:
if sideb < 0:
pos = intersection[abs_side(side)] - enteringp[1] - 1
else:
pos = intersection[abs_side(sideb)] - intersection[abs_side(side)] + enteringp[1]
leavingp = (sideb, pos)
else:
if enteringp[1] < noc[(sideb, side)]:
if sideb < 0:
pos = enteringp[1]
else:
pos = intersection[abs_side(sideb)] - enteringp[1] - 1
leavingp = (sideb, pos)
else:
if sidea < 0:
pos = intersection[abs_side(sidea)] - intersection[abs_side(side)] + enteringp[1]
else:
pos = intersection[abs_side(side)] - enteringp[1] - 1
leavingp = (sidea, pos)
return leavingp
def connecting(triangulation, intersection):
connection = []
for i in range(0,9):
if intersection[i] > 0:
entersd = i
break
for tr in triangulation:
for i in range(0,3):
if entersd == tr[i]:
entertr = tr
break
enterp = (entersd, 0)
count = 0
while count < 1:
leavingp = leaving_position(enterp, entertr, intersection)
connection.append((enterp, leavingp))
enterp = (-1-leavingp[0], leavingp[1])
#print(leavingp)
for tr in triangulation:
for i in range(0,3):
if enterp[0] == tr[i]:
entertr0 = tr
#print(entertr)
entertr = entertr0
if enterp == (entersd, 0):
count = count + 1
return connection
def octagon_only(connection, edges):
octagon_con = []
"Connection is the result from the connecting function."
"Edges is a list of sides that are the sides of the octagon."
"In the flipper default case, edges = [1, 6, 7, 8]."
for i in range(0,len(connection)):
if connection[i][0][0] in edges or -1-connection[i][0][0] in edges:
for j in range(i, len(connection)):
if connection[j][1][0] in edges or -1-connection[j][1][0] in edges:
octagon_con.append((connection[i][0], connection[j][1]))
break
"The last tuple that connects back to the starting point may not be included, so we add it here."
if connection[0][0][0] not in edges and -1-connection[0][0][0] not in edges:
lastone = (-1-octagon_con[len(octagon_con)-1][1][0], octagon_con[len(octagon_con)-1][1][1])
firstone = (-1-octagon_con[0][0][0], octagon_con[0][0][1])
octagon_con.append((lastone, firstone))
return octagon_con
"triangulation = [(-9, -2, -1), (-8, 8, 3), (-7,-3,7), (-6,6,2), (-5,-4,5), (0,4,1)]"
"""def connecting_points(intersection, triangulation):
connection = {}
noc = []
for triangle in triangulation:
noc.append(num_of_connections_within_a_triangle(triangle, intersection))
connection[(-9,1)] = min(noc[5][(0,1)], noc[0][(-9,-1)])
connection[(-9,-2)] = noc[0][(-9,-2)]
connection[(-2,1)] = noc[5][(0,1)] - connection[(-9,1)]
connection[(-7,7)] = noc[2][(-7,7)]
connection[(6,7)] = min(noc[3][(-6,2)], noc[2][(-3,7)])
connection[(-7,6)] = noc[3][(-6,2)] - connection[(6,7)]
connection[(-8,8)] = noc[1][(-8,8)]
connection[(-7,1)] = min(noc[5][(4,1)], noc[4][(-5,5)], noc[3][(-6,2)], noc[2][(-7,-3)])"""
"Start with a point on 0 or 1 or 2 or 3 that has no point on one side of it"
"Consider a triangle it is in"
"Compare its serial number, which is initially 0, to the num_of_connections of the side its on and the other two sides"
"By this we can tell which side it is going to"
"If we reach a side that we have encountered before, serial number + 1"
"Repeat until the serial number on the starting edge exceeds the boundary"
"Another method: point to point"
"iteration: start from, for example, (1,0), (1,0) to (0,0), ... Stop and record at edges on the side."
"[((1,0),(~8,0)), ...]"
if __name__ == "__main__":
print('hello')
triangulation = [(1, 8, 0), (7, ~3, ~8), (2, 6, ~7), (5, ~2, ~6), (3, 4, ~5), (~0, ~1, ~4)]
edges = [1, 6, 7, 8]