-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyhedra(beta).py
149 lines (119 loc) · 4.78 KB
/
polyhedra(beta).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
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
144
145
146
147
148
149
class Polyhedron:
def __init__(self, name, wythoff, symbol, c_num, w_num, u_num, k_num, vertices, edges, faces, faces_by_type):
self.name = name
self.wythoff = wythoff
self.symbol = symbol
self.c_num = c_num
self.w_num = w_num
self.u_num = u_num
self.k_num = k_num
self.vertices = vertices
self.edges = edges
self.faces = faces
self.faces_by_type = faces_by_type
def __repr__(self):
return self.name
class PolyhedraDatabase:
def __init__(self):
self.polyhedra = []
def add_polyhedron(self, polyhedron):
self.polyhedra.append(polyhedron)
def remove_polyhedron(self, polyhedron):
self.polyhedra.remove(polyhedron)
def get_polyhedron_by_name(self, name):
for polyhedron in self.polyhedra:
if polyhedron.name == name:
return polyhedron
return None
def get_polyhedra_by_wythoff(self, wythoff):
matching_polyhedra = []
for polyhedron in self.polyhedra:
if polyhedron.wythoff == wythoff:
matching_polyhedra.append(polyhedron)
return matching_polyhedra
def get_polyhedra_by_symbol(self, symbol):
matching_polyhedra = []
for polyhedron in self.polyhedra:
if polyhedron.symbol == symbol:
matching_polyhedra.append(polyhedron)
return matching_polyhedra
def get_polyhedra_by_vertex_count(self, vertex_count):
matching_polyhedra = []
for polyhedron in self.polyhedra:
if polyhedron.vertices == vertex_count:
matching_polyhedra.append(polyhedron)
return matching_polyhedra
def get_polyhedra_by_edge_count(self, edge_count):
matching_polyhedra = []
for polyhedron in self.polyhedra:
if polyhedron.edges == edge_count:
matching_polyhedra.append(polyhedron)
return matching_polyhedra
def get_polyhedra_by_face_count(self, face_count):
matching_polyhedra = []
for polyhedron in self.polyhedra:
if polyhedron.faces == face_count:
matching_polyhedra.append(polyhedron)
return matching_polyhedra
def get_polyhedra_by_face_type_count(self, face_type_count):
matching_polyhedra = []
for polyhedron in self.polyhedra:
if polyhedron.faces_by_type == face_type_count:
matching_polyhedra.append(polyhedron)
return matching_polyhedra
# Example usage:
database = PolyhedraDatabase()
# Add polyhedra to the database
polyhedron1 = Polyhedron("Tetrahedron", "3 | 2 3", "Td", "C15", "W001", "U01", "K06", 4, 6, 4, "4{3}")
polyhedron2 = Polyhedron("Cube", "3 | 2 4", "Oh", "C18", "W003", "U06", "K11", 8, 12, 6, "6{4}")
polyhedron3 = Polyhedron("Octahedron", "4 | 2 3", "Oh", "C17", "W002", "U05", "K10", 6, 12, 8, "8{3}")
database.add_polyhedron(polyhedron1)
database.add_polyhedron(polyhedron2)
database.add_polyhedron(polyhedron3)
# Find polyhedra by name
found_polyhedron = database.get_polyhedron_by_name("Cube")
print(found_polyhedron)
# Find polyhedra by Wythoff symbol
matching_polyhedra = database.get_polyhedra_by_wythoff("3 | 2 3")
print(matching_polyhedra)
# Find polyhedra by number of vertices
matching_polyhedra = database.get_polyhedra_by_vertex_count(6)
print(matching_polyhedra)
# Remove a polyhedron from the database
database.remove_polyhedron(polyhedron2)
def create_polyhedra_database_from_file(filename):
with open(filename, 'r') as file:
lines = file.readlines()
database = []
for line in lines:
line = line.strip()
if line:
fields = line.split(',')
name = fields[0].strip()
wythoff = fields[1].strip().split('|')[0]
symbol = fields[2].strip()
c_num = fields[3].strip()
w_num = fields[4].strip()
u_num = fields[5].strip()
k_num = fields[6].strip()
vertices = int(fields[7].strip())
edges = int(fields[8].strip())
faces = int(fields[9].strip())
faces_by_type = fields[10].strip()
polyhedron = {
'Name': name,
'Wythoff': wythoff,
'Sym.': symbol,
'C#': c_num,
'W#': w_num,
'U#': u_num,
'K#': k_num,
'Vert.': vertices,
'Edges': edges,
'Faces': faces,
'Faces by Type': faces_by_type
}
database.append(polyhedron)
return database
# Example usage:
database = create_polyhedra_database_from_file('polyhedra.txt')