在 Tikz 中填充区域

在 Tikz 中填充区域

我有什么选择可以对如下所示的区域进行着色:

在此处输入图片描述

梅威瑟:

\documentclass[tikz, border=1cm]{standalone}
\begin{document}

\begin{tikzpicture}
\draw (0, 0) rectangle (12, 6);
\draw (3,3) circle [radius=3cm];
\draw (9,3) circle [radius=3cm];
\draw (0, 0)--(12,6);
\end{tikzpicture} 

\end{document}

答案1

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}
  \clip (0,0)--(12,6)--(12,0)--cycle; 
  \clip (3,0) rectangle (12,6);
  \fill[fill=red] (0,0) rectangle (12,6) (3,3) circle[radius=3cm] (9,3) circle[radius=3cm];
\end{scope}
\draw (0, 0) rectangle (12, 6);
\draw (3,3) circle [radius=3cm];
\draw (9,3) circle [radius=3cm];
\draw (0, 0)--(12,6);
\end{tikzpicture} 
\end{document}

在此处输入图片描述

答案2

这不是最优雅的解决方案,因为您必须在移动圆圈时调整剪辑区域,但我确信这可以改进(例如使用 calc 库)。

\documentclass[tikz, border=1cm]{standalone}
\begin{document}

    \begin{tikzpicture}
        \draw (0, 0) rectangle (12, 6);
        \draw (3,3) circle [radius=3cm];
        \draw (9,3) circle [radius=3cm];
        \draw (0, 0)--(12,6);
        \begin{scope}[even odd rule]
            % you have to adjust the following line when moving your circles around
            \clip  (3,0)    % bottom of first circle
                -- (6,3)    % intersection of circles
                -- (12,6)   % upper right corner
                -- (12,0)   % lower right corner
                -- cycle;
            \fill (3,3) circle [radius=3cm] (0, 0) -- (12,6) -- (12, 0) -- cycle (9,3) circle [radius=3cm];
        \end{scope}

    \end{tikzpicture}

\end{document}

这是预览

答案3

很接近:

\documentclass[tikz, border=1cm]{standalone}
\begin{document}

\begin{tikzpicture}
\draw[fill=black] (0,0) rectangle (12,6);
\draw[fill=white] (0,0) -- (12,6) -| cycle;
\draw[fill=white] (3,3) circle [radius=3cm];
\draw[fill=white] (9,3) circle [radius=3cm];
\draw (0, 0)--(12,6);
\end{tikzpicture}

\end{document}

在此处输入图片描述

靠近点:

\documentclass[tikz, border=1cm]{standalone}
\begin{document}

\begin{tikzpicture}
\draw[fill=black] (0,0) rectangle (12,6);
\fill[white] (0,0) -- (3,0) -- (3,3) -- cycle;
\draw[fill=white] (0,0) -- (12,6) -| cycle;
\draw[fill=white] (3,3) circle [radius=3cm];
\draw[fill=white] (9,3) circle [radius=3cm];
\draw (0, 0)--(12,6);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容