自定义维恩图

自定义维恩图

对于我的工作,我需要一个由三个圆圈组成且相交处被一条线分成两部分的维恩图。在此处输入图片描述

我使用了 Tex.SE 的答案,但我不知道如何使用它来绘制中间线,并像图中那样对其进行阴影处理。有人能帮我吗?

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \tikzset{venn circle/.style={draw,circle,minimum width=6cm,fill=#1,opacity=0.4}}

  \node [venn circle = red] (A) at (0,0) {$A$};
  \node [venn circle = blue] (B) at (60:4cm) {$B$};
  \node [venn circle = green] (C) at (0:4cm) {$C$};
  \node[left] at (barycentric cs:A=1/2,B=1/2 ) {$A \cap B$}; 
  \node[below] at (barycentric cs:A=1/2,C=1/2 ) {$A \cap C$};   
  \node[right] at (barycentric cs:B=1/2,C=1/2 ) {$B \cap C$};   
  \node[below] at (barycentric cs:A=1/3,B=1/3,C=1/3 ){$A \cap B \cap C$};
\end{tikzpicture}  
\end{document}

在此处输入图片描述

答案1

也许您可以进一步完善它,但我认为这基本上可以回答您的问题。您需要做的是构建一条路径,您可以在其中进行操作并使用它创建所需的图案或填充。因此,您计算圆的交点并将其传递给坐标。您可以使用这些坐标来计算圆心和交点之间的角度,最后使用圆弧创建要填充的形状。要创建分隔 A、B 和 C 重叠区域的交点线,您基本上需要计算圆 B 的交点以及 A 和 C 两个交点之间的线。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}
  \tikzset{venn circle/.style={draw,circle,minimum width=6cm,fill=#1,opacity=0.4,text opacity=1}}

  \node [name path=A, venn circle = red] (A) at (0,0) {$A$};
  \node [name path=B, venn circle = blue] (B) at (60:4cm) {$B$};
  \node [name path=C, venn circle = green] (C) at (0:4cm) {$C$};

    % intersection points between circles A and B
    \path [name intersections={of = A and B}];
    \coordinate (AB1)  at (intersection-1);
    \coordinate (AB2)  at (intersection-2);

    % intersection points between circles B and C
    \path [name intersections={of = B and C}];
    \coordinate (BC1)  at (intersection-1);
    \coordinate (BC2)  at (intersection-2);

    % intersection points between circles A and C
    \path [name intersections={of = A and C}];
    \coordinate (AC1)  at (intersection-1);
    \coordinate (AC2)  at (intersection-2);

    % constructing path from AC1 to AC2 and calculating intersection point with circle B
    \path [name path=AC] (AC1)--(AC2);
    \path [name intersections={of = AC and B}];
    \coordinate (ACB1)  at (intersection-1);

    % calculate angles from center of A/B to intersection points
    \pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{AB2}{center}}
    \let\AABtwo\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{AC1}{center}}
    \let\AACone\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{B}{center}}{\pgfpointanchor{AB2}{center}}
    \let\BABtwo\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{B}{center}}{\pgfpointanchor{ACB1}{center}}
    \let\BACBone\pgfmathresult

    % calculate angles from center of B/C to intersection points
    \pgfmathanglebetweenpoints{\pgfpointanchor{B}{center}}{\pgfpointanchor{ACB1}{center}}
    \let\CACBone\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{B}{center}}{\pgfpointanchor{BC2}{center}}
    \let\BBCtwo\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{C}{center}}{\pgfpointanchor{AC1}{center}}
    \let\CACone\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{C}{center}}{\pgfpointanchor{BC2}{center}}
    \let\CBCtwo\pgfmathresult

    % calculate angles from center of A/C to intersection points
    \pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{AC1}{center}}
    \let\AACone\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{AC2}{center}}
    \let\AACtwo\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{C}{center}}{\pgfpointanchor{AC1}{center}}
    \let\CACone\pgfmathresult

    \pgfmathanglebetweenpoints{\pgfpointanchor{C}{center}}{\pgfpointanchor{AC2}{center}}
    \let\CACtwo\pgfmathresult

    % draw patterns
    \pattern[pattern=horizontal lines, pattern color=red]
    (AB2) arc[start angle=\AABtwo, end angle=\AACone,radius=3cm] -- (ACB1) --
    (ACB1) arc[start angle=\BACBone, end angle=\BABtwo,radius=3cm]; 

    \pattern[pattern=horizontal lines, , pattern color=blue]
    (BC2) arc[start angle=\BBCtwo, end angle=\BACBone,radius=3cm] -- (AC1)
    (AC1) arc[start angle=\CACone, end angle=\CBCtwo,radius=3cm];

    % draw separation line
    \draw [thick] (AC1)--(ACB1);

    % print annotations
  \node[left, fill=white, fill opacity=0.5, text opacity=1, inner sep=1.5pt]
    at (barycentric cs:A=1/2,B=1/2 ) {$A \cap B$}; 
  \node[below, fill=white, fill opacity=0.5, text opacity=1, inner sep=1.5pt]
    at (barycentric cs:A=1/2,C=1/2 ) {$A \cap C$};   
  \node[right, fill=white, fill opacity=0.5, text opacity=1, inner sep=1.5pt]
    at (barycentric cs:B=1/2,C=1/2 ) {$B \cap C$};   
  \node[below, fill=white, fill opacity=0.5, text opacity=1, inner sep=1.5pt]
    at (barycentric cs:A=1/3,B=1/3,C=1/3 ){$A \cap B \cap C$};
\end{tikzpicture}  
\end{document}

在此处输入图片描述

相关内容