假设我们有四个节点 a、b、c 和 d。例如:
\coordinate [label=left:a] (a) at (0,4);
\coordinate [label=right:b] (b) at (4,4);
\coordinate [label=left:c] (c) at (0,0);
\coordinate [label=right:d] (d) at (4,0);
让我们在 {(a,b), (a,c), (c,d), (d,b), (b,a)} 中的每对之间绘制一些任意路径。例如:
\draw [red] (a) to [bend left=30] (c);
\draw [blue] (b) to [out=45, in= -50] (a);
\draw [orange] (c) to [controls=+(45:6) and +(170:6)] (d);
\draw [green!60!black,decorate,decoration={snake,pre length=1pt}] (d) -- (b);
据我所知
\path (a) -- (c) -- (d) -- (b) -- cycle;
被视为一条路径,因此我们可以填充此路径内的区域;但是在上面的例子中,我们有四条路径,因此填充区域对于 tikZ 来说是没有意义的。
我的问题:是否可以融合所有路径(例如)以创建一条可填充路径,例如\fill [blue!10] (a) -- (c) -- (d) -- (b) -- cycle;
或其他路径?换句话说,我想孵化表面 S。
全部代码:
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\mathversion{bold}
\begin{document}
\begin{tikzpicture}
\coordinate [label=left:a] (a) at (0,4);
\coordinate [label=right:b] (b) at (4,4);
\coordinate [label=left:c] (c) at (0,0);
\coordinate [label=right:d] (d) at (4,0);
\foreach \p in {a,b,c,d}{
\fill[red] (\p) circle (2pt);}
\draw [red] (a) to [bend left=30] (c);
\draw [blue] (b) to [out=45, in= -50] (a);
\draw [orange] (c) to [controls=+(45:6) and +(170:6)] (d);
\draw [green!60!black,decorate,decoration={snake,pre length=1pt}] (d) -- (b);
\node at (2,2.5) {$S$};
\end{tikzpicture}
\end{document}
更清楚的是,我在创建(易碎的)tcolorbox时遇到了这个问题
我想填充空白表面 S,但是有四条路径我无法做到这一点。
答案1
当然可以。您不能用不同的颜色绘制路径,但您当然可以组合要填充的路径,然后明确地单独绘制彩色路径,或者通过edge
s 绘制彩色路径。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\mathversion{bold}
\begin{document}
\begin{tikzpicture}
\coordinate [label=left:a] (a) at (0,4);
\coordinate [label=right:b] (b) at (4,4);
\coordinate [label=left:c] (c) at (0,0);
\coordinate [label=right:d] (d) at (4,0);
\foreach \p in {a,b,c,d}{
\fill[red] (\p) circle (2pt);}
\path[decoration={snake,pre length=1pt},fill=blue!20]
(a) to [bend left=30] (c)
to [controls=+(45:6) and +(170:6)](d)
decorate { -- (b)}
to [out=45, in= -50] cycle;
\draw [red] (a) to [bend left=30] (c);
\draw [blue] (b) to [out=45, in= -50] (a);
\draw [orange] (c) to [controls=+(45:6) and +(170:6)] (d);
\draw [green!60!black,decorate,decoration={snake,pre length=1pt}] (d) -- (b);
\node at (2,2.5) {$S$};
\end{tikzpicture}
\end{document}
并添加even odd rule
,即
\path[decoration={snake,pre length=1pt},fill=blue!20,even odd rule]
(a) to [bend left=30] (c)
to [controls=+(45:6) and +(170:6)](d)
decorate { -- (b)}
to [out=45, in= -50] cycle;
产量