"""TikZ code for the figures of the paper. Each solid is projected orthogonally along a fixed viewing direction, with the hidden edges dashed, the vertices colored by their orbits under the Klein group, and the 3 half-turn axes drawn in gray. Run with an argument among placements, bloch, icosahedron, incidence, to print the corresponding code. """ import sys import numpy as np from solids import placement, TwistedSpace, PHI VIEW = np.array([0.75, 0.30, 0.59]) VIEW = VIEW / np.linalg.norm(VIEW) UP = np.array([0.0, 0.0, 1.0]) EX = np.cross(UP, VIEW) EX = EX / np.linalg.norm(EX) EY = np.cross(VIEW, EX) COLORS = ["qblue", "qgold", "magenta", "black", "black!35"] def proj(p, scale, shift): return (scale * (p @ EX) + shift[0], scale * (p @ EY) + shift[1]) def fmt(xy): return "(%.2f,%.2f)" % xy def visible_edges(pts, edges, faces): centroid = pts.mean(axis=0) front = [] for f in faces: c = pts[list(f)].mean(axis=0) front.append((c - centroid) @ VIEW > 1e-9) vis = [] for i, j in edges: vis.append(any(front[k] for k, f in enumerate(faces) if i in f and j in f)) vvis = [any(front[k] for k, f in enumerate(faces) if i in f) for i in range(len(pts))] return vis, vvis def solid(label, shift, scale=0.95, axes=True, title=None, algebra=None): pts, edges, faces = placement(label) r = np.linalg.norm(pts[0]) pts = pts / r sp = TwistedSpace(pts) color = {} for k, (x, orb, stab) in enumerate(sp.orbits): for y in orb: color[y] = COLORS[k] vis, vvis = visible_edges(pts, edges, faces) out = [] if axes: for k in range(3): e = np.zeros(3) e[k] = 1.25 out.append("\\draw[black!30] %s--%s;" % (fmt(proj(-e, scale, shift)), fmt(proj(e, scale, shift)))) for (i, j), v in zip(edges, vis): style = "" if v else "[densely dotted]" out.append("\\draw%s %s--%s;" % (style, fmt(proj(pts[i], scale, shift)), fmt(proj(pts[j], scale, shift)))) for i in range(len(pts)): out.append("\\fill[%s] %s circle(%s);" % (color[i], fmt(proj(pts[i], scale, shift)), "0.06" if vvis[i] else "0.045")) if title: out.append("\\node at (%.2f,%.2f) {%s};" % (shift[0], shift[1] + 1.45, title)) if algebra: out.append("\\node at (%.2f,%.2f) {%s};" % (shift[0], shift[1] - 1.45, algebra)) return "\n".join(out) def placements_figure(): row1 = [("tetrahedron", "tetrahedron", "$M_2$"), ("cube", "cube", "$M_2\\oplus M_2$"), ("octahedron", "octahedron", "$\\mathbb C^6$"), ("icosahedron", "icosahedron", "$M_2^{\\oplus3}$")] row2 = [("dodecahedron", "dodecahedron", "$M_2^{\\oplus5}$"), ("other cube", "other cube", "$M_2\\oplus M_2$"), ("other octahedron", "other octahedron", "$\\mathbb C^2\\oplus M_2$")] out = [] for k, (lab, title, alg) in enumerate(row1): out.append(solid(lab, (3.4 * k, 0), title=title, algebra=alg)) for k, (lab, title, alg) in enumerate(row2): out.append(solid(lab, (1.7 + 3.4 * k, -3.6), title=title, algebra=alg)) return "\n".join(out) def bloch_figure(): scale, shift = 1.6, (0, 0) pts = np.array([(a, b, c) for a in (1, -1) for b in (1, -1) for c in (1, -1)]) / 3 ** 0.5 out = ["\\draw[black!40] (0,0) circle(%.2f);" % scale] # equator, as an ellipse eq = [proj(np.array([np.cos(t), np.sin(t), 0]), scale, shift) for t in np.linspace(0, 2 * np.pi, 49)] out.append("\\draw[black!25] " + "--".join(fmt(p) for p in eq) + ";") edges = [(i, j) for i in range(8) for j in range(i + 1, 8) if np.sum(np.abs(pts[i] - pts[j]) > 1e-9) == 1] for i, j in edges: mid = (pts[i] + pts[j]) / 2 style = "" if mid @ VIEW > -1e-9 else "[densely dotted]" out.append("\\draw%s %s--%s;" % (style, fmt(proj(pts[i], scale, shift)), fmt(proj(pts[j], scale, shift)))) for p in pts: col = "qblue" if np.prod(np.sign(p)) > 0 else "qgold" out.append("\\fill[%s] %s circle(0.07);" % (col, fmt(proj(p, scale, shift)))) return "\n".join(out) def icosahedron_figure(): pts, edges, faces = placement("icosahedron") pts = pts / np.linalg.norm(pts[0]) scale, shift = 1.7, (0, 0) vis, vvis = visible_edges(pts, edges, faces) out = [] for k in range(3): e = np.zeros(3) e[k] = 1.3 out.append("\\draw[black!30] %s--%s;" % (fmt(proj(-e, scale, shift)), fmt(proj(e, scale, shift)))) for (i, j), v in zip(edges, vis): mid = (pts[i] + pts[j]) / 2 short = np.sum(np.abs(mid) > 1e-9) == 1 # the edge is pierced by an axis style = ["thick", "magenta"] if short else [] if not v: style.append("densely dotted") st = "[" + ",".join(style) + "]" if style else "" out.append("\\draw%s %s--%s;" % (st, fmt(proj(pts[i], scale, shift)), fmt(proj(pts[j], scale, shift)))) for i in range(len(pts)): out.append("\\fill %s circle(%s);" % (fmt(proj(pts[i], scale, shift)), "0.06" if vvis[i] else "0.045")) return "\n".join(out) def incidence_figure(): pts, edges, faces = placement("tetrahedron") pts = pts / np.linalg.norm(pts[0]) scale, shift = 1.7, (0, 0) vis, vvis = visible_edges(pts, edges, faces) out = [] for (i, j), v in zip(edges, vis): st = "" if v else "[densely dotted]" out.append("\\draw%s %s--%s;" % (st, fmt(proj(pts[i], scale, shift)), fmt(proj(pts[j], scale, shift)))) mids = [(pts[i] + pts[j]) / 2 for i, j in edges] for a in range(6): for b in range(a + 1, 6): if set(edges[a]) & set(edges[b]): mid = (mids[a] + mids[b]) / 2 st = "qgold" if mid @ VIEW > 0 else "qgold,densely dotted" out.append("\\draw[%s] %s--%s;" % (st, fmt(proj(mids[a], scale, shift)), fmt(proj(mids[b], scale, shift)))) for p in pts: out.append("\\fill[qblue] %s circle(0.07);" % fmt(proj(p, scale, shift))) for m in mids: out.append("\\fill[qgold] %s circle(0.06);" % fmt(proj(m, scale, shift))) return "\n".join(out) if __name__ == "__main__": which = sys.argv[1] if len(sys.argv) > 1 else "placements" print({"placements": placements_figure, "bloch": bloch_figure, "icosahedron": icosahedron_figure, "incidence": incidence_figure}[which]())