Created
April 18, 2023 21:56
-
-
Save dzackgarza/f83b28476a542236eadd7b15b09485c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\newcommand{\convexpath}[2]{ | |
[ | |
create hullnodes/.code={ | |
\global\edef\namelist{#1} | |
\foreach [count=\counter] \nodename in \namelist { | |
\global\edef\numberofnodes{\counter} | |
\node at (\nodename) [draw=none,name=hullnode\counter] {}; | |
} | |
\node at (hullnode\numberofnodes) [name=hullnode0,draw=none] {}; | |
\pgfmathtruncatemacro\lastnumber{\numberofnodes+1} | |
\node at (hullnode1) [name=hullnode\lastnumber,draw=none] {}; | |
}, | |
create hullnodes | |
] | |
($(hullnode1)!#2!-90:(hullnode0)$) | |
\foreach [ | |
evaluate=\currentnode as \previousnode using \currentnode-1, | |
evaluate=\currentnode as \nextnode using \currentnode+1 | |
] \currentnode in {1,...,\numberofnodes} { | |
let | |
\p1 = ($(hullnode\currentnode)!#2!-90:(hullnode\previousnode)$), | |
\p2 = ($(hullnode\currentnode)!#2!90:(hullnode\nextnode)$), | |
\p3 = ($(\p1) - (hullnode\currentnode)$), | |
\n1 = {atan2(\y3,\x3)}, | |
\p4 = ($(\p2) - (hullnode\currentnode)$), | |
\n2 = {atan2(\y4,\x4)}, | |
\n{delta} = {-Mod(\n1-\n2,360)} | |
in | |
{-- (\p1) arc[start angle=\n1, delta angle=\n{delta}, radius=#2] -- (\p2)} | |
} | |
-- cycle | |
} | |
\begin{tikzpicture} | |
\begin{pgfonlayer}{nodelayer} | |
\node [style=white node] (1) at (0, 0) {}; | |
\node [style=black node] (2) at (-2, 0) {}; | |
\node [style=black node] (3) at (2, 0) {}; | |
% ........ | |
\end{pgfonlayer} | |
\begin{pgfonlayer}{edgelayer} | |
\draw (1) to (3); | |
\draw (2) to (1); | |
\draw (2) to (4); | |
% ....... | |
\end{pgfonlayer} | |
\begin{pgfonlayer}{background} | |
\fill[cyan,opacity=1] \convexpath{1,2}{8pt}; | |
\fill[cyan,opacity=1] \convexpath{2,4}{8pt}; | |
\fill[cyan,opacity=1] \convexpath{2,5,6,7,8,9,10}{8pt}; | |
% ...... | |
\end{pgfonlayer} | |
\end{tikzpicture} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment