自訂維恩圖

自訂維恩圖

對於我的工作,我需要一個包含三個圓圈的維恩圖,並且相交的圓圈被一條線分成兩部分。在此輸入影像描述

我使用了 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}

在此輸入影像描述

相關內容