Instantly share code, notes, and snippets.

# charlesreid1/poly_directed.tex Last active Mar 17, 2019

TeX for drawing labeled polygons with directed and undirected paths (for illustrating solutions to the Josephus problem).

## poly_directed.tex

 \documentclass[border=2mm]{standalone} \usepackage{tikz} \usepackage{xintexpr} \usetikzlibrary{shapes.geometric} \begin{document} \begin{tikzpicture}[scale=3] % make a node with variable name pol (with the list of features given) at the location (0,0), and don't label it \node (pol) [draw, thick, black!90!black,rotate=0,minimum size=6cm,regular polygon, regular polygon sides=11] at (0,0) {}; % anchor is "corner 1" % label is 1/2/3/4/etc % placement is placement w.r.t. coordinate location \foreach \anchor/\label/\placement in {corner 1/$1$/above, corner 2/$2$/left, corner 3/$3$/left, corner 4/$4$/left, corner 5/$5$/below left, corner 6/$6$/below, corner 7/$7$/below, corner 8/$8$/below, corner 9/$9$/right, corner 10/${10}$/right, corner 11/${11}$/above right} \draw[shift=(pol.\anchor)] plot coordinates{(0,0)} node[font=\scriptsize,\placement] {\label}; % solution for n = 11, m = 4: % ( 1 3 7 6 4 ) ( 2 8 ) ( 5 9 11 ) ( 10 ) % cycle (1 3 7 6 4) \path [->, shorten > = 3 pt, blue, shorten < = 4 pt, > = stealth] (pol.corner 1) edge (pol.corner 3); \path [->, shorten > = 3 pt, blue, shorten < = 4 pt, > = stealth] (pol.corner 3) edge (pol.corner 7); \path [->, shorten > = 3 pt, blue, shorten < = 4 pt, > = stealth] (pol.corner 7) edge (pol.corner 6); \path [->, shorten > = 3 pt, blue, shorten < = 4 pt, > = stealth] (pol.corner 6) edge (pol.corner 4); \path [->, shorten > = 3 pt, blue, shorten < = 4 pt, > = stealth] (pol.corner 4) edge (pol.corner 1); % cycle 2 (2 8) \path [->, shorten > = 3 pt, green, shorten < = 4 pt, > = stealth] (pol.corner 2) edge (pol.corner 8); \path [->, shorten > = 3 pt, green, shorten < = 4 pt, > = stealth] (pol.corner 8) edge (pol.corner 2); % cycle 3 (5 9 11 ) \path [->, shorten > = 3 pt, red, shorten < = 4 pt, > = stealth] (pol.corner 5) edge (pol.corner 9); \path [->, shorten > = 3 pt, red, shorten < = 4 pt, > = stealth] (pol.corner 9) edge (pol.corner 11); \path [->, shorten > = 3 pt, red, shorten < = 4 pt, > = stealth] (pol.corner 11) edge (pol.corner 5); % Draw a red dot at the starting point \filldraw[red] (pol.corner 1) circle[radius=0.8pt]; \end{tikzpicture} \end{document}
 \documentclass[border=2mm]{standalone} \usepackage{tikz} \usepackage{xintexpr} \usetikzlibrary{shapes.geometric} \begin{document} \begin{tikzpicture}[scale=3] % make a node with variable name pol (with the list of features given) at the location (0,0), and don't label it \node (pol) [draw, thick, black!90!black,rotate=0,minimum size=6cm,regular polygon, regular polygon sides=11] at (0,0) {}; % anchor is "corner 1" % label is 1/2/3/4/etc % placement is placement w.r.t. coordinate location \foreach \anchor/\label/\placement in {corner 1/$1$/above, corner 2/$2$/left, corner 3/$3$/left, corner 4/$4$/left, corner 5/$5$/below left, corner 6/$6$/below, corner 7/$7$/below, corner 8/$8$/below, corner 9/$9$/right, corner 10/${10}$/right, corner 11/${11}$/above right} \draw[shift=(pol.\anchor)] plot coordinates{(0,0)} node[font=\scriptsize,\placement] {\label}; % solution for n = 11, m = 4: % ( 1 3 7 6 4 ) ( 2 8 ) ( 5 9 11 ) ( 10 ) % cycle (1 3 7 6 4) \path [-] (pol.corner 1) edge (pol.corner 3); \path [-] (pol.corner 3) edge (pol.corner 7); \path [-] (pol.corner 7) edge (pol.corner 6); \path [-] (pol.corner 6) edge (pol.corner 4); \path [-] (pol.corner 4) edge (pol.corner 1); % cycle 2 (2 8) \path [-] (pol.corner 2) edge (pol.corner 8); \path [-] (pol.corner 8) edge (pol.corner 2); % cycle 3 (5 9 11 ) \path [-] (pol.corner 5) edge (pol.corner 9); \path [-] (pol.corner 9) edge (pol.corner 11); \path [-] (pol.corner 11) edge (pol.corner 5); % Draw a red dot at the starting point \filldraw[red] (pol.corner 1) circle[radius=0.8pt]; \end{tikzpicture} \end{document}
to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.