绘制形状奇特的节点以包含 tikz 中的现有节点

绘制形状奇特的节点以包含 tikz 中的现有节点

我在 tikz 中有一个有点复杂的人物。

在此处输入图片描述

您会注意到有两种颜色(在我看来它们是红色和绿色,但有人告诉我色盲人士可以区分它们:如果您是色盲并且它们没有区别,请告诉我)。我想绘制一个适当形状的节点,该节点包围所有包含两个红色和两个绿色的圆圈,中心节点为红色,另一个节点包围所有包含两个红色和两个绿色的圆圈,中心节点为绿色。我希望这些节点不相交或包含任何其他节点。

这是我用来创建图形的代码。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, backgrounds, fit, arrows, arrows.meta}
\definecolor{colorS}{RGB}{0,154,128}
\definecolor{colorI}{RGB}{255,32,0}
\tikzstyle{SusCirc}=[circle,draw=black!50,fill=colorS!90,thick, minimum size=2mm, inner sep = 0mm]%a circle
                                %representing a susceptible individual
\tikzstyle{InfCirc}=[circle,draw=black!50,fill=colorI!90,thick, minimum size=2mm, inner sep = 0mm]%a circle
                                %representing an infected individual
\tikzstyle{BigCirc}=[circle,draw=black!50,thick,inner sep=0pt,minimum size=0pt, inner sep = 0mm]



\begin{document}
\begin{tikzpicture}
\coordinate (top) at (0.000000,0.2500000);
\coordinate (left) at (-0.2165,-0.1250000);
\coordinate (right) at (0.2165,-0.1250000);
\coordinate (center) at (0,0);

\coordinate (SSSSloc) at (10.000000, 0.000000);
  \node[SusCirc, minimum size = 2mm] (SSSScenter) at ($(SSSSloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (SSSSleft) at ($(SSSSloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (SSSStop) at ($(SSSSloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (SSSSright) at ($(SSSSloc)+(right)$) {};
  \draw [-] (SSSScenter) -- (SSSSleft);
  \draw [-] (SSSScenter) -- (SSSStop);
  \draw [-] (SSSScenter) -- (SSSSright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SSSScenter)(SSSSleft)(SSSStop)(SSSSright)] (SSSS) at (SSSSloc) {};
\end{pgfonlayer}


\coordinate (SSSIloc) at (8.349598, 2.05150);
  \node[SusCirc, minimum size = 2mm] (SSSIcenter) at ($(SSSIloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (SSSIleft) at ($(SSSIloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (SSSItop) at ($(SSSIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (SSSIright) at ($(SSSIloc)+(right)$) {};
  \draw [-] (SSSIcenter) -- (SSSIleft);
  \draw [-] (SSSIcenter) -- (SSSItop);
  \draw [-] (SSSIcenter) -- (SSSIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SSSIcenter)(SSSIleft)(SSSItop)(SSSIright)] (SSSI) at (SSSIloc) {};
\end{pgfonlayer}


\coordinate (SSISloc) at (7.109723, 1.3464);%+0.2
  \node[SusCirc, minimum size = 2mm] (SSIScenter) at ($(SSISloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (SSISleft) at ($(SSISloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (SSIStop) at ($(SSISloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (SSISright) at ($(SSISloc)+(right)$) {};
  \draw [-] (SSIScenter) -- (SSISleft);
  \draw [-] (SSIScenter) -- (SSIStop);
  \draw [-] (SSIScenter) -- (SSISright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SSIScenter)(SSISleft)(SSIStop)(SSISright)] (SSIS) at (SSISloc) {};
\end{pgfonlayer}


\coordinate (SSIIloc) at (4.911270, 2.8868);
  \node[SusCirc, minimum size = 2mm] (SSIIcenter) at ($(SSIIloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (SSIIleft) at ($(SSIIloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (SSIItop) at ($(SSIIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (SSIIright) at ($(SSIIloc)+(right)$) {};
  \draw [-] (SSIIcenter) -- (SSIIleft);
  \draw [-] (SSIIcenter) -- (SSIItop);
  \draw [-] (SSIIcenter) -- (SSIIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SSIIcenter)(SSIIleft)(SSIItop)(SSIIright)] (SSII) at (SSIIloc) {};
\end{pgfonlayer}


\coordinate (SISSloc) at (7.059278, -1.007567); %-0.2
  \node[SusCirc, minimum size = 2mm] (SISScenter) at ($(SISSloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (SISSleft) at ($(SISSloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (SISStop) at ($(SISSloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (SISSright) at ($(SISSloc)+(right)$) {};
  \draw [-] (SISScenter) -- (SISSleft);
  \draw [-] (SISScenter) -- (SISStop);
  \draw [-] (SISScenter) -- (SISSright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SISScenter)(SISSleft)(SISStop)(SISSright)] (SISS) at (SISSloc) {};
\end{pgfonlayer}


\coordinate (SISIloc) at (4.955251, 1.31373); 
  \node[SusCirc, minimum size = 2mm] (SISIcenter) at ($(SISIloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (SISIleft) at ($(SISIloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (SISItop) at ($(SISIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (SISIright) at ($(SISIloc)+(right)$) {};
  \draw [-] (SISIcenter) -- (SISIleft);
  \draw [-] (SISIcenter) -- (SISItop);
  \draw [-] (SISIcenter) -- (SISIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SISIcenter)(SISIleft)(SISItop)(SISIright)] (SISI) at (SISIloc) {};
\end{pgfonlayer}


\coordinate (SIISloc) at  (3.473197, 0.17413);
  \node[SusCirc, minimum size = 2mm] (SIIScenter) at ($(SIISloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (SIISleft) at ($(SIISloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (SIIStop) at ($(SIISloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (SIISright) at ($(SIISloc)+(right)$) {};
  \draw [-] (SIIScenter) -- (SIISleft);
  \draw [-] (SIIScenter) -- (SIIStop);
  \draw [-] (SIIScenter) -- (SIISright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SIIScenter)(SIISleft)(SIIStop)(SIISright)] (SIIS) at (SIISloc) {};
\end{pgfonlayer}


\coordinate (SIIIloc) at (1.487967, 2.03170);
  \node[SusCirc, minimum size = 2mm] (SIIIcenter) at ($(SIIIloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (SIIIleft) at ($(SIIIloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (SIIItop) at ($(SIIIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (SIIIright) at ($(SIIIloc)+(right)$) {};
  \draw [-] (SIIIcenter) -- (SIIIleft);
  \draw [-] (SIIIcenter) -- (SIIItop);
  \draw [-] (SIIIcenter) -- (SIIIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (SIIIcenter)(SIIIleft)(SIIItop)(SIIIright)] (SIII) at (SIIIloc) {};
\end{pgfonlayer}


\coordinate (ISSSloc) at (8.323451, -1.79198);
  \node[InfCirc, minimum size = 2mm] (ISSScenter) at ($(ISSSloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (ISSSleft) at ($(ISSSloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (ISSStop) at ($(ISSSloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (ISSSright) at ($(ISSSloc)+(right)$) {};
  \draw [-] (ISSScenter) -- (ISSSleft);
  \draw [-] (ISSScenter) -- (ISSStop);
  \draw [-] (ISSScenter) -- (ISSSright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (ISSScenter)(ISSSleft)(ISSStop)(ISSSright)] (ISSS) at (ISSSloc) {};
\end{pgfonlayer}


\coordinate (ISSIloc) at (6.478631, 0.190366);
  \node[InfCirc, minimum size = 2mm] (ISSIcenter) at ($(ISSIloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (ISSIleft) at ($(ISSIloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (ISSItop) at ($(ISSIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (ISSIright) at ($(ISSIloc)+(right)$) {};
  \draw [-] (ISSIcenter) -- (ISSIleft);
  \draw [-] (ISSIcenter) -- (ISSItop);
  \draw [-] (ISSIcenter) -- (ISSIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (ISSIcenter)(ISSIleft)(ISSItop)(ISSIright)] (ISSI) at (ISSIloc) {};
\end{pgfonlayer}


\coordinate (ISISloc) at (5.037411, -0.94354);
  \node[InfCirc, minimum size = 2mm] (ISIScenter) at ($(ISISloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (ISISleft) at ($(ISISloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (ISIStop) at ($(ISISloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (ISISright) at ($(ISISloc)+(right)$) {};
  \draw [-] (ISIScenter) -- (ISISleft);
  \draw [-] (ISIScenter) -- (ISIStop);
  \draw [-] (ISIScenter) -- (ISISright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (ISIScenter)(ISISleft)(ISIStop)(ISISright)] (ISIS) at (ISISloc) {};
\end{pgfonlayer}


\coordinate (ISIIloc) at  (2.797099, 1.3294); %+0.2
  \node[InfCirc, minimum size = 2mm] (ISIIcenter) at ($(ISIIloc)+(center)$) {};
  \node[SusCirc, minimum size = 2mm] (ISIIleft) at ($(ISIIloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (ISIItop) at ($(ISIIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (ISIIright) at ($(ISIIloc)+(right)$) {};
  \draw [-] (ISIIcenter) -- (ISIIleft);
  \draw [-] (ISIIcenter) -- (ISIItop);
  \draw [-] (ISIIcenter) -- (ISIIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (ISIIcenter)(ISIIleft)(ISIItop)(ISIIright)] (ISII) at (ISIIloc) {};
\end{pgfonlayer}


\coordinate (IISSloc) at (5.071966, -2.5883046);
  \node[InfCirc, minimum size = 2mm] (IISScenter) at ($(IISSloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (IISSleft) at ($(IISSloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (IISStop) at ($(IISSloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (IISSright) at ($(IISSloc)+(right)$) {};
  \draw [-] (IISScenter) -- (IISSleft);
  \draw [-] (IISScenter) -- (IISStop);
  \draw [-] (IISScenter) -- (IISSright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (IISScenter)(IISSleft)(IISStop)(IISSright)] (IISS) at (IISSloc) {};
\end{pgfonlayer}


\coordinate (IISIloc) at (2.951006, -1.02703);%-0.2
  \node[InfCirc, minimum size = 2mm] (IISIcenter) at ($(IISIloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (IISIleft) at ($(IISIloc)+(left)$) {};
  \node[SusCirc, minimum size = 2mm] (IISItop) at ($(IISIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (IISIright) at ($(IISIloc)+(right)$) {};
  \draw [-] (IISIcenter) -- (IISIleft);
  \draw [-] (IISIcenter) -- (IISItop);
  \draw [-] (IISIcenter) -- (IISIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (IISIcenter)(IISIleft)(IISItop)(IISIright)] (IISI) at (IISIloc) {};
\end{pgfonlayer}


\coordinate (IIISloc) at (1.725861, -1.81121);
  \node[InfCirc, minimum size = 2mm] (IIIScenter) at ($(IIISloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (IIISleft) at ($(IIISloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (IIIStop) at ($(IIISloc)+(top)$) {};
  \node[SusCirc, minimum size = 2mm] (IIISright) at ($(IIISloc)+(right)$) {};
  \draw [-] (IIIScenter) -- (IIISleft);
  \draw [-] (IIIScenter) -- (IIIStop);
  \draw [-] (IIIScenter) -- (IIISright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (IIIScenter)(IIISleft)(IIIStop)(IIISright)] (IIIS) at (IIISloc) {};
\end{pgfonlayer}


\coordinate (IIIIloc) at (0.000000, 0.000000);
  \node[InfCirc, minimum size = 2mm] (IIIIcenter) at ($(IIIIloc)+(center)$) {};
  \node[InfCirc, minimum size = 2mm] (IIIIleft) at ($(IIIIloc)+(left)$) {};
  \node[InfCirc, minimum size = 2mm] (IIIItop) at ($(IIIIloc)+(top)$) {};
  \node[InfCirc, minimum size = 2mm] (IIIIright) at ($(IIIIloc)+(right)$) {};
  \draw [-] (IIIIcenter) -- (IIIIleft);
  \draw [-] (IIIIcenter) -- (IIIItop);
  \draw [-] (IIIIcenter) -- (IIIIright);
\begin{pgfonlayer}{background}
  \node[BigCirc, fit = (IIIIcenter)(IIIIleft)(IIIItop)(IIIIright)] (IIII) at (IIIIloc) {};
\end{pgfonlayer}

  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (ISSS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (SSSI);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (SSIS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSS) -- (SISS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SSSI.240) -- (ISSI.30);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSI) -- (SSII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSSI) -- (SISI);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SSIS.210) -- (ISIS.70);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSIS) -- (SSII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSIS) -- (SIIS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SSII) -- (ISII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SSII) -- (SIII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SISS) -- (IISS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SISS.150) -- (SISI.290);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SISS) -- (SIIS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SISI.250) -- (IISI.30);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SISI) -- (SIII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SIIS.200) -- (IIIS.70);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-] (SIIS.160) -- (SIII.290);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (SIII) -- (IIII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSS.110) -- (ISSI.330);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSS) -- (ISIS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSS) -- (IISS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSI) -- (ISII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISSI) -- (IISI);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISIS.110) -- (ISII.330);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISIS) -- (IIIS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (ISII) -- (IIII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IISS) -- (IISI);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IISS) -- (IIIS);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IISI) -- (IIII);
  \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (IIIS) -- (IIII);
\end{tikzpicture}
\end{document}

绘制这样的节点可行吗?理想情况下,我希望能够用另一种颜色填充它,并且不需要太多的调整。

评论一下我为什么要这样做。我有初始图。然后我显示我加入的这些状态是对称的(也会对 3 和 1 节点执行此操作),然后我将边缘从原始节点之间切换到新分区之间。最后,我将分区折叠成单个节点。

答案1

以下是一个建议,涉及完全重写您的代码。稍后可能会添加更多解释,但目前,一些关键点如下:

  • 状态是用pic而不是新的节点集合来绘制的。

  • 定位已调整,以便事物对称(似乎是要做的事情)

  • 箭头画成两个\foreach环。

至于您的问题实际上涉及的部分,与此相关的代码如下,位于末尾tikzpicture

\begin{scope}[on background layer]
\draw [line width=40pt,opacity=0.3,red,line cap=round,rounded corners] (IISScirc.center) -- (SIIScirc.center) -- (ISIScirc.center);
\draw [line width=40pt,opacity=0.3,blue,line cap=round,rounded corners] (SSIIcirc.center) -- (ISSIcirc.center) -- (SISIcirc.center);

\coordinate (A) at ($(ISSIcirc)!0.4!(SSIIcirc)$);
\coordinate (B) at ($(IISScirc)!0.6!(SIIScirc)$);
\draw [stealth-stealth,ultra thick,green]  ($(A)!20pt!90:(SSIIcirc)$) -- ($(B)!20pt!90:(IISScirc)$);
\end{scope}

前两行只是通过指定的三个点画了一条很宽的线。最后一行展示了计算这条宽线边缘点的一种方法。可能还有其他方法,而且可能更好,但我也不是一个巫师。

无论如何,首先发生的事情是两个coordinates 定义在两个节点之间的某个位置。在第一个 s 中,A位于ISSIcirc和之间 40% 的位置SSIIcirc

语句中使用的坐标\draw计算在指定距离处投影到该点。所以意味着距离($(A)!20pt!90:(SSIIcirc)$)的点沿着与之间的线成 90 度角的线。为什么?因为粗线的线宽是,所以一半就可以到达它的边缘。20ptAASSIIcirc20pt40pt

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, backgrounds, fit, arrows, arrows.meta}

\definecolor{colorS}{RGB}{0,154,128}
\definecolor{colorI}{RGB}{255,32,0}
\tikzset{
S/.style={circle,draw=black!50,fill=colorS!90,thick, minimum size=2mm, inner sep = 0mm},
I/.style={circle,draw=black!50,fill=colorI!90,thick, minimum size=2mm, inner sep = 0mm},
BigCirc/.style={circle,draw=black!50,thick,inner sep=0pt,minimum size=0pt, inner sep = 0mm},
pics/circles/.style args={#1#2#3#4}{
  code={
   \node [#1,minimum size=2mm] (#1#2#3#4top) at (0,0.25) {};
   \node [#2,minimum size=2mm] (#1#2#3#4left) at (-0.2165,-0.125) {};
   \node [#3,minimum size=2mm] (#1#2#3#4right) at (0.2165,-0.125) {};
   \node [#4,minimum size=2mm] (#1#2#3#4center) at (0,0) {};
   \draw (#1#2#3#4top) -- (#1#2#3#4center) -- (#1#2#3#4left) (#1#2#3#4center) -- (#1#2#3#4right);
    \node[BigCirc, fit = (#1#2#3#4left)(#1#2#3#4top)(#1#2#3#4right)] (circ) at (#1#2#3#4center) {};
   }
  }
}

\pgfmathsetmacro{\xA}{1.5}
\pgfmathsetmacro{\xB}{3}
\pgfmathsetmacro{\xC}{3.35}
\pgfmathsetmacro{\yA}{1.2}
\pgfmathsetmacro{\yB}{2.05}
\pgfmathsetmacro{\yC}{2.9}

\begin{document}


\begin{tikzpicture}
\pic (IIII) at (0,0)         {circles=IIII};
\pic (IIIS) at (\xA,\yB)     {circles=IIIS};
\pic (IISI) at (\xA,-\yB)    {circles=IISI};
\pic (ISII) at (\xB,\yA)     {circles=ISII};
\pic (SIII) at (\xB,-\yA)    {circles=SIII};
\pic (IISS) at (\xC,0)       {circles=IISS};
\pic (SIIS) at (5,\yA)       {circles=SIIS};
\pic (ISSI) at (5,-\yA)      {circles=ISSI};
\pic (ISIS) at (5,\yC)       {circles=ISIS};
\pic (SISI) at (5,-\yC)      {circles=SISI};
\pic (SSIS) at (10-\xA,\yB)  {circles=SSIS};
\pic (SSSI) at (10-\xA,-\yB) {circles=SSSI};
\pic (ISSS) at (10-\xB,\yA)  {circles=ISSS};
\pic (SISS) at (10-\xB,-\yA) {circles=SISS};
\pic (SSII) at (10-\xC,0)    {circles=SSII};
\pic (SSSS) at (10,0)        {circles=SSSS};

\foreach \A/\B in {
  IIIS/SIIS, IIIS/ISIS, IIIS/IISS, IISS/ISSS,
  IISS/SISS, ISIS/ISSS, ISIS/SSIS, SSIS/SSSS,
  ISSS/SSSS, SISS/SSSS, SSSI/SSSS, SIIS/SSIS}
    \draw [-{Latex[length=2.5mm,width=1mm,angle'=30]}] (\A circ) -- (\B circ);


\foreach \A/\B in {
  IIII/IIIS, IIII/ISII, IIII/SIII, IIII/IISI,
  IISI/IISS, IISI/ISSI, IISI/SISI,
  SSSI/SISI, SSSI/ISSI, SSSI/SSII,
  SIII/SIIS, SIII/SSII, ISSS/ISSI,
  ISII/ISIS, ISII/SSII, ISII/ISSI,
  SISI/SIII, SISI/SISS, SSIS/SSII}
    \draw [{Latex[length=2.5mm,width=1mm,angle'=30]}-{Latex[length=2.5mm,width=1mm,angle'=30]}] (\A circ) -- (\B circ);

\begin{scope}[on background layer]
\draw [line width=40pt,opacity=0.3,red,line cap=round,rounded corners] (IISScirc.center) -- (SIIScirc.center) -- (ISIScirc.center);
\draw [line width=40pt,opacity=0.3,blue,line cap=round,rounded corners] (SSIIcirc.center) -- (ISSIcirc.center) -- (SISIcirc.center);

\coordinate (A) at ($(ISSIcirc)!0.4!(SSIIcirc)$);
\coordinate (B) at ($(IISScirc)!0.6!(SIIScirc)$);
\draw [stealth-stealth,ultra thick,green]  ($(A)!20pt!90:(SSIIcirc)$) -- ($(B)!20pt!90:(IISScirc)$);
\end{scope}

\end{tikzpicture}
\end{document}

答案2

这并不是试图回答您的问题,而是演示如何使用图片(在某种程度上)简化代码。具体来说,doodle 在 BigCirc 中绘制所有内容,每次使用新键 Tcolor、Lcolor、Rcolor 和 Ccolor 更改填充颜色。诚然,设置它需要手动进行更多计算,但对于 TikZ 来说,工作量要少得多。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, backgrounds, fit, arrows, arrows.meta}
\definecolor{colorS}{RGB}{0,154,128}
\definecolor{colorI}{RGB}{255,32,0}

\tikzstyle{BigCirc}=[circle,draw=black!50,thick,inner sep=0pt,minimum size=8.8mm, inner sep = 0mm]

\tikzset{% create new tikz keys
  Tcolor/.initial=white,
  Rcolor/.initial=white,
  Lcolor/.initial=white,
  Ccolor/.initial=white}

\tikzset{% create pic doodle
pics/doodle/.style ={code = { %
\draw[-] (0,0.1) -- (0,0.15)
  (-.0866,-.05) -- (-.1299,-.075)
  (.0866,-.05) -- (.1299,-.075);
\path[draw=black!50,thick,fill=\pgfkeysvalueof{/tikz/Ccolor}!90]
  (0,0) circle[radius=1mm];
\path[draw=black!50,thick,fill=\pgfkeysvalueof{/tikz/Tcolor}!90]
  (0,0.25) circle[radius=1mm];
\path[draw=black!50,thick,fill=\pgfkeysvalueof{/tikz/Lcolor}!90]
 (-0.2165,-0.125) circle[radius=1mm];
\path[draw=black!50,thick,fill=\pgfkeysvalueof{/tikz/Rcolor}!90]
 (0.2165,-0.125) circle[radius=1mm];
}}}

\begin{document}
\begin{tikzpicture}

\coordinate (SSSSloc) at (0,0);
\begin{pgfonlayer}{background}
  \pic[Tcolor=colorS,Lcolor=colorS,Rcolor=colorS,Ccolor=colorS] at (SSSSloc) {doodle};
  \node[BigCirc] (SSSS) at (SSSSloc) {};
\end{pgfonlayer}

\pic[Tcolor=colorI,Lcolor=colorI,Rcolor=colorI,Ccolor=colorS] at (1,0) {doodle};

\end{tikzpicture}
\end{document}

相关内容