1

I am using the code from this answer to generate a convex path around some nodes in a Beamer presentation. Here's a MWE:

\documentclass[12pt,aspectratio=169]{beamer}

\usepackage{tikz}
\usetikzlibrary{calc}

\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} {
-- ($(hullnode\currentnode)!#2!-90:(hullnode\previousnode)$)
  let \p1 = ($(hullnode\currentnode)!#2!-90:(hullnode\previousnode) - (hullnode\currentnode)$),
    \n1 = {atan2(\y1,\x1)},
    \p2 = ($(hullnode\currentnode)!#2!90:(hullnode\nextnode) - (hullnode\currentnode)$),
    \n2 = {atan2(\y2,\x2)},
    \n{delta} = {-Mod(\n1-\n2,360)}
  in 
    {arc [start angle=\n1, delta angle=\n{delta}, radius=#2]}
}
-- cycle
}

\begin{document}

\tikzstyle{mynode}=[outer sep=0pt,draw,shape=circle,minimum size=11mm,inner sep=0pt]

\begin{frame}[t]{MWE}
\begin{figure}
\begin{tikzpicture}[scale=1.8]
\node[mynode,fill=red!50] at (0,0) (i1) {$A$};
\node[mynode,fill=blue!50] at (0,-1) (i2) {$B$};
\node[mynode,fill=green!50] at (0,-2) (i3) {$C$};
\node[mynode] at (3,0) (b1) {1};
\node[mynode] at (3,-1) (b2) {2};
\node[mynode] at (3,-2) (b3) {3};
\draw[black,dashed,thick] \convexpath{i1,b1}{10.5pt};
\draw[black,dashed,thick] \convexpath{i1,b3,i3}{12pt};
\draw[black,dashed,thick] \convexpath{i3,b2}{10.5pt};
\draw[black,dashed,thick] \convexpath{i1,b1,i2}{13.5pt};
\end{tikzpicture}
\end{figure}
\end{frame}

\end{document}

which should produce something like this:

enter image description here

Now, I want to show the different paths one at the time (in different slides), while leaving the others "shaded". I thought of using \only, but the "let \p1" part in the convex path code seems to break something and I get a "undefined control sequence" error. How can I solve this?

1 Answers1

2

The overlay-beamer-styles library can be instrumental for that. It has the alt key, with which you can say

\draw[black,dashed,thick,alt=<2>{opacity=1}{opacity=0.2}] \convexpath{i1,b3,i3}{12pt};

such that the path has full opacity on frame 2 only.

\documentclass[12pt,aspectratio=169]{beamer}

\usepackage{tikz}
\usetikzlibrary{calc,overlay-beamer-styles}

\newcommand{\convexpath}[2]{
[   
    create hullnodes={#1}
]
($(hullnode1)!#2!-90:(hullnode0)$)
\foreach [
    evaluate=\currentnode as \previousnode using \currentnode-1,
    evaluate=\currentnode as \nextnode using \currentnode+1
    ] \currentnode in {1,...,\numberofnodes} {
-- ($(hullnode\currentnode)!#2!-90:(hullnode\previousnode)$)
  let \p1 = ($(hullnode\currentnode)!#2!-90:(hullnode\previousnode) - (hullnode\currentnode)$),
    \n1 = {atan2(\y1,\x1)},
    \p2 = ($(hullnode\currentnode)!#2!90:(hullnode\nextnode) - (hullnode\currentnode)$),
    \n2 = {atan2(\y2,\x2)},
    \n{delta} = {-Mod(\n1-\n2,360)}
  in 
    {arc [start angle=\n1, delta angle=\n{delta}, radius=#2]}
}
-- cycle
}

\begin{document}

\tikzset{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] {};
    },mynode/.style={outer sep=0pt,draw,shape=circle,minimum size=11mm,inner
sep=0pt}}

\begin{frame}[t]{MWE}
\begin{figure}
\begin{tikzpicture}[scale=1.8]
\node[mynode,fill=red!50] at (0,0) (i1) {$A$};
\node[mynode,fill=blue!50] at (0,-1) (i2) {$B$};
\node[mynode,fill=green!50] at (0,-2) (i3) {$C$};
\node[mynode] at (3,0) (b1) {1};
\node[mynode] at (3,-1) (b2) {2};
\node[mynode] at (3,-2) (b3) {3};
\draw[black,dashed,thick,alt=<1>{opacity=1}{opacity=0.2}] \convexpath{i1,b1}{10.5pt};
\draw[black,dashed,thick,alt=<2>{opacity=1}{opacity=0.2}] \convexpath{i1,b3,i3}{12pt};
\draw[black,dashed,thick,alt=<3>{opacity=1}{opacity=0.2}] \convexpath{i3,b2}{10.5pt};
\draw[black,dashed,thick,alt=<4>{opacity=1}{opacity=0.2}] \convexpath{i1,b1,i2}{13.5pt};
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}

enter image description here