我想要绘制所谓的 Cantor 目标:
我开始“手动”绘制许多圆圈,但花费的时间太长了。该集合是通过取中间第三个康托集合构建的:并以端点为枢轴,绕轴旋转 360 度。
有没有办法做到这一点,而不需要看似无穷无尽的圆圈?
先感谢您。
我对中间三分之一康托尔的代码
\documentclass{article}
\usetikzlibrary{decorations.fractals,math}
\begin{document}
\begin{tikzpicture}[decoration=Cantor set]
\draw (0,0) -- (7,0) node[right] {$E_{0}$};
\draw decorate{ (0,-1) -- (7,-1)} node[right] {$E_{1}$};
\draw decorate{ decorate{ (0,-2) -- (7,-2)}} node[right] {$E_{2}$};
\draw decorate{ decorate{ decorate{ (0,-3) -- (7,-3)}}} node[right] {$E_{3}$};
\draw decorate{ decorate{ decorate{ decorate{ (0,-4) -- (7,-4)}}}} node[right] {$E_{4}$};
\end{tikzpicture}
\end{document}
答案1
这将迭代原始图形,每次迭代旋转给定角度。循环次数越多,近似值就越接近。我每度使用 1 次迭代,因此 360 次循环。增加此数字将提高质量,但会降低编译速度。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}
[
decoration=Cantor set,
deco/.pic={
\draw [pic actions] (0,0) -- (7,0) node[right] {$E_{0}$};
\draw [pic actions] decorate{ (0,-1) -- (7,-1)} node[right] {$E_{1}$};
\draw [pic actions] decorate{ decorate{ (0,-2) -- (7,-2)}} node[right] {$E_{2}$};
\draw [pic actions] decorate{ decorate{ decorate{ (0,-3) -- (7,-3)}}} node[right] {$E_{3}$};
\draw [pic actions] decorate{ decorate{ decorate{ decorate{ (0,-4) -- (7,-4)}}}} coordinate [midway] (#1) node[right] {$E_{4}$};
}
]
\pic [blue] {deco=a};
\foreach \i [evaluate=\i as \j using {int(\i/3.6)} ] in {1,...,359} \pic [blue!\j!magenta, rotate around={\i:(a)}] {deco};
\end{tikzpicture}
\end{document}
编辑
但是,我怀疑您实际上只想迭代手册中的最后一行代码。如果您还删除了节点,那么这将近似于同心圆:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}
[
decoration=Cantor set,
deco/.pic={
\draw [pic actions] decorate{ decorate{ decorate{ decorate{ (0,0) -- (7,0)}}}} coordinate [midway] (#1);
}
]
\pic [blue] {deco=a};
\foreach \i [evaluate=\i as \j using {int(\i/3.6)} ] in {.5,1,1.5,...,359.5} \pic [blue!\j!magenta, rotate around={\i:(a)}] {deco};
\end{tikzpicture}
\end{document}
毫无疑问还有更有效的方法!
答案2
我猜是这样的
\documentclass[border=9,tikz]{standalone}
\begin{document}
\tikz{
\draw[line width=729]circle(729/2pt);
\draw[white,line width=243]circle(729/2pt);
\draw[white,line width=81]circle(243*.5pt)circle(243*2.5pt);
\draw[white,line width=27]circle(81*.5pt)circle(81*2.5pt)circle(81*6.5pt)circle(81*8.5pt);
\draw[white,line width=9]circle(27* .5pt)circle(27* 2.5pt)circle(27* 6.5pt)circle(27* 8.5pt)
circle(27*18.5pt)circle(27*20.5pt)circle(27*24.5pt)circle(27*26.5pt);
}
\end{document}
方法 2
\documentclass[border=9,tikz]{standalone}
\begin{document}
\def\drawwhite#10;{
\ifnum1#1=1\else
\draw[white,line width=\a]circle(\b/4pt);
{\pgfmathsetmacro\a{\a-\b}\pgfmathsetmacro\b{\b/3}\drawwhite#1;}
{\pgfmathsetmacro\a{\a+\b}\pgfmathsetmacro\b{\b/3}\drawwhite#1;}
\fi
}
\tikz{
\pgfmathsetmacro\a{243}
\pgfmathsetmacro\b{2*\a/3}
\draw[line width=\a]circle(\a/2pt);
\drawwhite00000000;
}
\end{document}
如果愿意的话,可以继续添加 0。