1

I am trying to create a macro which gets 3 nodes as input and then draws some kind of ellipse (a hyperedge) around these 3 nodes. This is how I currently draw the edges, but I would like to automate the process.

\documentclass[tikz]{standalone}
\usetikzlibrary{topaths,calc,patterns}

\begin{document}
\begin{tikzpicture}
\def \r {1.2cm}
\def \n {8}
\def \vxsize {0.2cm}


\pgfdeclarelayer{bg}    % declare background layer
\pgfsetlayers{bg,main}  % set the order of the layers (main is the standard layer)

\foreach \i in {1,...,\n} {
    \pgfmathsetmacro\angle{(\i -1)*360/\n}
    \node[draw=black,fill=black!50, circle, minimum width = \vxsize, inner sep=0cm] (u\i) at (\angle:\r) {};
}

\node (v) at (270:\r+0.5cm) {loose cycle};

\begin{pgfonlayer}{bg}
\begin{scope}[fill opacity=0.5]
\foreach \i in {2,4,...,\n} {
    \pgfmathsetmacro\anglea{(\i -1)*360/\n - 8}
    \pgfmathsetmacro\angleb{(\i)*360/\n}
    \pgfmathsetmacro\anglec{(\i +1)*360/\n + 8}
    \filldraw[fill=red, draw=black, thick] (\anglea:\r) 
    to[out = \anglea, in = \angleb + 270] (\angleb:1.27*\r) 
    to[out = 90 + \angleb, in = \anglec] (\anglec:\r)
    to[out = 180 + \anglec, in =90+ \angleb] (\angleb:0.73*\r)
    to[out = 270 + \angleb, in = 180+\anglea] (\anglea:\r);
}
\end{scope}
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

loose cycle

My basic approach is as follows:

\newcommonad{\hyperedge}[3]{%
\coordinate (P1) at (#1);
\coordinate (P2) at (#2);
\coordinate (P3) at (#3);
\begin{scope}[shift = (P2)]
**Get x and y coordinates of (P1)-(P2) and (P3)-(P2)**
[draw the edge]
\end{scope} 
}

\node (v1) at (0,3);
\node (v2) at (1,2);
\node (v3) at (3,2);
\hyperedge{v1}{v2}{v3}

Is there a simple way to get the x and y coordinates in line 6 so that they are stored in variables x_1, y_1, x_3, y_3? Once I have this, I should be able to draw the shape (I hope).

Many thanks!

jan1892
  • 23
  • 6

0 Answers0