1

I made the following diagram based on an excellent, very interesting answer to an earlier question.

enter image description here

%%% Preamble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[border=9,tikz,rgb]{standalone}
\usetikzlibrary{arrows.meta,decorations.pathreplacing}
\tikzset{/pgf/arrow keys/colorsize/.style={fill=#1,length=10pt, line width=0.5pt}}
\begin{document}
%%% Set total number of vertices here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\N{6}
%%% Set vertex coordinates here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzdeclarecoordinatesystem{sunflower}{ % #1 is vertex index
    \pgfmathsetmacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunangle{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunradius{sqrt(\sunindex)*50}
    \pgfpointpolar{\sunangle}{\sunradius}
}
%%% Set colours here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\globalcolorstrue
\def\definesuncolor#1{
    \pgfmathtruncatemacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunhue{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunsaturation{sqrt(\sunindex/\N)}
    \definecolor{sun#1}{Hsb}{\sunhue,\sunsaturation,1}
}
%%% Draw here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikz{
%%% Draw vertices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{1,...,\N}{
        \definesuncolor{\i}
        \path(sunflower cs:\i)node(vertex\i)
            [circle,draw,minimum size=2cm,line width=6pt]{};
        \fill[sun\i](vertex\i)+(1pt,1pt)circle(1);
    }
%%% Draw edges %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{2,...,\N}{
        \foreach\j in{1,...,\numexpr\i-1}{
            \path[scale=.666/sqrt(\N)]
                [shift=(vertex\i)](sunflower cs:\j)coordinate(X-\i-\j)
                [shift=(vertex\j)](sunflower cs:\i)coordinate(Y-\i-\j);
            \draw[{Stealth[colorsize=sun\j]}-{Stealth[colorsize=sun\i]}]
                [line width=.1](X-\i-\j)--(Y-\i-\j);
        }
    }
}
%%% End here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

I've played around with it a lot, but I still don't fully understand how it all pieces together. What I'd like to be able to do is make adaptations like this (drawn with Adobe Illustrator), while maintaining scalability, etc:

enter image description here

I asked this question a while back, hoping it might help me come up with a way to incorporate the two concepts and produce a hybrid, but my skills just aren't quite there yet.

So specifically: Instead of all the nodes pointing to every other node (once), they just need to point to the first node (twice).

In the end I managed to get this far:

enter image description here

%%% Preamble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[border=9,tikz,rgb]{standalone}
\usetikzlibrary{arrows.meta,calc}%,decorations.pathreplacing}
\tikzset{/pgf/arrow keys/colorsize/.style={fill=#1,length=10pt,line width=0.4pt,scale=1}}
\begin{document}
%%% Set total number of vertices here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\N{6}
%%% Set vertex coordinates here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzdeclarecoordinatesystem{sunflower}{ % #1 is vertex index
    \pgfmathsetmacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunangle{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunradius{sqrt(\sunindex)*50}
    \pgfpointpolar{\sunangle}{\sunradius}
}
%%% Set colours here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\globalcolorstrue
\def\definesuncolor#1{
    \pgfmathtruncatemacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunhue{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunsaturation{sqrt(\sunindex/\N)}
    \definecolor{sun#1}{Hsb}{\sunhue,\sunsaturation,1}
}
%%% Draw here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikz{
%%% Draw vertices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{1,...,\N}{
        \definesuncolor{\i}
        \path(sunflower cs:\i)node(vertex\i)
            [circle,draw,minimum size=2cm,line width=6pt]{};
        \fill[sun\i](vertex\i)+(1pt,1pt)circle(1);
    }
%%% Draw edges %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{2,...,\N}{
        \foreach\j in{1,...,\i}{
            \path[scale=.666/sqrt(\N)]
                [shift=(vertex\i)](sunflower cs:\j)coordinate(X-\i-\j)
                [shift=(vertex\j)](sunflower cs:\i)coordinate(Y-\i-\j);}
            \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}]
                [line width=.1](X-\i-1)--(Y-\i-1);
    }
}
%%% End here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

So that's one down. Now I just need to double up on these edges and arrowheads but I'm not sure how to incorporate the following syntax into it:

\draw[arr=1em] ($(c)!1mm!90:(n\i)$) -- ($(n\i)!1mm!-90:(c)$);
\draw[arr=1em] ($(c)!1mm!-90:(n\i)$) -- ($(n\i)!1mm!90:(c)$);
voices
  • 2,039
  • 1
    If you only want to draw one connection, you do no longer need the loop over \j. –  Jul 05 '19 at 21:49

2 Answers2

3

Like this ?

screenshot

\documentclass[border=9,tikz,rgb]{standalone}
\usetikzlibrary{arrows.meta,calc}%,decorations.pathreplacing}
\tikzset{/pgf/arrow keys/colorsize/.style={fill=#1,length=10pt,line width=0.4pt,scale=1}}

\begin{document}
%%% Set total number of vertices here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\N{6}
%%% Set vertex coordinates here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzdeclarecoordinatesystem{sunflower}{ % #1 is vertex index
    \pgfmathsetmacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunangle{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunradius{sqrt(\sunindex)*50}
    \pgfpointpolar{\sunangle}{\sunradius}
}
%%% Set colours here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\globalcolorstrue
\def\definesuncolor#1{
    \pgfmathtruncatemacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunhue{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunsaturation{sqrt(\sunindex/\N)}
    \definecolor{sun#1}{Hsb}{\sunhue,\sunsaturation,1}
}
%%% Draw here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikz{
%%% Draw vertices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{1,...,\N}{
        \definesuncolor{\i}
        \path(sunflower cs:\i)node(vertex\i)
            [circle,draw,minimum size=2cm,line width=6pt]{};
        \fill[sun\i](vertex\i)+(1pt,1pt)circle(1);
    }
%%% Draw edges %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{2,...,\N}{
        \foreach\j in{1,...,\i}{
            \path[scale=.666/sqrt(\N)]
                [shift=(vertex\i)](sunflower cs:\j)coordinate(X-\i-\j)
                [shift=(vertex\j)](sunflower cs:\i)coordinate(Y-\i-\j);
                }
            \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}]
                [line width=.1]
                ($(X-\i-1)!1mm!90:(Y-\i-1)$)--($(Y-\i-1)!1mm!-90:(X-\i-1)$);
            \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}]
                [line width=.1]
                ($(X-\i-1)!1mm!-90:(Y-\i-1)$)--($(Y-\i-1)!1mm!90:(X-\i-1)$);
    }
}

%%% End here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
AndréC
  • 24,137
3

The sunflower code is extremely ingenious. It attaches the arrow to another node to the same spot of this node in a local coordinate system. So a node top right on the picture will connect to a top right position on the node. This is a beautiful idea!

With regards to your question, if you do not want to connect all nodes with each other, then you do not need the inner loop over \j. So you can label the coordinates by \i only, and all you need to do is to replace (n\i) and (c) by (X-\i) and (Y-\i), respectively.

\documentclass[border=9,tikz,rgb]{standalone}
\usetikzlibrary{arrows.meta,calc}%,decorations.pathreplacing}
\tikzset{/pgf/arrow keys/colorsize/.style={fill=#1,length=10pt,line width=0.4pt,scale=1}}
\begin{document}
%%% Set total number of vertices here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\N{6}
%%% Set vertex coordinates here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzdeclarecoordinatesystem{sunflower}{ % #1 is vertex index
    \pgfmathsetmacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunangle{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunradius{sqrt(\sunindex)*50}
    \pgfpointpolar{\sunangle}{\sunradius}
}
%%% Set colours here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\globalcolorstrue
\def\definesuncolor#1{
    \pgfmathtruncatemacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunhue{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunsaturation{sqrt(\sunindex/\N)}
    \definecolor{sun#1}{Hsb}{\sunhue,\sunsaturation,1}
}
%%% Draw here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikz{
%%% Draw vertices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{1,...,\N}{
        \definesuncolor{\i}
        \path(sunflower cs:\i)node(vertex\i)
            [circle,draw,minimum size=2cm,line width=6pt]{};
        \fill[sun\i](vertex\i)+(1pt,1pt)circle(1);
    }
%%% Draw edges %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{2,...,\N}{
            \path[scale=.666/sqrt(\N)]
                [shift=(vertex\i)](sunflower cs:1)coordinate(X-\i)
                [shift=(vertex1)](sunflower cs:\i)coordinate(Y-\i);
            \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}]
                [line width=.1]
                 ($(X-\i)!1mm!90:(Y-\i)$) -- ($(Y-\i)!1mm!-90:(X-\i)$);
            \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}]
                [line width=.1]
                 ($(X-\i)!1mm!-90:(Y-\i)$) -- ($(Y-\i)!1mm!90:(X-\i)$);
    }
}
%%% End here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

enter image description here

I personally would shrink the mini sun coordinate system since you have less connections and thus more space.

\documentclass[border=9,tikz,rgb]{standalone}
\usetikzlibrary{arrows.meta,calc}%,decorations.pathreplacing}
\tikzset{/pgf/arrow keys/colorsize/.style={fill=#1,length=10pt,line width=0.4pt,scale=1}}
\begin{document}
%%% Set total number of vertices here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\N{6}
\def\sunscale{50}
%%% Set vertex coordinates here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzdeclarecoordinatesystem{sunflower}{ % #1 is vertex index
    \pgfmathsetmacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunangle{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunradius{sqrt(\sunindex)*\sunscale}
    \pgfpointpolar{\sunangle}{\sunradius}
}
%%% Set colours here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\globalcolorstrue
\def\definesuncolor#1{
    \pgfmathtruncatemacro\sunindex{#1-.5}
    \pgfmathsetmacro\sunhue{mod(\sunindex*16.18034,10)*36}
    \pgfmathsetmacro\sunsaturation{sqrt(\sunindex/\N)}
    \definecolor{sun#1}{Hsb}{\sunhue,\sunsaturation,1}
}
%%% Draw here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikz{
%%% Draw vertices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach\i in{1,...,\N}{
        \definesuncolor{\i}
        \path(sunflower cs:\i)node(vertex\i)
            [circle,draw,minimum size=2cm,line width=6pt]{};
        \fill[sun\i](vertex\i)+(1pt,1pt)circle(1);
    }
%%% Draw edges %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \def\sunscale{35} % redefine the sun coordinate system scale
    \foreach\i in{2,...,\N}{
            \path[scale=.666/sqrt(\N)]
                [shift=(vertex\i)](sunflower cs:1)coordinate(X-\i)
                [shift=(vertex1)](sunflower cs:\i)coordinate(Y-\i);
            \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}]
                [line width=.1]
                 ($(X-\i)!1mm!90:(Y-\i)$) -- ($(Y-\i)!1mm!-90:(X-\i)$);
            \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}]
                [line width=.1]
                 ($(X-\i)!1mm!-90:(Y-\i)$) -- ($(Y-\i)!1mm!90:(X-\i)$);
    }
}
%%% End here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

enter image description here

  • Interesting. I didn't know you could do that. On an unrelated note, Is it possible to add a [bend right=40] to the /draw command? I managed to do it with the /path command, but it doesn't have the arrowheads etc. – voices Jul 06 '19 at 16:10
  • 1
    @tjt263 Sure: \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}] [line width=.1] ($(X-\i)!1.2mm!90:(Y-\i)$) to[bend left=20] ($(Y-\i)!1.2mm!-90:(X-\i)$); \draw[{Stealth[colorsize=sun1]}-{Stealth[colorsize=sun\i]}] [line width=.1] ($(X-\i)!1.2mm!-90:(Y-\i)$) to[bend right=20] ($(Y-\i)!1.2mm!90:(X-\i)$); You need to replace -- by to for bending and friends. (you can replace 20 by 40 but I feel 20 looks better but this is just personal taste). –  Jul 06 '19 at 16:14