![裁剪椭圆以适合 Tikz 中的其他形状](https://linux22.com/image/449837/%E8%A3%81%E5%89%AA%E6%A4%AD%E5%9C%86%E4%BB%A5%E9%80%82%E5%90%88%20Tikz%20%E4%B8%AD%E7%9A%84%E5%85%B6%E4%BB%96%E5%BD%A2%E7%8A%B6.png)
假设我有两个形状,我想添加一个圆形(如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}