2

For illustrating my thesis on k-gap-planar graphs I'd like to find an elegant and parametrizable way to produce drawings of such graphs with cased edges (to make clear to which of the edges the intersection is charged).

Reference article with similar drawings

What I've accomplished so far is rather cluttered and I hope it can be simplified. I've used the tikzpackage "intersections" to place a white disc on top of each crossing and repeat the edge that should pass the intersection without beeing gapped. "intersections" allows to name the involved paths, but I couldn't find out how to let the named paths be drawn again without defining them anew (see code and image below).

The combination of calculation the crossings by "intersections" and putting the edges on different layers via "pgfonlayer"-environment to control the drawing sequence did not work. Maybe this package is not compatible with edges on different layers.

I appreciate any relevant suggestions :) 1-gap-planar drawing of K_7 with edge casing

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\tikzstyle{vertex}=[circle, draw=black, fill=black, radius = 1mm,
scale = 0.8,anchor=center]

\tikzstyle{crossing}=[circle, radius=0.5pt, fill= white]

\tikzstyle{cased}=[draw=white,line width = 12pt,
double=black,very thick, distance = 2pt]

\begin{tikzpicture}[every node/.style={vertex}]
    \pgfmathtruncatemacro{\n}{4}
    \foreach \pos
    [evaluate=\pos as \angle using (360/\n/2)+\pos*360/\n)]
    in {2,...,\n}
    {%inner  vertices
        \path node (i\pos) at (\angle:2) {};% 
    };
    \foreach \pos
    [evaluate=\pos as \angle using (360/\n/2)+\pos*360/\n)]
    in {1,2,...,\n}
    {%outer vertices
        \node (o\pos) at (\angle:6) {};
    };       

    %bent outer edges
    \pgfmathtruncatemacro{\distA}{10}
    \path[name path=e_o1_o3] (o1.center) .. controls 
    +(30:\distA) and +(60:\distA) .. (o3.center);
    \draw[name path=e_o2_o4] (o2.center) .. controls 
    +(120:\distA) and +(150:\distA) .. (o4.center);

    %straight edges between inner and outer
    %o4.center
    \draw[name path=e_o4_i4]  (o4.center) -- (i4.center);
    %o2.center
    \draw[name path=e_o2_i2]  (o2.center) -- (i2.center);
    %o3.center
    \draw[name path=e_o3_i3]  (o3.center) -- (i3.center);

    %bent edges between inner and outer
    %offset=1
    \pgfmathtruncatemacro{\distI}{2}
    %o1.center
    \draw[name path=e_o1_i4]  (o1.center) .. controls 
    +(-20:\distI) and +(140:\distI) .. (i4.center);
    \path[name path=e_o1_i2]  (o1.center) .. controls 
    +(-70:\distI) and +(130:\distI) .. (i2.center);
    %o4.center
    \draw[name path=e_o4_i3]  (o4.center) .. controls 
    +(-110:\distI) and +(50:\distI) .. (i3.center);
    %o2.center
    \path[name path=e_o2_i3]  (o2.center) .. controls 
    +(20:\distI) and +(-140:\distI) .. (i3.center);
    %o3.center
    \draw[name path=e_o3_i2]  (o3.center) .. controls 
    +(160:\distI) and +(-40:\distI) .. (i2.center);
    \path[name path=e_o3_i4]  (o3.center) .. controls 
    +(110:\distI) and +(-50:\distI) .. (i4.center);

    %bent edges between inner and outer
    %offset=2 (opposite)
    \pgfmathsetmacro{\distG}{5.5}
    %o1.center
    \path[name path=e_o1_i3]  (o1.center) .. controls 
    +(-10:\distG) and +(70:\distG) .. (i3.center);
    %o4.center
    \path[name path=e_o4_i2]  (o4.center) .. controls 
    +(-100:\distG) and +(-20:\distG) .. (i2.center);
    %o2.center
    \draw[name path=e_o2_i4]  (o2.center) .. controls 
    +(80:\distG) and +(160:\distG) .. (i4.center);

    \foreach \pos
    [remember=\pos as \last (initially \n)]
    in {1,2,...,\n}
    {%straight outer edges
        \draw[name path=e_o\pos_o\last] (o\pos.center) -- 
        (o\last.center);
    };
    \foreach \pos
    [remember=\pos as \last (initially \n)]
    in {2,...,\n}
    {%straight inner edges
        \draw (i\pos.center) -- (i\last.center);
    };  

    %crossings
    \begin{scope}[every node/.style={crossing}]
        %crossing e_o1_o3 and e_o2_o4
        \path [draw,name intersections={of={e_o1_o3 and e_o2_o4}}]
        (intersection-1) node (a) {} ;
        %repeat edge drawing
        \draw[name path=e_o1_o3] (o1.center) .. controls 
        +(30:\distA) and +(60:\distA) .. (o3.center);
        %crossing e_o1_i2 and e_o2_i4
        \path [draw,name intersections={of={e_o1_i2 and e_o2_i4}}]
        (intersection-1) node (b) {} ;
        %repeat edge drawing
        \draw[name path=e_o1_i2]  (o1.center) .. controls 
        +(-70:\distI) and +(130:\distI) .. (i2.center);
        %crossing e_o1_i3 and e_o4_i4
        \path [draw,name intersections={of={e_o1_i3 and e_o4_i4}}]
        (intersection-1) node (d) {} ;
        %repeat edge drawing
        \draw[name path=e_o1_i3]  (o1.center) .. controls 
        +(-10:\distG) and +(70:\distG) .. (i3.center);
        %crossing e_o1_i3 and e_o3_i4
        \path [draw,name intersections={of={e_o1_i3 and e_o3_i4}}]
        (intersection-1) node (c) {} ;
        %crossing e_o2_i3 and e_o3_i2
        \path [draw,name intersections={of={e_o2_i3 and e_o3_i2}}]
        (intersection-1) node (e) {};
        %repeat edge drawing
        \draw[name path=e_o2_i3]  (o2.center) .. controls 
        +(20:\distI) and +(-140:\distI) .. (i3.center) ;
        %crossing e_o2_i3 and e_o4_i2
        \path [draw,name intersections={of={e_o2_i3 and e_o4_i2}}]
        (intersection-1) node (f) {} ;
        %crossing e_o3_i4 and e_o4_i3
        \path [draw,name intersections={of={e_o3_i4 and e_o4_i3}}]
        (intersection-1) node (i) {} ;
        %repeat edge drawing
        \draw[name path=e_o3_i4]  (o3.center) .. controls 
        +(110:\distI) and +(-50:\distI) .. (i4.center);
        %crossing e_o3_i4 and e_o4_i2
        \path [draw,name intersections={of={e_o3_i4 and e_o4_i2}}]
        (intersection-1) node (g) {} ;
        %crossing e_o3_i3 and e_o4_i2
        \path [draw,name intersections={of={e_o3_i3 and e_o4_i2}}] 
        (intersection-1) node (h) {} ;
        %repeat edge drawing
        \draw[name path=e_o4_i2]  (o4.center) .. controls 
        +(-100:\distG) and +(-20:\distG) .. (i2.center);
    \end{scope}
\end{tikzpicture}
\end{document}
  • There is the phantastic knots library which does all the things that you do by hand. – user194703 Nov 18 '19 at 21:32
1

Welcome! You could just use the very nice knots library. Instead of drawing all these paths, finding intersections, redrawing them ourselves, let knots do that for us. One basically needs to replace all the \draw commands by \strand, and that's it.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{knots,%bbox
}
\begin{document}

\tikzset{vertex/.style={circle, draw=black, fill=black, radius = 1mm,
scale = 0.8,anchor=center}}

\begin{tikzpicture}[every node/.style={vertex},%bezier bounding box
    ]
    \begin{knot}[%draft mode=crossings,
    knot gap=9,%<- controls the gap size
    flip crossing/.list={1,...,9}]
    \pgfmathtruncatemacro{\n}{4}
    \foreach \pos
    [evaluate=\pos as \angle using (360/\n/2)+\pos*360/\n)]
    in {2,...,\n}
    {%inner  vertices
        \path node (i\pos) at (\angle:2) {};% 
    };
    \foreach \pos
    [evaluate=\pos as \angle using (360/\n/2)+\pos*360/\n)]
    in {1,2,...,\n}
    {%outer vertices
        \node (o\pos) at (\angle:6) {};
    };       

    %bent outer edges
    \pgfmathtruncatemacro{\distA}{10}
    \strand (o2.center) .. controls 
        +(120:\distA) and +(150:\distA) .. (o4.center);

    %straight edges between inner and outer
    %o4.center
    \strand  (o4.center) -- (i4.center);
    %o2.center
    \strand  (o2.center) -- (i2.center);
    %o3.center
    \strand  (o3.center) -- (i3.center);

    %bent edges between inner and outer
    %offset=1
    \pgfmathtruncatemacro{\distI}{2}
    %o1.center
    \strand  (o1.center) .. controls +(-20:\distI) and +(140:\distI) .. (i4.center);
    %o4.center
    \strand  (o4.center) .. controls +(-110:\distI) and +(50:\distI) .. (i3.center);
    %o2.center
    %o3.center
    \strand  (o3.center) .. controls +(160:\distI) and +(-40:\distI) .. (i2.center);
    %bent edges between inner and outer
    %offset=2 (opposite)
    \pgfmathsetmacro{\distG}{5.5}
    %o1.center
    %o4.center
    %o2.center
    \strand  (o2.center) .. controls 
    +(80:\distG) and +(160:\distG) .. (i4.center);

    \foreach \pos
    [remember=\pos as \last (initially \n)]
    in {1,2,...,\n}
    {%straight outer edges
        \draw (o\pos.center) --  (o\last.center);
    };
    \foreach \pos
    [remember=\pos as \last (initially \n)]
    in {2,...,\n}
    {%straight inner edges
        \draw (i\pos.center) -- (i\last.center);
    };  
    %crossings
    \strand (o1) .. controls +(30:\distA) and +(60:\distA) .. (o3);
    \strand (o1) .. controls +(-70:\distI) and +(130:\distI) .. (i2);
    \strand (o1) .. controls +(-10:\distG) and +(70:\distG) .. (i3);
    \strand (o2) .. controls +(20:\distI) and +(-140:\distI) .. (i3) ;
    \strand (o3) .. controls +(110:\distI) and +(-50:\distI) .. (i4);
    \strand (o4) .. controls +(-100:\distG) and +(-20:\distG) .. (i2);
    \end{knot}  
\end{tikzpicture}
\end{document}

enter image description here

Notice that

  1. you can flip crossings, as illustrated. I hope to have reproduced your conventions, but if not, you can always unflip a crossing;
  2. draft mode=crossings, allows you to find out which crossing belongs to which number;
  3. \tikzstyle is deprecated;
  4. if you use the bbox library, you can even fix the bounding box automatically. As of now, you'd need to download the this file as tikzlibrarybbox.code.tex and put it somewhere where LaTeX can find it, such as the same directory as the file you are compiling. If I understood correctly, this library may become part of the official libraries in the future. Unfortunately I fail to understand even the most basic GitHub commands and messages, so I am not sure.)
| improve this answer | |
  • Thank you so much, this is exactly what I was looking for! – Grohana Nov 23 '19 at 8:45
  • The only problem I encountered was that strands inside a foreach-loop are neither drawn nor considered in the knot calculation. If I add the option draw to them, they are visible, but still part of knots, although they cross each other or another strand outside the loop. Example: \begin{tikzpicture} \begin{knot}[draft mode=crossings ] \strand (-3,-3) -- (3,3); \foreach \pos in {1,...,5} { \strand (\pos*70+30:2) -- (\pos*30+20:2); \strand[draw] (\pos*70:2) -- (\pos*30:2); }; \end{knot} \end{tikzpicture} – Grohana Nov 23 '19 at 9:03
  • @Grohana Presumably this is because a foreach loop puts its argument in a group and the \strand command does not make things global. For simple loops like the one you are mentioning you could just use a \loop. Something like \newcounter{iloop}\setcounter{iloop}{0}\loop\stepcounter{iloop} \strand (\number\value{iloop}*70+30:2) -- (\number\value{iloop}*30+20:2); \strand[draw] (\number\value{iloop}*70:2) -- (\number\value{iloop}*30:2); \ifnum\value{iloop}<5\repeat. – user194703 Nov 23 '19 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.