如何仅填充三个圆之间的交点?

如何仅填充三个圆之间的交点?

昨天我遇到了这个问题:如何在 LaTeX 中绘制维恩图(尤其是:补语)。我了解到了相交圆的概念,并且只填充由相交圆的线的边界定义的特定部分。上面的链接中给出了一些示例,但我开始自己进行实验,并能够生成大量的图案:

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[fill=blue]
    %\draw[gray!30] (-2,-2) grid (2,2) (0,0);
    \begin{scope}
    \clip (330:0.75) circle (1);
    \fill (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \begin{scope}
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \draw[color=black] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[xshift=3.5cm]
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \draw[color=black,xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,xshift=3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[xshift=7cm]
    \clip (90:0.75) circle (1) (210:0.75) circle (1);
    \fill (330:0.75) circle (1);
    \end{scope}
    \draw[color=black,xshift=7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,xshift=7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,xshift=7cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[xshift=10.5cm]
    \clip (90:0.75) circle (1) (330:0.75) circle (1);
    \fill (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,xshift=10.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,xshift=10.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,xshift=10.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-3.5cm]
    \clip (90:0.75) circle (1) (330:0.75) circle (1);
    \fill (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=3.5cm]
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm,xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm,xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm,xshift=3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=7cm]
    \clip (210:0.75) circle (1) (90:0.75) circle (1);
    \fill (330:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm,xshift=7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm,xshift=7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm,xshift=7cm] (90:0.75) circle (1) node[]{C};
    
    %other ideas: clipping 2 circles and filling 2. that fills the non-intersected region of one circle, and only the intersection of the other two circles.
    
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=10.5cm]
    \clip (210:0.75) circle (1);
    \fill (330:0.75) circle (1) (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=10.5cm]
    \clip (330:0.75) circle (1);
    \fill (210:0.75) circle (1)  (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=10.5cm]
    \clip (90:0.75) circle (1);
    \fill (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm,xshift=10.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm,xshift=10.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm,xshift=10.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-7cm]
    \clip (210:0.75) circle (1);
    \fill (330:0.75) circle (1) (90:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-7cm, xshift=3.5cm]
    \clip (210:0.75) circle (1) (90:0.75) circle (1);
    \fill (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-7cm, xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm, xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm, xshift=3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-7cm, xshift=7cm,fill=purple]
    \clip (210:0.75) circle (1) (90:0.75) circle (1) (330:0.75) circle (1);
    \fill[red] (90:0.75) circle (1) (330:0.75) circle (1) (210:0.75) circle (1) (210:1);
    \end{scope}
    \draw[color=black,yshift=-7cm, xshift=7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm, xshift=7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm, xshift=7cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[nonzero rule,yshift=-7cm, xshift=10.5cm]
    \clip (210:0.75) circle (1) (90:0.75) circle (1);
    \fill (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-7cm, xshift=10.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm, xshift=10.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm, xshift=10.5cm] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\begin{tikzpicture}[opacity=0.5]
    \draw[color=black, fill=red] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,fill=green] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,fill=blue] (90:0.75) circle (1) node[]{C};
    
    \draw[color=black, fill=gray!10,xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,fill=gray!10,xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,fill=gray!10,xshift=3.5cm] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\end{document}

我一直搞不清楚如何制作的一个图案是仅有的三个圆的交点被填满。(或者反过来:仅有的三个圆相交的区域未填充。)如何实现?如果可以实现,是否可以使用我自己编写的一般代码模式(即,只是一些范围,可能使用一些奇偶规则)来实现,但我还没有想出一种方法?

编辑:好的,所以我想出了一个方法(@Steven B. Segletes 也独立提出了以下相同的想法),那就是制作一些白色填充的形状,并将它们放在正确的蓝色区域上,这样只有中间的蓝色才会显示出来。这是我得到的结果:

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[,fill=blue]
    \begin{scope}[even odd rule,yshift=-7cm]
    \clip (210:0.75) circle (1);
    \fill (330:0.75) circle (1) (90:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[yshift=-6.6cm,xshift=-26,rotate=45,fill=white,color=white] (-1.5,-2) rectangle (-0,0.5);
    \draw[yshift=-5cm,xshift=-39,rotate=45,fill=white,color=white] (-1.5,-2) rectangle (-0,0.5);
    \draw[color=black,yshift=-7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\end{document}

不过,这种方法似乎效率不高(我花了几分钟才把这些矩形放在正确的位置),而且没有使用数学精度(与我可以在 Photoshop 或 LucidChart 上进行的手动定位和着色相反),我喜欢使用 Tikz 之类的工具。有没有更好的方法来做到这一点?

答案1

通过不使用,even odd rule剪辑会在范围内累积。不过,为了实现这一点,它们确实需要是不同的路径。否则,它会将其视为一条路径,并根据其外部进行剪辑。

\documentclass{article}
%\url{https://tex.stackexchange.com/q/640808/86}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
% Store the centres in coordinates for ease of use
\coordinate (A) at (210:0.75);
\coordinate (B) at (330:0.75);
\coordinate (C) at (90:0.75);
\begin{scope}
% Could use a `\foreach` loop here, as below
\clip (A) circle[radius=1]; 
\clip (B) circle[radius=1];
\clip (C) circle[radius=1];
% Could use any of the circles here
\fill[blue] (A) circle[radius=1]; 
\end{scope}
\foreach \coord in {A,B,C}
{
  \draw (\coord) circle[radius=1];
  \node at (\coord) {\(\coord\)};
}
\end{tikzpicture}
\end{document}

顺便说一下,现代 Tikz 语法是circle[radius=1]

以中心突出显示的维恩图

答案2

我知道你可以使用文图包以获得所需的输出。查看手册,您就可以构建所有绘图。

\documentclass[a4paper,12pt]{article}
\usepackage{tikz,venndiagram}

\begin{document}

\begin{venndiagram3sets}
\fillACapBCapC
\end{venndiagram3sets}
\end{document}

在此处输入图片描述

答案3

Pstricks有一个专用包 – pst-venn– 它使用非常短的代码。三个相交圆定义的每个部分都有一个数字(从 1 到 7,因为有七个部分),所有圆的交点都有数字 7,所以我们有这个代码:

    \documentclass[border=6pt, pstricks, svgnames]{standalone}
    \usepackage{pst-venn}

    \begin{document}

    \begin{pspicture*}(-10,-6 )(10,12)
    \psVenn[bgcircle=false,fgcolor=Thistle](-1,0.5)(0,-1)(1,0.5){1.5}{7}
    \end{pspicture*}

    \end{document} 

在此处输入图片描述

答案4

我确信有更好的方法,但我只是叠加了你的几个填充(即你的第 1 个和第 8 个数字),并在进行过程中改变颜色。

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    %\draw[gray!30] (-2,-2) grid (2,2) (0,0);
    \begin{scope}
    \clip (330:0.75) circle (1);
    \fill[red] (210:0.75) circle (1);
    \fill[red] (90:0.75) circle (1);
    \end{scope}
    \begin{scope}
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill[red] (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule]
    \clip (210:0.75) circle (1);
    \fill[white] (330:0.75) circle (1) (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule]
    \clip (330:0.75) circle (1);
    \fill[white] (210:0.75) circle (1)  (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule]
    \clip (90:0.75) circle (1);
    \fill[white] (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容