提问于:
浏览数:
2110
请教各位大佬,如何用tikz实现图中的迭代?
![](https://wenda.latexstudio.net/data/attach/210219/QvJJtc8o.png)
3 回答
1
直接用tikz试了一下,没有计算坐标,用foreach循环,效果上看可以实现一部分,点你再自己绘制:
```csharp
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage[active]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
\begin{document}
\newcommand{\diedai}[1]{\tikz{
\draw[thick,rotate=#1](-1,-1)rectangle(1,1);
}}
\begin{tikzpicture}
\foreach \R/\A in {1/0,0.72/30,0.52/60,0.375/90,0.27/120,0.195/150,0.141/180,0.102/210,0.0745/240,0.054/270}
{
\node[scale=\R] at (0,0){\diedai{\A}};
}
\end{tikzpicture}
\end{document}
```
这个效果:
![](https://wenda.latexstudio.net/data/attach/210220/WhHPqtXt.jpg)
0
```c
%\usepackage{tikz}
%\usetikzlibrary[calc]
\begin{tikzpicture}
\def\myiterationtimes{10}%迭代次数
\def\myrationum{0.3}%一个比例值
\path
coordinate (p01) at (1,1)
coordinate (p02) at (-1,1)
coordinate (p03) at (-1,-1)
coordinate (p04) at (1,-1)
\foreach \i [count=\j from 0] in {1,...,\myiterationtimes}
{
coordinate (p\i 1) at ($(p\j 1)!\myrationum!(p\j 2)$)
coordinate (p\i 2) at ($(p\j 2)!\myrationum!(p\j 3)$)
coordinate (p\i 3) at ($(p\j 3)!\myrationum!(p\j 4)$)
coordinate (p\i 4) at ($(p\j 4)!\myrationum!(p\j 1)$)
}
;
\foreach \i[evaluate={\k=1.2-\i/(\myiterationtimes+1);\h=1-\i/\myiterationtimes;}] in {0,...,\myiterationtimes}
{
\draw [line width=\h pt](p\i 1)--(p\i 2)--(p\i 3)--(p\i 4)--cycle;
\foreach \j in {1,...,4}
\fill[fill=red] (p\i \j)circle[radius=\k pt];
}
\end{tikzpicture}
```
效果是
![](https://wenda.latexstudio.net/data/attach/210221/ea4ZIA5z.PNG)
你的回答
请登录后回答
你的回答将会帮助更多人,请务必认真回答问题。