-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_fans_ex.py
More file actions
71 lines (58 loc) · 1.88 KB
/
all_fans_ex.py
File metadata and controls
71 lines (58 loc) · 1.88 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
from regfans import VectorConfiguration
# construct all fans from a simple acyclic vector configuration
# =============================================================
# (N.B.: acyclic VC ~= PC. I.e., this is analogous to a 2D square)
pts = [[0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 1]]
vc = VectorConfiguration(pts)
fans = vc.all_triangulations()
print(f"The vector configuration {vc} has the following fans:")
for f in fans:
print(f"a fan with cones {f.cones()}")
print()
print('-'*60)
print()
# construct all fans from a simple totally-cyclic vector configuration
# ====================================================================
pts = [[-1,1],[0,1],[1,1],[1,0],[0,-1]]
vc = VectorConfiguration(pts)
G, fans, labels = vc.flip_graph(compute_node_labels=True) # this time, compute the fans via the flip_graph method... this also gives a formal graph object
print(f"The vector configuration {vc} has the following fans:")
for f in fans:
print(f"a fan with cones {f.cones()}")
# plot the flip graph
# -------------------
try:
import matplotlib.pyplot as plt
HAS_MATPLOTLIB = True
except ImportError:
HAS_MATPLOTLIB = False
if HAS_MATPLOTLIB:
import networkx as nx
import matplotlib.pyplot as plt
# construct node labels
def node_label(label: dict) -> str:
return (
("F" if label.get("fine") else "")
+ ("R" if label.get("regular") else "")
+ "S"
+ ("T" if label.get("respects_ptconfig") else "")
)
node_labels = {i: node_label(labels[i]) for i in range(len(labels))}
# plot the graph
pos = nx.spring_layout(G)
plt.figure()
nx.draw(
G,
pos,
with_labels=False,
node_size=200,
node_color="lightgray"
)
nx.draw_networkx_labels(
G,
pos,
labels=node_labels,
font_size=6
)
plt.axis("off")
plt.show()