在 Tikz 中裁切橢圓以適合其他形狀

在 Tikz 中裁切橢圓以適合其他形狀

假設我有兩個形狀,並且我想添加一個圓形形狀(如ellipse)。如何裁切這個橢圓形,使其適合其他形狀,如下圖所示?不過,我不想在形狀周圍添加白色邊框,因為我想保持空白空間透明。

在此輸入影像描述

微量元素:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\fill  (-4,2) rectangle (-1,1.5);
\fill  (-3.5,1.25) rectangle (-0.5,0.75);
\fill  (-1.6,1.35) ellipse (0.3);
\end{tikzpicture}
\end{document}

編輯:由於上面範例中的矩形形狀可能有點過於具體,因此我想給出一個更複雜的範例來說明我想要實現的目標;這次有更複雜的形狀重疊我的ellipse

在此輸入影像描述

答案1

\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\pattern[pattern=checkerboard,pattern color=black!30] (-5,0) rectangle (0,3);
\newcommand{\myspace}{0.5}
\fill  (-4,2) rectangle (-1,1.5);
\fill  (-3.5,1.25) rectangle (-0.5,0.75);
\clip ([yshift=\myspace] -2,1.25) rectangle ([yshift=-\myspace] -1,1.5);
\fill  (-1.6,1.35) ellipse (0.3);
\end{tikzpicture}
\end{document}

棋盤圖案上的形狀

編輯:這是使用以下方法實作更新問題的一種方法tikzfadingfrompicture

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings, patterns}
\begin{tikzfadingfrompicture}[name=myfading]
\draw[draw=transparent!100, ultra thick, fill=transparent!0] (0,0) circle[radius=1];
\draw[draw=transparent!100, ultra thick, fill=transparent!0] (-2,-1) -- (0,0) -- (-1,2.5) -- (-2,2) -- cycle;
\draw[draw=transparent!100, ultra thick, fill=transparent!0] (0,1) ellipse [x radius=0.5, y radius=0.8];
\draw[draw=transparent!100, ultra thick, fill=transparent!0] (0.2,-0.5) -- (1,1.5) -- (2,-0.5) -- cycle;
\draw (0,0) circle[radius=10]; %encompassing circle for alignment 
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\pattern[pattern=checkerboard,pattern color=black!30] (-3,-3) rectangle (3,3);
\fill[path fading=myfading, fit fading=false] (-3,-3) rectangle (3,3);
\end{tikzpicture}
\end{document}

棋盤上的形狀

相關內容