Unendliche Dreiecke (Koch-Schneeflocken) und Kombination zu einer Linie

Unendliche Dreiecke (Koch-Schneeflocken) und Kombination zu einer Linie

Ich habe versucht, das folgende Bild zu erzeugen:

Unendliche Dreiecke (leider kenne ich den offiziellen Namen dieser Folge nicht)

Ich habe jedenfalls versucht, eine Möglichkeit zu finden, dies zu erstellen und habe diesen Code von einem anderen Benutzer gefunden, also habe ich ihn wie folgt manipuliert:

\documentclass[11pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{asy}
\begin{document}
\begin{asy}
size(100);
pair t = dir(150);
int d = 0;

pair[] points = {t};

void forward(real dist) {
pair oldT = t;
t = oldT + dist*dir(d);
draw(oldT--t);
pair[] p = {t};
points.append(p);
}

void left(int angle) {
d = d + angle;
}

int[] angles = {60,-120,60,0};

void koch(int order, real size) {
if (order == 0) {
forward(size);
}
else {
for (int i = 0; i < angles.length; i += 1) {
koch(order-1, size/3);
left(angles[i]);
}
}
}

koch(0,sqrt(3));

void drawArray(pair[] arr) {
for (int i = 1; i<arr.length; i+=1) {
if (i == 1) {
draw(arr[0]--arr[1]);
}
else {
draw(arr[i-1]--arr[i]);
}
}
}

pair[] pointsLeft = new pair[points.length];
pair[] pointsRight = new pair[points.length];

for (int i = 0; i < points.length; i+=1) {
pointsLeft[i] = points[i] * dir(120);
pointsRight[i] = points[i] * dir(-120);
}

drawArray(pointsLeft);
drawArray(pointsRight);
\end{asy}

\begin{asy}
size(100);
pair t = dir(150);
int d = 0;

pair[] points = {t};

void forward(real dist) {
pair oldT = t;
t = oldT + dist*dir(d);
draw(oldT--t);
pair[] p = {t};
points.append(p);
}

void left(int angle) {
d = d + angle;
}

int[] angles = {60,-120,60,0};

void koch(int order, real size) {
if (order == 0) {
forward(size);
}
else {
for (int i = 0; i < angles.length; i += 1) {
koch(order-1, size/3);
left(angles[i]);
}
}
}

koch(1,sqrt(3));

void drawArray(pair[] arr) {
for (int i = 1; i<arr.length; i+=1) {
if (i == 1) {
draw(arr[0]--arr[1]);
}
else {
draw(arr[i-1]--arr[i]);
}
}
}

pair[] pointsLeft = new pair[points.length];
pair[] pointsRight = new pair[points.length];

for (int i = 0; i < points.length; i+=1) {
pointsLeft[i] = points[i] * dir(120);
pointsRight[i] = points[i] * dir(-120);
}

drawArray(pointsLeft);
drawArray(pointsRight);
\end{asy}

\begin{asy}
size(100);
pair t = dir(150);
int d = 0;

pair[] points = {t};

void forward(real dist) {
pair oldT = t;
t = oldT + dist*dir(d);
draw(oldT--t);
pair[] p = {t};
points.append(p);
}

void left(int angle) {
d = d + angle;
}

int[] angles = {60,-120,60,0};

void koch(int order, real size) {
if (order == 0) {
forward(size);
}
else {
for (int i = 0; i < angles.length; i += 1) {
koch(order-1, size/3);
left(angles[i]);
}
}
}

koch(2,sqrt(3));

void drawArray(pair[] arr) {
for (int i = 1; i<arr.length; i+=1) {
if (i == 1) {
draw(arr[0]--arr[1]);
}
else {
draw(arr[i-1]--arr[i]);
}
}
}

pair[] pointsLeft = new pair[points.length];
pair[] pointsRight = new pair[points.length];

for (int i = 0; i < points.length; i+=1) {
pointsLeft[i] = points[i] * dir(120);
pointsRight[i] = points[i] * dir(-120);
}

drawArray(pointsLeft);
drawArray(pointsRight);
\end{asy}
\begin{document}

Ich habe dies erhalten (der rosa/orange Hintergrund stammt von einem Textfeld):

Meine Arbeit

Ich würde gerne wissen, wie man diese drei Figuren zu einer Linie mit angemessenem Abstand kombiniert, und das $P_n$ darunter sowie die $\cdots$ rechts, obwohl das nicht so notwendig ist. Danke!

Antwort1

Noch eine Alternative:

// Koch.asy
//    run `asy Koch.asy`
//    to get a standalone  `Koch.pdf`

settings.tex="pdflatex";
import fontsize;defaultpen(fontsize(7.5pt));
texpreamble("\usepackage{lmodern}"
   +"\usepackage{amsmath}"
   +"\usepackage{amsfonts}"
   +"\usepackage{amssymb}"
);

guide gKoch(int n, pair A, pair B){
  guide g;
  pair C,D,E;
  if(n>0){
    C=A+(B-A)/3; E=B+(A-B)/3;
    D=rotate(-60,C)*E;
    g=gKoch(n-1,A,C)--gKoch(n-1,C,D)--gKoch(n-1,D,E)--gKoch(n-1,E,B);
  }else{
    g=A--B;
  }
  return g;
}

guide KochFlake(int n, pair A, pair B, pair C){
  return gKoch(n,A,B)--gKoch(n,B,C)--gKoch(n,C,A)--cycle;
}

int nMax=6; 

pen linePen=darkblue+0.3bp;

pair A,B,C,D;
real a=1;
A=(0,a); D=(0,-a);
B=rotate( 120)*A; C=rotate(-120)*A;

transform sh=identity();
for(int i=0;i<nMax;++i){
  draw(sh*KochFlake(i,A,B,C),linePen);
  label("$P_{"+string(i)+"}$",sh*D,plain.S);
  sh*=shift(2*a,0);
}

size(nMax*3*a*cm,2*a*cm);

Bildbeschreibung hier eingeben


Aktualisieren

Dies ist die Inline-Version:

\documentclass[12pt]{article}
\usepackage[inline]{asymptote}

\title{2D Graphics with Asymptote}
\author{The Asymptote Project}
\begin{document}
\maketitle

\begin{asydef}
//
// Global Asymptote definitions can be put here.
//
    import fontsize;defaultpen(fontsize(7.5pt));
    texpreamble("\usepackage{lmodern}"
       +"\usepackage{amsmath}"
       +"\usepackage{amsfonts}"
       +"\usepackage{amssymb}"
    );

    guide gKoch(int n, pair A, pair B){
      guide g;
      pair C,D,E;
      if(n>0){
        C=A+(B-A)/3; E=B+(A-B)/3;
        D=rotate(-60,C)*E;
        g=gKoch(n-1,A,C)--gKoch(n-1,C,D)--gKoch(n-1,D,E)--gKoch(n-1,E,B);
      }else{
        g=A--B;
      }
      return g;
    }
    
    guide KochFlake(int n, pair A, pair B, pair C){
      return gKoch(n,A,B)--gKoch(n,B,C)--gKoch(n,C,A)--cycle;
    }
    
    pen linePen=darkblue+0.3bp;
    
    void KochFlakesDiagram(int nFirst=0, int nLast){
      pair A,B,C,D;
      real a=1;
      A=(0,a); D=(0,-a);
      B=rotate( 120)*A; C=rotate(-120)*A;
    
      transform sh=identity();
    
      for(int i=nFirst;i<=nLast;++i){
        draw(sh*KochFlake(i,A,B,C),linePen);
        label("$P_{"+string(i)+"}$",sh*D,plain.S);
        sh*=shift(2*a,0);
      }
      size((nLast-nFirst)*3*a*cm,2*a*cm);
    }

\end{asydef}

Here is a Koch flakes diagram produced with Asymptote

\begin{center}
\begin{asy}
KochFlakesDiagram(0,3);
\end{asy}
\end{center}

\begin{center}
\begin{asy}
KochFlakesDiagram(4,7);
\end{asy}
\end{center}

\end{document}

Bildbeschreibung hier eingeben

Antwort2

Mit

\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}

Bildbeschreibung hier eingeben

%\documentclass[tikz, border=5pt]{standalone}
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}

\def\a{3.14}

\pgfmathsetmacro\p{2*sqrt(3)/3+0.3}
\tikzset{koch/.style={
insert path={%
 lindenmayer system[very thin, fill=lightgray,
l-system={  rule set={F -> F-F++F-F},  axiom=F++F++F,
step=\a cm/3^#1, angle=60, order=#1,  
anchor=center 
}] -- cycle node[below=0.6*\a cm]{$P_{#1}$}
}    }   }

\begin{document}
%\tikz \draw[] (0,0) [koch=7]; 

\begin{tikzpicture}
\begin{groupplot}[group style={group size=3 by 99,
vertical sep=\p cm, %horizontal sep=5mm, 
}, 
height=1.5*\a cm, width=1.5*\a cm, clip=false, hide axis, 
]
\pgfplotsforeachungrouped \n in {0,...,6}{%%
\edef\tmp{
        \noexpand\nextgroupplot%[title=\x]
        \noexpand\addplot[draw=none] coordinates {(0,0)  (\a,\a)};
        \noexpand\draw[] (0.5*\a,0.5*\a) [koch=\n]; 
}\tmp}%%
\nextgroupplot
\addplot[draw=none] coordinates {(0,0)  (\a,\a)};
\node[font=\Huge] at (0.5*\a,0.5*\a) {\dots}; 
\end{groupplot}
\end{tikzpicture}
\end{document}

verwandte Informationen