![`clip` 可以去除这个 tikzpicture 的外边框吗?](https://linux22.com/image/389662/%60clip%60%20%E5%8F%AF%E4%BB%A5%E5%8E%BB%E9%99%A4%E8%BF%99%E4%B8%AA%20tikzpicture%20%E7%9A%84%E5%A4%96%E8%BE%B9%E6%A1%86%E5%90%97%EF%BC%9F.png)
我借用了一些代码这一页并对其进行了稍微的修改,得到如下结果:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (0,0) circle (3cm);
\draw (0,0) circle (3cm);
\end{scope}
\coordinate (a) at (90:3);
\coordinate (b) at (-30:3);
\coordinate (c) at (210:3);
\foreach \in in {1,2,...,4}
{
\node[circle through=(a),draw] {};
\draw (a)--(b)--(c)--cycle;
\coordinate(aux) at (a);
\path (a)--(b) coordinate[pos=.5] (a);
\path (b)--(c) coordinate[pos=.5] (b);
\path (c)--(aux) coordinate[pos=.5] (c);
}
\end{tikzpicture}
\end{document}
得出的结果是:
我希望去掉最外层的圆;因此进行了范围界定和裁剪。但这没有奏效。我还尝试将命令放在命令clip
后面draw
,并向环境添加一个clip
选项scope
。有没有办法clip
做我想做的事情?(看起来有一种方法可以从三角形开始,然后从那里计算,就像这次讨论,但我希望避免这种程度的复杂化。
答案1
此代码覆盖节点并重绘圆圈。最小的手术可能是
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (90:3);
\coordinate (b) at (-30:3);
\coordinate (c) at (210:3);
\foreach \in in {1,2,...,4}
{
\ifnum\in=1
\else
\node[circle through=(a),draw] {};
\fi
\draw (a)--(b)--(c)--cycle;
\coordinate(aux) at (a);
\path (a)--(b) coordinate[pos=.5] (a);
\path (b)--(c) coordinate[pos=.5] (b);
\path (c)--(aux) coordinate[pos=.5] (c);
}
\end{tikzpicture}
\end{document}
答案2
在循环中,首先绘制圆圈,(在循环的开始处)(a)
然后用 重新定义点\coordinate(aux) at (a);
,因此在循环的末尾而不是开头绘制圆就足够了。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (0,0) circle (3cm);
%\draw (0,0) circle (3cm);
\end{scope}
\coordinate (a) at (90:3);
\coordinate (b) at (-30:3);
\coordinate (c) at (210:3);
\foreach \in in {1,2,...,4}
{
%\node[circle through=(a),draw] {};
\draw (a)--(b)--(c)--cycle;
\coordinate(aux) at (a);
\path (a)--(b) coordinate[pos=.5] (a);
\path (b)--(c) coordinate[pos=.5] (b);
\path (c)--(aux) coordinate[pos=.5] (c);
\node[circle through=(a),draw] {};% draw the circle at the end
}
\end{tikzpicture}
\end{document}
答案3
- 将最外面的三角形放在循环之外
- 减少迭代次数
- 循环首先计算新坐标 (a)、(b) 和 (c)
!
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (90:3);
\coordinate (b) at (-30:3);
\coordinate (c) at (210:3);
\draw(a)--(b)--(c)--cycle;
\foreach \in in {1,2,...,3}
{
\coordinate(aux) at (a);
\path (a)--(b) coordinate[pos=.5] (a);
\path (b)--(c) coordinate[pos=.5] (b);
\path (c)--(aux) coordinate[pos=.5] (c);
\node[circle through=(a),draw] {};
\draw (a)--(b)--(c)--cycle;
}
\end{tikzpicture}
\end{document}