如何剪切具有多种形状(圆形)的矩形?

如何剪切具有多种形状(圆形)的矩形?

如何用多个形状(圆形)裁剪矩形?我需要创建一个复杂的维恩图,并需要用多个圆形组合的形状裁剪外部矩形。不知道怎么做。不过我可以用一个圆形来做,

\documentclass{minimal}

\usepackage{graphicx, tikz}

\begin{document}

\def\Space{(-5,-5) rectangle (5,5)}
\def\Item{(-1.9,0.62) circle (2.5cm)}

\begin{tikzpicture}
    \begin{scope}[shift={(3cm,-5cm)}, fill opacity=1.0]
        \fill [orange, even odd rule] \Space \Item;
    \end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

您可以使用保罗·加博瑞特invclip风格为此,每个圆使用一个剪切路径:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\tikzset{
    invclip/.style={
        clip,
        insert path={{[reset cm](-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)}}
    }
}

\begin{tikzpicture}

\begin{scope}
    \begin{pgfinterruptboundingbox}
        \path [invclip] (0,0) circle [radius=1cm];
        \path [invclip] (1,0.5) circle [radius=0.8cm];
        \path [invclip] (1.2,-0.3) circle [radius=0.8cm];
    \end{pgfinterruptboundingbox}
    \fill [orange] (-1.5,-1.5) rectangle (2.5,1.5);
\end{scope}
\end{tikzpicture}

\end{document}

答案2

这是另一种选择,(\x,\y)通过在圆半径中引入新变量 \z 可以改变圆半径。

在此处输入图片描述

代码

\documentclass[]{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=2]
\fill[orange] (-1.2,-1.2) rectangle (1.4,1.4);
\begin{scope}
\foreach \x/\y in {0/0.5, -0.3/0, 0.3/0}
{
\filldraw[yellow,opacity=0.5] (\x,\y) circle (0.5 cm);
}
\end{scope}
\node at (0,0.2) {A};
\end{tikzpicture}

答案3

我不太确定你的问题,但如果它的意思是“如何在几个圆圈后面绘制一个背景矩形?”,那么你还有另一种选择。在这种情况下,你不需要为矩形固定先前的大小。

\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}

\begin{tikzpicture}[execute at end picture=%
{
\begin{pgfonlayer}{background}
\path[fill=orange]
([shift={(-1mm,-1mm)}]current bounding box.south west) rectangle
([shift={(1mm,1mm)}]current bounding box.north east);
\end{pgfonlayer}
}]
    \fill[white] (0,0) circle [radius=1cm];
    \fill[white] (1,0.5) circle [radius=0.8cm];
    \fill[white] (1.2,-0.3) circle [radius=0.8cm];

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案4

感谢您帮助我找到软件包中的错误。修复程序以 V3.21 形式发布后,MWE 可以简单到

\documentclass{article}
\usepackage{stackengine}
\usepackage{xcolor}
\usepackage{graphicx}

\begin{document}
{\color{white}%
\stackinset{l}{.5cm}{b}{1.8cm}{\scalebox{15}{$\bullet$}}{%
\stackinset{l}{1.5cm}{b}{2cm}{\scalebox{15}{$\bullet$}}{%
\stackinset{l}{1.2cm}{b}{0.8cm}{\scalebox{15}{$\bullet$}}{%
\textcolor{orange}{\rule{5cm}{5cm}}%
}%
}}}
\end{document}

但与此同时,直到修复被传播之前,这里是使用该stackengine包的 MWE:

\documentclass{article}
\usepackage{stackengine}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{etoolbox}
\makeatletter
%\stackinset{l/c/r}{x}{b/c/t}{y}{inset}{anchor}
\renewcommand*\stackinset[6]{%
  \def\conditioned@inset{\stack@delim#5\stack@delim}%
  \def\conditioned@anchor{\stack@delim#6\stack@delim}%
  \ifstrequal{#4}{}%
    {\setlength{\stack@tmplength}{0pt}}%
    {\setlength{\stack@tmplength}{#4}}%
  \if c#3%
    \setlength{\temp@stkl}{%
      \heightof{\conditioned@anchor}+\depthof{\conditioned@anchor}%
      -\heightof{\conditioned@inset}-\depthof{\conditioned@inset}}%
    \addtolength{\stack@tmplength}{.5\temp@stkl}%
  \fi%
  \ifstrequal{#2}{}{\def\stack@tmp{0pt}}{\def\stack@tmp{#2}}%
  \def\stack@lroffset{\rule{\stack@tmp}{0pt}}%
  \addtolength{\stack@tmplength}{%
    \heightof{\conditioned@inset}+\depthof{\conditioned@inset}}%
  \if c#1%
    \def\conditioned@inset{\stack@lroffset\stack@lroffset#5}%
  \else%
    \def\conditioned@inset{\stack@lroffset#5\stack@lroffset}%
  \fi%
  \stackengine{-\stack@tmplength}{#6}{\conditioned@inset}%
              {\inset@valign{#3}}{#1}{\quietstack}{T}{S}%
}
\makeatother
\begin{document}
{\color{white}%
\stackinset{l}{.5cm}{b}{1.8cm}{\scalebox{15}{$\bullet$}}{%
\stackinset{l}{1.5cm}{b}{2cm}{\scalebox{15}{$\bullet$}}{%
\stackinset{l}{1.2cm}{b}{0.8cm}{\scalebox{15}{$\bullet$}}{%
\textcolor{orange}{\rule{5cm}{5cm}}%
}%
}}}
\end{document}

在此处输入图片描述

相关内容