TikZ 淡入淡出剪辑问题

TikZ 淡入淡出剪辑问题

下列的fade-no-fill.sty 的问题,我想尝试实现@hpekristiansen 解决方案。我在这里给出了更完整的代码,因为路径上实际上有文本节点。

\documentclass[tikz]{standalone}

\usetikzlibrary{shapes, fadings}

\begin{document}
\begin{tikzpicture}
    \node [red,draw,thick,ellipse] (S) at (-3,0) {Solide};
    \node [blue,draw,thick,ellipse] (L) at (3,0) {Liquide};
    \node [green,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
    \draw [thick,-latex,red,path fading=north,postaction={draw,green,path fading=south}] (S) to[bend left] node [midway,above,sloped,black] {Sublimation} (G);
    \draw [thick,-latex,green,path fading=south,postaction={draw,blue,path fading=north}] (G) to[bend left] node [midway,above,sloped,black] {Liquéfaction} (L);
    \draw [thick,-latex,blue,path fading=west,postaction={draw,red,path fading=east}] (L) to[bend left] node [midway,below,sloped,black] {Solidification} (S);
    \draw [thick,-latex,red,path fading=east,postaction={draw,blue,path fading=west}] (S) to node [midway,above,sloped,black] {Fusion} (L);
    \draw [thick,-latex,blue,path fading=north,postaction={draw,green,path fading=south}] (L) to node [midway,below,sloped,black] {Vaporisation} (G);
    \draw [thick,-latex,green,path fading=south,postaction={draw,red,path fading=north}] (G) to node [midway,below,sloped,black] {Condensation} (S);
\end{tikzpicture}
\end{document}

输出(在正确的 PDF 查看器中,请参阅下面的评论https://tex.stackexchange.com/a/615816/56823)如下: 代码输出

我对此有两个问题:

  1. 水平线上的剪切。@hpekristiansen 提到了这个问题和解决方法(也在TikZ 中的淡出箭头),但实际上剪切不仅限于箭头:文本节点也被剪切了!我当然也可以重新绘制它,但这远非理想。请注意,使用arrows.meta和替换-latex不能解决-Latex此处的问题(但如果需要适当的解决方案,则是一个很好的更改)。
  2. 文本节点淡入淡出。我尝试添加path fading=none节点选项,但没有结果。我当然可以单独绘制文本节点,但这仍然远非理想。

答案1

我不确定这在多大程度上算作“黑客行为”,但通常情况下,许多黑客行为可以隐藏在样式中,这样感觉就不会太糟糕。

这两个问题处理如下:

  1. 使得节点不受衰落的影响,但仍定义在相关路径上,则衰落实现于后行动(后行动的选择是任意的 - 可以是两个预行动,也可以是一个前行动和一个后行动)。路径本身未绘制。为了使它更巧妙,我定义了一种path bifading采用两个方向和两种样式的样式(在此,样式只是颜色,但它们可以更通用)。

  2. 为了确保箭头可见,我定义了一个扩展边界框的键。具体来说,在路径的末端,这个键模拟添加一个点,该点位于(-5pt,5pt)相对于路径末端的位置,并旋转,使 x 方向指向路径,y 方向垂直于路径。请注意,这实际上并没有扩展路径,它只是扩展了边界框。到这个坐标系的转换是通过我的spath3库实现的。

\documentclass[tikz,border=10pt]{standalone}
%\url{https://tex.stackexchange.com/q/615945/86}
\usetikzlibrary{
  shapes,
  fadings,
  arrows.meta,
  spath3
}

\tikzset{
  path bifading/.style n args={4}{
    postaction={
      every bifading/.try,
      path fading=#1,%
      #3%
    },
    postaction={
      every bifading/.try,
      path fading=#2,%
      #4%
    }
  },
  every bifading/.style={draw,thick},
  fade arrow/.style={
    #1,
    spath/transform to={current}{1},
    extend bounding box={(-5pt,5pt)}
  }
}

\makeatletter
\tikzset{
  extend bounding box/.code={%
    \tikz@scan@one@point\pgfutil@firstofone#1\relax
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}
\node [red,draw,thick,ellipse] (S) at (-3,0) {Solide};
\node [blue,draw,thick,ellipse] (L) at (3,0) {Liquide};
\node [green,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
\path
[path bifading={north}{south}{red}{green}]
(S) to[bend left] node [midway,above,sloped,black] {Sublimation} (G)
[fade arrow={-Latex}]
;
\path
[path bifading={south}{north}{green}{blue}]
(G) to[bend left] node [midway,above,sloped,black] {Liquéfaction} (L)
[fade arrow={-Latex}]
;
\path
[path bifading={west}{east}{blue}{red}]
(L) to[bend left] node [midway,below,sloped,black] {Solidification} (S)
[fade arrow={-Latex}]
;
\path
[path bifading={east}{west}{red,-Latex}{blue}]
(S) to node [midway,above,sloped,black] {Fusion} (L)
[fade arrow={-Latex}]
;
\path
[path bifading={north}{south}{blue}{green}]
(L) to node [midway,below,sloped,black] {Vaporisation} (G)
[fade arrow={-Latex}]
;
\path
[path bifading={south}{north}{green}{red}]
(G) to node [midway,below,sloped,black] {Condensation} (S)
[fade arrow={-Latex}]
;
\end{tikzpicture}
\end{document}

带有箭头和节点的路径淡化


正如@hpekristiansen 在评论中建议的那样,可以从路径的端点计算出淡入淡出的角度。要使路径在后期操作中可访问,还需要做一些工作,但这是可行的。

\documentclass[tikz,border=10pt]{standalone}
%\url{https://tex.stackexchange.com/q/615945/86}
\usetikzlibrary{
  shapes,
  fadings,
  decorations.markings,
  arrows.meta,
  spath3
}

\tikzset{
  path bifading/.style 2 args={
    postaction={
      spath/save action path,
      extend bounding box,
      every bifading/.try,
      path fading=west,
      set fading angle,
      #1%
    },
    postaction={
      spath/save action path,
      extend bounding box,
      every bifading/.try,
      path fading=east,%
      set fading angle,
      #2%
    }
  },
  every bifading/.style={draw,thick},
}

\makeatletter
\ExplSyntaxOn
\tikzset{
  spath/save~ action~ path/.code={
    \cs_set_eq:cN {\__tikzspath_path_name:n {action}} \tikz@actions@path
  }
}
\ExplSyntaxOff

\tikzset{
  extend bounding box/.code={%
    \begingroup
    \tikzset{spath/transform to={action}{1}}
    \tikz@scan@one@point\pgfutil@firstofone(-5pt,5pt)\relax
    \pgf@protocolsizes{\pgf@x}{\pgf@y}%
    \endgroup
  },
  set fading angle/.code={%
    \tikz@scan@one@point\pgfutil@firstofone(spath cs:action 0)\relax
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \tikz@scan@one@point\pgfutil@firstofone(spath cs:action 1)\relax
    \pgfmathsetmacro\fading@angle{atan2(\pgf@ya - \pgf@y, \pgf@xa - \pgf@x)}%
    \tikzset{fading angle=\fading@angle}%
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}
\node [red,draw,thick,ellipse] (S) at (-3,0) {Solide};
\node [blue,draw,thick,ellipse] (L) at (3,0) {Liquide};
\node [green,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
\path
[
  -Latex,
  path bifading={red}{green}
]
(S) to[bend left] node [midway,above,sloped,black] {Sublimation} (G)
;
\path
[
  -Latex,
  path bifading={green}{blue}
]
(G) to[bend left] node [midway,above,sloped,black] {Liquéfaction} (L)
;
\path
[
  -Latex,
  path bifading={blue}{red}
]
(L) to[bend left] node [midway,below,sloped,black] {Solidification} (S)
;
\path
[
  -Latex,
  path bifading={red}{blue}
]
(S) to node [midway,above,sloped,black] {Fusion} (L)
;
\path
[
  -Latex,
  path bifading={blue}{green}
]
(L) to node [midway,below,sloped,black] {Vaporisation} (G)
;
\path
[
  -Latex,
  path bifading={green}{red}
]
(G) to node [midway,below,sloped,black] {Condensation} (S)
;
\end{tikzpicture}
\end{document}

自动角度路径衰减

答案2

仅供记录,这是我的解决方法:

\documentclass[tikz]{standalone}

\usetikzlibrary{shapes, fadings, decorations.markings}

\begin{document}
\begin{tikzpicture}
    \node [red,draw,thick,ellipse] (S) at (-3,0) {Solide};
    \node [blue,draw,thick,ellipse] (L) at (3,0) {Liquide};
    \node [green,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
    \draw [thick,-latex,red,path fading=north,postaction={draw,green,path fading=south}] (S) to[bend left] (G);
    \draw [thick,-latex,green,path fading=south,postaction={draw,blue,path fading=north}] (G) to[bend left] (L);
    \draw [thick,-latex,blue,path fading=west,postaction={draw,red,path fading=east}] (L) to[bend left] (S);
    \draw [thick,-latex,red,path fading=east,postaction={draw,blue,path fading=west},decoration={markings,mark=at position 1 with {\arrow[blue]{latex}}},preaction={decorate}] (S) to  (L);
    \draw [thick,-latex,blue,path fading=north,postaction={draw,green,path fading=south}] (L) to (G);
    \draw [thick,-latex,green,path fading=south,postaction={draw,red,path fading=north}] (G) to (S);
    \path (S) to[bend left] node [midway,above,sloped] {Sublimation} (G);
    \path (G) to[bend left] node [midway,above,sloped] {Liquéfaction} (L);
    \path (L) to[bend left] node [midway,below,sloped] {Solidification} (S);
    \path (S) to node [midway,above,sloped] {Fusion} (L);
    \path (L) to node [midway,below,sloped] {Vaporisation} (G);
    \path (G) to node [midway,below,sloped] {Condensation} (S);
\end{tikzpicture}
\end{document}

其(正确)输出如下: 代码输出

答案3

这是一个不使用的解决方案decorations.markings

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes, fadings}
\begin{document}
\begin{tikzpicture}
    \node [red,draw,thick,ellipse] (S) at (-3,0) {Solide};
    \node [blue,draw,thick,ellipse] (L) at (3,0) {Liquide};
    \node [green,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
    \draw [thick,-latex,red,path fading=north,postaction={draw,green,path fading=south}] (S) to[bend left] (G);
    \draw [thick,-latex,green,path fading=south,postaction={draw,blue,path fading=north}] (G) to[bend left] (L);
    \draw [thick,-latex,blue,path fading=west,postaction={draw,red,path fading=east}] (L) to[bend left] (S);
    \draw [thick,-latex,red,path fading=east,postaction={draw,blue,path fading=west}] ([yshift=5pt]S.east) (S.east) to  (L);
    \draw [thick,-latex,blue,path fading=north,postaction={draw,green,path fading=south}] (L) to (G);
    \draw [thick,-latex,green,path fading=south,postaction={draw,red,path fading=north}] (G) to (S);
    \path (S) to[bend left] node [midway,above,sloped] {Sublimation} (G);
    \path (G) to[bend left] node [midway,above,sloped] {Liquéfaction} (L);
    \path (L) to[bend left] node [midway,below,sloped] {Solidification} (S);
    \path (S) to node [midway,above,sloped] {Fusion} (L);
    \path (L) to node [midway,below,sloped] {Vaporisation} (G);
    \path (G) to node [midway,below,sloped] {Condensation} (S);
\end{tikzpicture}
\end{document}

带箭头的三个节点

相关内容