用曲线和波浪线绘制混合区

用曲线和波浪线绘制混合区

我正在尝试创建下面的图片。 混合区

我只取得了如此大的进展。

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tikz-feynman}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
    \begin{figure}[!ht]
        \centering
        \begin{tikzpicture}
        \draw (0,0) -- (2,0) -- (2,3);
        \draw (0,0) -- (0,3);
        \draw[decorate,decoration={snake,amplitude=.4mm,segment length=2mm,post length=0mm}] (0,2.5) -- (0.9,2.5);
        \draw[decorate,decoration={snake,amplitude=.4mm,segment length=2mm,post length=0mm}] (1.1,2.5) -- (2,2.5);
        \draw[dashed] (0.9,2.5) to[out=-180,in=180] (1,1.5);
        \draw[dashed] (1.1,2.5) to[out=0,in=0] (1,1.5);
        \draw[red] (0.9,3.2) -- +(0,-0.7);
        \draw[red] (1.1,3.2) -- +(0,-0.7);
        \begin{feynman}
        \vertex (a) at (0.9,2.5) {};
        \vertex (b) at (1,1.5);
        \diagram{(a) -- [gluon] (b) -- };
        \end{feynman}
        \end{tikzpicture}
     \end{figure}
\end{document}

输出为

tikz输出

我可以处理文本部分,但我很难弄清楚混合区域中的线条。另外,有没有办法绕过蛇形线的直线部分。我想要一条连续的波浪线。任何帮助都将不胜感激。

提前致谢!

答案1

混合可能最好在 Inkscape 之类的软件中完成。除非你想要下面这样的效果,在我看来,这有点像恶魔的地狱。

但是,这个答案的重点是演示一种防止snake拉直的方法。另一种方法是确保amplitude精确地除以路径长度。在我看来,将较长的路径剪裁成合适的大小要容易得多。

在这里,我们定义一个pic来进行裁剪、绘制路径并将效果限制在本地范围内。pic命名的路径wiggle有两个参数,即路径的起点和终点。将绘制一条较长的路径并将其裁剪为合适的大小,以确保直线部分全部在裁剪部分中,而不是在图表的其余部分中。

我不知道它gluon与目标图像有何关系,所以我把它省略了,特别是因为它似乎需要 LuaTeX。显然,如果需要,可以替换它。

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{decorations.pathmorphing,decorations.pathreplacing,calc,fadings}
\begin{document}
\tikzset{%
  my snake/.style={decorate, decoration={snake, amplitude=.4mm, segment length=2mm, post length=0pt}},
  pics/wiggle/.style 2 args={%
    code={%
      \begin{scope}
        \clip ([yshift=.5mm]#1) rectangle  ([yshift=-.5mm]#2);
        \draw [my snake] ([xshift=-2mm]#1) --  ([xshift=2mm]#2);
      \end{scope}%
    },
  },
}
\begin{tikzpicture}
  \draw (0,0) -- (2,0) -- (2,3);
  \draw (0,0) -- (0,3);
  % because the \coordinate ... at ... fails
  \foreach \i [count=\j]  in {(0.9,2.5), (1.1,2.5), (1,1.5), (0,2.5), (2,2.5)} \path \i coordinate (p\j);
  \begin{scope}
    \clip (p1) [out=-180, in=180] to (p3) [out=0, in=0] to (p2) [out=-180, in=0] to cycle;
    \begin{scope}[shift=($($(p1)!1/2!(p2)$)!1/2!(p3)$), scale=.25]
      % p. 604
      \foreach \l/\i/\j\k/\m in {(0,0)/2mm/60/1mm/red!50!gray,(-.25,1)/1.9mm/-60/1.5mm/red!25!black,(.5,-1)/2mm/70/2mm/red!20!gray!90!black,(.3,.5)/2mm/60/2mm/red!30!black,(.4,1.15)/2.1mm/80/1mm/red,(-.1,-1)/1.85mm/40/2.5mm/black,(.1,-.7)/2mm/80/2mm/gray}
      {
        \path [opacity=.5, blend mode=overlay, \m, inner color=\m!50, outer color=\m, path fading=circle with fuzzy edge 15 percent, opacity=.6] \l circle (15mm) ;
        \path [decoration={waves, segment length=\i, angle=\j, radius=\k}, line width=.3mm, postaction={decorate, draw}, opacity=.35, blend mode=difference, \m] \l circle (5mm) ;
      }
    \end{scope}
  \end{scope}
  \pic {wiggle={p4}{p1}};
  \pic {wiggle={p2}{p5}};
  \draw[dashed] (p1)   to[out=-180,in=180]   (p3);
  \draw[dashed] (p2)  to[out=0,in=0] (p3);
  \draw[red] (0.9,3.2) -- +(0,-0.7);
  \draw[red] (1.1,3.2) -- +(0,-0.7);
\end{tikzpicture}
\end{document}

混合

答案2

要在某个区域上“涂鸦”,您可以选择合适的路径来填充该区域,然后使用coil或对其进行变形random steps

线圈:

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{
  mixing/.style={decorate, decoration={coil, amplitude=.125cm, segment length=.125cm, aspect=.75}},
  water/.style={decorate,decoration={snake,amplitude=.4mm,segment length=2mm,post length=0mm}}}
\begin{document}
\begin{tikzpicture}
  \draw (-1,1.25) -- +(0,-3) -- +(2,-3) -- +(2,0);
  \draw[water] (-1, .7) -- +(2,0);
  \draw[dashed] (0,0) circle (.5 and .75);
  \draw[double, double distance=.3cm, red] (0,1.5) -- (0,.6); % tube
  \draw [mixing] (0,.5) arc (450:70:.25 and .5);
  \draw [mixing, red] (0,.25) arc (90:540:.13 and .25);
\end{tikzpicture}
\end{document}

线圈

随机步骤:

\documentclass[tikz, border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{
  mixing/.style={decorate, decoration={random steps, amplitude=.25cm, segment length=.2mm}, rounded corners=1mm},
  water/.style={decorate,decoration={snake,amplitude=.4mm,segment length=2mm,post length=0mm}}}
\begin{document}
\begin{tikzpicture}
  \draw (-1,1.25) -- +(0,-3) -- +(2,-3) -- +(2,0);
  \draw[water] (-1, .7) -- +(2,0);
  \draw[dashed] (0,0) circle (.5 and .75);
  \draw[double, double distance=.2cm, red] (0,1.5) -- (0,.6);
  \draw [mixing] (0,0) circle (.25 and .5);
  \draw [mixing, red] (0,0) circle (.2 and .4);
\end{tikzpicture}
\end{document}

随机步骤

平滑路径变形在已经紧密弯曲的路径上不能特别一致地起作用,但如果您只是需要涂鸦,那么几个尖角可能不会有太大损害。

当然,您可能喜欢摆弄变形参数。对于某些参数,路径变形会产生错误Dimension too large.,但似乎没有任何明显的后果。

结果random steps可能会有所不同(随机),因此您可能需要选择一个可以给出良好结果的种子(通过使用\pgfmathsetseed{<integer>})。

相关内容