我搜索过,但找不到与此问题足够接近的先前问题来找到答案。同时,这个问题似乎之前一定有人解决过,所以如果它是重复的,请原谅。
我想使用具有形状的节点来剪切路径(特别是圆形,但通用解决方案也很有用)。以下是示例:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\node [draw,circle,fill=white,minimum size=1mm] (u) at (0,0) {};
\node [draw,circle through=(u)] at (1,0) {};
\end{tikzpicture}
\end{document}
我希望红色圆圈被黑色圆圈截断,但至少黑色圆圈仍保留为一个节点。如果可能的话,我还想先指定黑色节点。
我猜想我可能需要一些后续操作之类的东西,但我还无法充分理解它们,因此无法解决它。
编辑:澄清一下,还有一些奇怪的事情
我想要的是类似这样的东西:
显然可以通过如下代码获得:
\begin{tikzpicture}
\node [circle,minimum size=5mm] (u) at (0,0) {};
\node [draw, circle through=(u),red] at (1,0) {};
\node [draw,circle,fill=white,minimum size=5mm] at (0,0) {};
\end{tikzpicture}
但这需要指定两次第一个节点。
这个用例是我已经完成的大量图表,vertex
对所有顶点节点使用一种样式,理想情况下,我只想编辑这种样式来执行反向剪辑。
最后,这个答案
此代码按预期工作
\begin{tikzpicture}[remember picture,overlay]
% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
]
\node [circle,minimum size=8mm] (u) at (0,0) {};
\coordinate (A) at (0,0);
\coordinate (B) at (1,0);
\coordinate (C) at (1,1);
\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
\path [clip,draw] (A) -- (B) -- (C) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
\draw [fill=red] (1,0) circle (1cm);
\end{tikzpicture}
但这并不
\begin{tikzpicture}[remember picture,overlay]
% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
]
\node [circle,minimum size=8mm] (u) at (0,0) {};
\coordinate (A) at (u.east);
\coordinate (B) at (u.south west);
\coordinate (C) at (u.north west);
\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
\path [clip,draw] (A) -- (B) -- (C) -- cycle [reverseclip];
\end{pgfinterruptboundingbox}
\draw [fill=red] (1,0) circle (1cm);
\end{tikzpicture}
这对我来说完全没有意义。第一个反向剪辑如预期的那样,第二个只是在顶部绘制一个实心圆,就好像根本没有发生剪辑一样。
答案1
尝试画小圆圈后较大的那个,所以它的填充将覆盖它里面的圆弧。基本上,你应该将一个放置\coordinate
在你想要它的中心的位置,然后相对于该点绘制两个圆。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\coordinate (u) at (0,0);
\node [draw,circle through=(u)] at (1,0) {};
\node [draw,circle,fill=white,minimum size=1mm] at (u) {};
\end{tikzpicture}
\end{document}
答案2
使用 reverseclip !(Werner 的建议和 Jake 的精彩回答)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,through}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
% A path that follows the edges of the current page
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
]
\node [draw,circle,fill=white,minimum size=6mm,inner sep=0pt] (u) at (0,0) {};
\begin{pgfinterruptboundingbox} % To make sure our clipping path does not mess up the placement of the picture
\path [clip] let \p1 = ($ (u.center) - (u.east) $) in circle ({veclen(\x1,\y1)})-- cycle [reverseclip];
\end{pgfinterruptboundingbox}
\node [draw,circle through=(u)] at (1,0) {};
\end{tikzpicture}
\end{document}
更新来自reverseclip
Jake 和 append after command
percusse
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,through}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
(current page.north east)}
]
\path[clip,draw] node [draw,circle,fill=white,minimum size=6mm,inner sep=0pt,
append after command={%
let \p1 = ($ (u.center) - (u.east) $) in circle ({veclen(\x1,\y1)})-- cycle
[reverseclip]}] (u) at (0,0) {};
\node [red,draw,circle through=(u)] at (1,0) {};
\end{tikzpicture}
\end{document}
答案3
这实际上不是一个合适的答案,更像是一条评论,但我没有声誉,因此暂时无法发表评论。此外,我意识到这是一个老问题,但这可能有助于避免我刚刚经历的困惑!
针对“使用的技术有些奇怪,这个答案“备注:我遇到了类似的现象,几个小时后变得越来越困惑,直到我最终明白了。当你为\path[clip]
,它要么限制(剪辑)到该区域之间要么忽略内环而将范围限制在外环所包围的整个区域。如果两个环的方向不同,则执行前者;如果两个环的方向相同,则执行后者。
我认为这是奇偶规则的反面例子:这里使用奇偶规则在两个圆之间进行剪辑,并且我认为在这种情况下这是必要的,因为两个循环都是使用创建的circle
,因此具有相同的方向(或者未分配方向;我不知道后台究竟发生了什么)。
答案4
这是一个通过backgrounds
TikZ 库实现的非常简单的解决方案:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{through,backgrounds}
\begin{document}
\begin{tikzpicture}
\node [draw,circle,fill=white,minimum size=1mm] (u) at (0,0) {};
\begin{scope}[on background layer]
\node [draw=red,circle through=(u)] at (1,0) {};
\end{scope}
\end{tikzpicture}
\end{document}