Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
create_entity_figures.py
Go to the documentation of this file.
1"""Geometric sketches of the 3D polyhedral and simplex hierarchies."""
2from pathlib import Path
3import numpy as np
4import matplotlib
5matplotlib.use('Agg')
6import matplotlib.pyplot as plt
7from matplotlib.patches import Polygon, FancyArrowPatch
8
9OUT = Path(__file__).resolve().parents[1] / 'figures'
10BLUE, ORANGE, DARK = '#176b91', '#d27a30', '#203547'
11plt.rcParams.update({'font.family': 'DejaVu Sans', 'font.size': 11, 'pdf.fonttype': 42})
12
13def polygon(ax, points, fill='#edf4f8', z=2):
14 ax.add_patch(Polygon(points, closed=True, facecolor=fill, edgecolor=BLUE, linewidth=1.5, zorder=z))
15
16def line(ax, points, color=BLUE, dashed=False, z=4):
17 ax.plot(*np.asarray(points).T, color=color, lw=2, ls='--' if dashed else '-', zorder=z)
18
19def arrow(ax, start, end, color=BLUE):
20 ax.add_patch(FancyArrowPatch(start, end, arrowstyle='-|>', mutation_scale=12, color=color, lw=1.3))
21
22def make(simplex=False):
23 fig, ax = plt.subplots(figsize=(10, 2.7))
24 ax.set(xlim=(-1.1, 9.1), ylim=(-.95, 1.6), aspect='equal')
25 ax.axis('off')
26 centers = [0, 2.65, 5.3, 7.95]
27 if simplex:
28 p = np.array([[-.75,-.25],[.65,-.25],[.32,1.05],[-.05,.2]])
29 polygon(ax, p[[0,1,2]])
30 for i in [0,1,2]:
31 line(ax, p[[3,i]], dashed=True, z=3)
32 polygon(ax, p[[0,1,2]], '#fae3cc', z=3.5)
33 # Dashed edges meet at the hidden fourth vertex.
34 for i in [0,1,2]:
35 line(ax, p[[3,i]], dashed=True, z=4)
36 face = p[[0,1,2]] + [centers[1],0]
37 labels = ['Tetrahedron', 'Triangle', 'Edge', 'Vertex']
38 detail = ['4 vertices', '3 vertices', '2 vertices', '1 vertex']
39 title = 'Simplex<3, order>: boundary entities'
40 else:
41 p = np.array([[-.75,.05],[-.4,-.25],[.4,-.25],[.75,.05],[.4,.48],[-.4,.48]])
42 back = p + [0,.65]
43 polygon(ax, back)
44 for i in range(3):
45 polygon(ax, np.array([p[i],p[i+1],back[i+1],back[i]]), '#d9e9f1')
46 polygon(ax, p, '#fae3cc', z=4)
47 face = p + [centers[1],.15]
48 labels = ['Region', 'Face', 'Edge', 'Vertex']
49 detail = ['region ID', 'planar polygon', 'shared by faces', 'position']
50 title = 'Polyhedron<3, order>: boundary entities'
51 polygon(ax, face)
52 line(ax, face[:2], ORANGE)
53 edge = np.array([[-.65,.2],[.65,.2]]) + [centers[2],0]
54 line(ax, edge)
55 ax.scatter(*edge.T, s=25, color=BLUE, zorder=5)
56 ax.scatter(*edge[1], s=40, color=ORANGE, zorder=6)
57 ax.scatter(centers[3],.2,s=50,color=ORANGE,zorder=6)
58 for i, x in enumerate(centers):
59 ax.text(x,-.53, f'{labels[i]} ({3-i}-cell)', ha='center', color=DARK, weight='bold')
60 ax.text(x,-.8, detail[i], ha='center', color=DARK, fontsize=10)
61 for x in centers[:-1]:
62 arrow(ax, (x+.92,.45), (x+1.66,.45))
63 if not simplex:
64 arrow(ax, (x+1.66,.08), (x+.92,.08), ORANGE)
65 ax.text(3.95,1.4,title,ha='center',color=DARK,fontsize=12)
66 name = 'simplex_complex' if simplex else 'cell_complex'
67 for ext in ['pdf','png']:
68 fig.savefig(OUT / f'{name}.{ext}', bbox_inches='tight', dpi=180)
69 plt.close(fig)
70
71make()
72make(simplex=True)
line(ax, points, color=BLUE, dashed=False, z=4)
arrow(ax, start, end, color=BLUE)
polygon(ax, points, fill='#edf4f8', z=2)