在 Adobe Illustrator 中,使用 Pathfinder 创建复合形状非常容易(使用路径排除功能,在后层保留形状,在上层删除所有路径):
显然,我们可以使用基本的剪辑应用程序来尝试使用 Tikz 重新创建此图像,如果我们不关心绘制边框的话,这种方法可以很好地工作:
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% \clip (0,0) circle (1);
\fill[red!20] (0,0) circle (1);
\begin{scope}[rotate=-60]
\fill[white] (0,-0.1) rectangle (1.5,0.1);
\end{scope}
\begin{scope}[rotate=-120]
\fill[white] (0,-0.1) rectangle (1.5,0.1);
\end{scope}
\fill[white] (-1.5,-0.1) rectangle (1.5,0.1);
\end{tikzpicture}
\end{document}
然而,如果我们关心绘制边框,然后它变得更加有趣,并且无法轻松实现所需的解决方案。 最好的尝试,但存在一堆问题(考虑剪辑上的线宽(目前它会切入线)和排除区域中的重叠线)。
\documentclass[12pt,tikz, border = 1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\clip (0,0) circle (1);
\filldraw[fill=red!10,draw=blue] (0,0) circle (1);
\begin{scope}[rotate=-60]
\filldraw[anchor=east,fill=white,draw=blue] (0,-0.1) rectangle (1.5,0.1);
\end{scope}
\begin{scope}[rotate=-120]
\filldraw[anchor=east,fill=white,draw=blue] (0,-0.1) rectangle (1.5,0.1);
\end{scope}
\filldraw[fill=white,draw=blue] (-1.5,-0.1) rectangle (1.5,0.1);
\end{tikzpicture}
\end{document}
有没有办法让我们使用 TikZ 实现所需的结果(第一张图像,第二个圆圈,排除区域但可以绘制)?我们是否可以通过剪切路径,然后填充该路径来实现这一点,但同时还可以绘制该路径?
答案1
这个spath3
库非常强大,非常适合这个问题。但在这种特殊情况下,我们可以通过使用双线来获得类似的结果,如下所示:
\documentclass[tikz,border=7pt]{standalone}
\begin{document}
\begin{tikzpicture}
\clip[postaction={fill=red!20, draw=blue, thick}]
(0,0) circle (1cm)
;
\path[draw=blue, double, double distance=2mm]
(-2,0) -- (2,0)
(0,0) -- (-60:2)
(0,0) -- (-120:2)
;
\end{tikzpicture}
\end{document}
答案2
spath3
这是使用Ti 的可能性钾Z 库并按照 Andrew Stacey 的出色回答中的步骤进行操作这里。代码不是很短,但重复性强且易于理解(我希望)。我们需要创建路径(圆形和矩形),在交叉点处分割它们,然后使用适当的组件绘制所需的图形
像这样:
\documentclass[tikz]{standalone}
\usetikzlibrary{intersections,spath3}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
\useasboundingbox (-1.2,-1.2) rectangle (1.2,1.2);
% original paths, not drawn
\path[spath/save=circle] (0,0) circle (1);
\path[rotate=240,spath/save=rect24] (0,-0.1) rectangle (1.5,0.1);
\path[rotate=300,spath/save=rect30] (0,-0.1) rectangle (1.5,0.1);
\path[spath/save=rect00] (-1.5,-0.1) rectangle (1.5,0.1);
% spath3 operations
\tikzset
{% Circles have an "empty" component at the start which
% moves from the centre to the rim; it can be irritating
% when trying to count components later so this removes
% any empty components
spath/remove empty components={circle},
% Now split each path where it intersects with the lines
spath/split at intersections={circle}{rect00},
spath/split at intersections={circle}{rect24},
spath/split at intersections={circle}{rect30},
spath/split at intersections={rect00}{rect24},
spath/split at intersections={rect00}{rect30},
spath/split at intersections={rect24}{rect30},
% Each path is now a collection of components; to work
% with them individually we split them into a list of
% separate paths which is stored in a macro
spath/get components of={circle}\Ccpts,
spath/get components of={rect00}\Rcpts,
spath/get components of={rect24}\Scpts,
spath/get components of={rect30}\Tcpts,
}
\draw[fill=red!10,draw=blue,
spath/use=\getComponentOf\Ccpts{1},
spath/use={\getComponentOf\Rcpts{2},weld}
];
\draw[fill=red!10,draw=blue,
spath/use=\getComponentOf\Ccpts{3},
spath/use={\getComponentOf\Scpts{3},weld},
spath/use={\getComponentOf\Rcpts{8},weld},
];
\draw[fill=red!10,draw=blue,
spath/use=\getComponentOf\Ccpts{5},
spath/use={\getComponentOf\Tcpts{3},weld},
spath/use={\getComponentOf\Scpts{7},weld}
];
\draw[fill=red!10,draw=blue,
spath/use=\getComponentOf\Ccpts{7},
spath/use={\getComponentOf\Rcpts{4},weld},
spath/use={\getComponentOf\Tcpts{7},weld}
];
\end{tikzpicture}
\end{document}
评论:可以使用该选项绘制每个扇区的最后一条(直线)cycle
,但我这样做是为了查看spath3
库的运行情况。