如何填充 tikz 中的区域

如何填充 tikz 中的区域

我在 Tikz 中绘制了以下图形:

梅威瑟:

\documentclass[border=5pt,tikz] {standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[thick] (-0.25,0) circle (2);
        \draw[thick] (0.25,0) circle (2);
        \draw (0.25,0) node[above] {$w$};
        \draw (-0.25,0) node[above] {$z$};
        \draw (0.25,0) node {$\bullet$};
        \draw (-0.25,0) node {$\bullet$};
        \draw (2,0) node {$B$};
        \draw (-2,0) node {$A$};
    \end{tikzpicture}
\end{document}

我想用浅灰色填充 A 和 B 区域。我知道如何填充整个圆圈,但不知道如何填充如此特定的区域。最好的方法是什么?

答案1

除了@current_user的回复之外,我们还可以使用even odd rule此处的颜色来标记部分里面一条路径。

这里描绘的路径是两个中心圆的连续zw

\filldraw[thick,fill=green!50,even odd rule] (-0.25,0) circle (2) (0.25,0) circle (2);

为了解释这条规则,我添加了两个箭头,一个是起点z和终点z',另一个是。Bb'这些箭头表示它们的起点z和终点是否B里面或者外部所追踪的路径。它们总是追踪到无穷远。

从点出发z,箭头与路径相交两次,两次是甚至,所以z重点是外部该路径以及其所在的区域均未着色。

从点开始B,箭头与路径相交一次,一个是奇怪的B所以里面路径,因此是彩色的。

奇偶规则

\documentclass[border=5mm,tikz] {standalone}
\begin{document}
    \begin{tikzpicture}
        \filldraw[thick,fill=green!50,even odd rule] (-0.25,0) circle (2) (0.25,0) circle (2);
        \draw (0.25,0) node[above] {$w$};
        \draw (-0.25,0) coordinate (z) node[above] {$z$};
        \draw (0.25,0) node {$\bullet$};
        \draw (-0.25,0) node {$\bullet$};
        \draw (2,0) node {$B$};
        \draw (-2,0) node {$A$};
        %drawing arrows to explain the even odd rule
        \coordinate(z') at (-2.5,.5);
        \draw[->](z)--(z')node[left]{z'};
        \coordinate (b) at (2,.25);
        \coordinate (b') at (2.5,1);
        \draw[->](b)node{$\bullet$}--(b')node[above right]{b'};
    \end{tikzpicture}
\end{document}

使用 www.DeepL.com/Translator 翻译

答案2

\documentclass[border=5pt,tikz]{standalone}
\tikzstyle{io} = [fill=black,inner sep=2pt,circle]
\begin{document}
    \begin{tikzpicture}
        \begin{scope}
            \clip (.5,0) circle(2);
                \fill[gray!20] (.25,-5) rectangle (-5,5);
        \end{scope}
        \begin{scope}
            \clip (0,0) circle(2);
                \fill[gray!20] (.25,-5) rectangle (5,5);
        \end{scope}
        \draw (0,0) circle(2);
        \draw (.5,0) circle(2);
            \node[right] at (-2,0) {$A$};
            \node[left] at (2.5,0) {$B$};
        \node[io,label={$z$}] at (0,0) {};
        \node[io,label={$w$}] at (.5,0) {};
    \end{tikzpicture}
\end{document}

截屏

相关内容