是否有一些用于自动融合操作的 Tikz 库/包?

是否有一些用于自动融合操作的 Tikz 库/包?

融合是指插入连接电线的盒子,这样电线就可以缠绕或融合,如下图所示。您可以在右侧看到黄色电缆位于红色电缆下方。

在此处输入图片描述

我可以(可能)在 Tikz 上绘制这个,但我更希望有一种自动化的方法来写下这样的图表,其中电缆的曲线是根据它们行进的“距离”等固定的。

任何帮助都将受到赞赏。


编辑:使用辫子包我可以绘制如下图片:

在此处输入图片描述

但是绘制框并以统一的方式定义样式非常耗时且困难。

答案1

您在评论中说您尝试过使用braids包,但很难制作盒子。由于辫子上到处都是坐标,fit因此使用库制作盒子并不困难。

接下来,我先画出辫子,然后使用坐标定义节点。通过用背景色填充这些节点,我就可以“擦除”部分辫子线。我1在“辫子”一词中使用了很多 s,以确保线足够长,同时还提供沿其长度的大量坐标(另一种方法是使用辫子height来延长各个部分,然后使用calc库来填充不存在的坐标)。

虽然代码看起来很长,但相当一部分可以包含在样式中(每个辫子上的样式大致相同),而且也没有大量的补充计算。甚至 s 也fit可以简化,因为每个都可以写成fit=(braid-i-j) (braid-i+1-j+1)

事实上,如果我要做很多这样的事,那么我可能会把它包装成一个pic(因为pics 可以嵌套),它设置了股线的样式,处理了标签,然后我会为只需要一个坐标和标签的盒子定义一个单独的图片。

\documentclass{article}
%\url{https://tex.stackexchange.com/q/646559/86}
\usepackage{tikz}
\usetikzlibrary{braids,fit}

\begin{document}

\begin{tikzpicture}

\coordinate (above) at (0,1.5);
\coordinate (below) at (0,-1.5);

\pic[
  rotate=90,
  braid/.cd,
  number of strands=3,
  every strand/.style={ultra thick},
  strand 1/.style={red},
  strand 2/.style={green},
  strand 3/.style={blue},
  anchor=1-3
] at (above)  (simple) {braid={1 1 1 1 1}};

\node[left] at (simple-3-s) {\(\alpha\)};
\node[left] at (simple-2-s) {\(\beta\)};
\node[left] at (simple-1-s) {\(\gamma\)};

\node[right] at (simple-3-e) {\(\alpha\)};
\node[right] at (simple-2-e) {\(\beta\)};
\node[right] at (simple-1-e) {\(\gamma\)};

\node[fit=(simple-2-1) (simple-3-2),draw,fill=white] {\(U_{\beta\alpha}\)};
\node[fit=(simple-2-3) (simple-1-4),draw,fill=white] {\(U_{\gamma\beta}\)};


\pic[
  rotate=90,
  braid/.cd,
  number of strands=3,
  every strand/.style={ultra thick},
  strand 1/.style={red},
  strand 2/.style={green},
  strand 3/.style={blue},
  anchor=3-5
] at (below) (fusion) {braid={1 1 1 s_1^{-1} 1 1 1 1 1}};

\node[left] at (fusion-3-s) {\(\alpha\)};
\node[left] at (fusion-2-s) {\(\beta\)};
\node[left] at (fusion-1-s) {\(\gamma\)};

\node[right] at (fusion-3-e) {\(\alpha\)};
\node[right] at (fusion-2-e) {\(\beta\)};
\node[right] at (fusion-1-e) {\(\gamma\)};

\node[fit=(fusion-1-1) (fusion-2-2),draw,fill=white] {\(U_{\gamma\beta}\)};
\node[fit=(fusion-1-5) (fusion-3-6),draw,fill=white] {\(U_{\gamma\alpha}\)};
\node[fit=(fusion-1-7) (fusion-2-8),draw,fill=white] {\(U_{\beta\gamma}\)};

\path (simple-1-3) -- (fusion-3-4) node[font=\Huge,pos=.5] {\(=\)};

\end{tikzpicture}

\end{document}

辫状线熔接操作

答案2

不是自动的,但也不太复杂

\documentclass[tikz, border=2mm]{standalone}

\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[box/.style={draw, minimum size=15mm},
    crossingline/.style={double, draw=white, double=black, very thick}]
    
\node[box] (A) {$U_{\beta\alpha}$};
\draw ([yshift=-3mm]A.north west) coordinate (A1) --++(180:8mm) node[left] (alpha) {$\alpha$};
\draw ([yshift=3mm]A.south west) coordinate (A2) --++(180:8mm) node[left] (beta) {$\beta$};
\node[box, above right= 6mm and 1cm of A.south east, anchor=north west] (B) {$U_{\gamma\beta}$};
\draw ([yshift=3mm]B.south west) coordinate (B2) -- (B2-|alpha.east) node [left] {$\gamma$};
\draw (B2-|B.east) --++(0:8mm) node [right] (gamma) {$\gamma$};
\draw (A2-|B.east)--(A2-|gamma.west) node [right] {$\beta$};
\draw (A1-|A.east)--(A1-|gamma.west) node [right] {$\alpha$};
\draw (A2-|A.east)--(A2-|B.west);

\end{tikzpicture}


\begin{tikzpicture}[box/.style={draw, minimum size=15mm},
    crossingline/.style={double, draw=white, double=black, very thick}]
    
\node[box] (A) {$U_{\gamma\beta}$};
\node[box, below right= 6mm and 3cm of A.north east, anchor=south west] (B) {$U_{\gamma\alpha}$};
\node[box, above right= 6mm and 1cm of B.south east, anchor=north west] (C) {$U_{\beta\gamma}$};

\draw ([yshift=3mm]A.south west) coordinate (A2) --++(180:8mm) node[left] (gamma) {$\gamma$};
\draw ([yshift=-3mm]A.north west) coordinate (A1) --++(180:8mm) node[left] (beta) {$\beta$};
\draw ([yshift=-3mm]B.north west) coordinate (B1) -- (B1-|gamma.east) node [left] {$\alpha$};

\draw (A1-|B.east)--(A1-|C.west);
\draw (A1-|C.east) --++(0:8mm) node[right] (beta) {$\beta$};
\draw (A2-|C.east) --(A2-|beta.west) node[right] {$\gamma$};
\draw (B1-|B.east) --(B1-|beta.west) node[right] {$\alpha$};

\path (A1-|A.east) -- coordinate[midway] (center1) (A1-|B.west);
\path (A2-|A.east) -- coordinate[midway] (center2) (A2-|B.west);

\draw[rounded corners] (A1-|A.east) -- ([xshift=-5mm]center1)--([xshift=5mm]center2)--(A2-|C.west);
\draw[rounded corners, crossingline] (A2-|A.east) -- ([xshift=-5mm]center2)--([xshift=5mm]center1)--(A1-|B.west);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容