我根据一个优秀的非常有趣的答案回答之前的一个问题。
%%% 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}
我已经尝试了很多次,但我仍然不完全理解它们是如何组合在一起的。我希望能够进行这样的调整(使用 Adobe Illustrator 绘制),同时保持可扩展性等:
我问这个问题不久前,我希望它能帮助我想出一种方法来结合这两个概念并产生一种混合体,但我的技能还不够。
因此具体来说:所有节点不需要指向其他每个节点(一次),而只需指向第一个节点(两次)。
最终我成功做到了这一点:
%%% 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}
所以就完成了一个。现在我只需要将这些边和箭头加倍,但我不确定如何将以下语法合并到其中:
\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)$);
答案1
像这样 ?
\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}
答案2
向日葵代码非常巧妙。它将指向另一个节点的箭头附加到本地坐标系中该节点的同一位置。因此,图片右上角的节点将连接到该节点的右上方位置。这是一个很棒的主意!
关于您的问题,如果您不想将所有节点相互连接,则不需要对 进行内循环\j
。因此,您可以仅用 标记坐标\i
,而您需要做的就是分别用(n\i)
和替换和。(c)
(X-\i)
(Y-\i)
\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}
我个人会缩小迷你太阳坐标系,因为连接更少,因此空间更大。
\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}