填充路径的交叉点

填充路径的交叉点

我知道有很多帖子涉及 tikz 中对象的交叉,但到目前为止,我还没有找到一篇展示如何交叉两条路径的帖子。我想对两个斑点的交叉处进行阴影处理或填充:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usetikzlibrary{hobby,intersections,fillbetween,patterns}
 
\begin{document}

\begin{tikzpicture}
\path[name path = A,draw,use Hobby shortcut,closed=true, fill=blue]
(0,2) .. (3,3) .. (4,-3) .. (5,1);
\path[name path = B,draw,use Hobby shortcut,closed=true, fill=red,xshift=3cm, yshift=-1cm, fill opacity=.5]
(.5,.5) .. (2,4) .. (.5,4) .. (-1,2);
\end{tikzpicture}

\end{document}

在此处输入图片描述

由于无法看到如何使用\clip\path并按照这个帖子,我想fillbetween这可能是答案,但添加

\tikzfillbetween[of=A and B,split] {pattern=north west lines};

生产

在此处输入图片描述

我想我明白为什么了。我怎样才能只给交叉点添加阴影?

答案1

如果我理解正确的话,解决方案是\clip

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{hobby,patterns}
\begin{document}
\begin{tikzpicture}
\path[use Hobby shortcut,closed=true, fill=red,xshift=3cm, yshift=-1cm,fill opacity=0.5]
        (0.5,0.5) .. (2,4) .. (.5,4) .. (-1,2);
\path[use Hobby shortcut,closed=true, fill=blue]
        (0,2) .. (3,3) .. (4,-3) .. (5,1);
\begin{scope}
\clip[use Hobby shortcut, closed=true, xshift=3cm, yshift=-1cm]
        (0.5,0.5) .. (2,4) .. (.5,4) .. (-1,2);
\path[use Hobby shortcut,closed=true, pattern=north west lines,preaction={fill=red,opacity=0.5}]
        (0,2) .. (3,3) .. (4,-3) .. (5,1);
\end{scope}
\path[draw,use Hobby shortcut,closed=true]
        (0,2) .. (3,3) .. (4,-3) .. (5,1);
\path[draw,use Hobby shortcut,closed=true,xshift=3cm, yshift=-1cm]
        (0.5,0.5) .. (2,4) .. (.5,4) .. (-1,2); 
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容