2

I'm trying to build a large inverted tree structure in Tikz, like the one below (except much larger, and ideally recursive):

enter image description here

In this tree structure, each 'line' is made up of three nodes, and each of those nodes will have a parent which is the bottom node in another line.

Is it possible to write this recursively in such a way that I can easily change the amount of nodes per line (at the moment this is 3) and the maximum amount of lines (at the moment this is 5)?

I manually generated the above diagram using the code below:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[every node/.style={draw,shape=circle,fill=black}]

\node[fill=red] (A) at (0,0) {};
\node[fill=red] (B) at (0,1) {};
\node[fill=red] (C) at (0,2) {};

\draw (A) -- (B) (B) -- (C);

\node (D) at (2,1) {};
\node (E) at (2,2) {};
\node (F) at (2,3) {};

\draw (A) -- (D) (D) -- (E) (E) -- (F);

\node (G) at (-1,2) {};
\node (H) at (-1,3) {};
\node (I) at (-1,4) {};

\draw (B) -- (G) (G) -- (H) (H) -- (I);

\node (J) at (1,3) {};
\node (K) at (1,4) {};
\node (L) at (1,5) {};

\draw (C) -- (J) (J) -- (K) (K) -- (L);

\node (M) at (-2,3) {};
\node (N) at (-2,4) {};
\node (O) at (-2,5) {};

\draw (G) -- (M) (M) -- (N) (N) -- (O);

\end{tikzpicture}
\end{document}
  • Welcome! But each of those nodes will have a parent which is the bottom node in another line? Surely not! – cfr Apr 01 '16 at 10:38
  • The thing is: the number of lines does not determine the structure of the tree. How does TikZ (or anything else) know which 5 groups of 3 to draw? This would be true even if the trees obeyed the rule you gave which the tree you show does not. – cfr Apr 01 '16 at 10:43
  • You can check this question to see how you can draw recursively a tree. – Kpym Apr 01 '16 at 19:48
  • @Kpym Did you link to the wrong question? There are plenty of relevant questions around, but that doesn't seem to be one of them! Of course, I may have misunderstood the question. (And it is certainly true that fractals are recursive. And I'm not really sure how these are supposed to work. So maybe you're right.) – cfr Apr 02 '16 at 02:15
  • @cfr in the question of my link these are trees (of a free group). They are not fractals. Their boundary looks like a fractal. I think that all the methods their could be adapted to draw the kind of tree asked in this question. But I agree their is a work to do ;) – Kpym Apr 02 '16 at 05:40
  • @Kpym Oh. The manual describes L-systems as producing 'fractal patterns'. – cfr Apr 02 '16 at 13:12
  • @cfr 'fractal patterns' = 'self repeating patterns' (this is the case here). But these trees are not fractals in the mathematical sens. – Kpym Apr 02 '16 at 13:23
  • @Kpym I don't know much about it. However, I was surprised these counted as fractals so it makes perfect sense if they are fractal-ish rather than fractals proper. But I don't see how these trees can be drawn that way because there's no obvious algorithm. Why 2 steps from the second red node but only 1 from the first, for example? Is there a rule? Because the one in the question doesn't appear to make sense: all the red nodes have branches off and not just the bottom one, for instance. – cfr Apr 02 '16 at 13:47
  • @cfr you are right : the image is not exactly what is described in the question. if you stop at "level 1", there should be no the left most one; if you stop at "level 2" there are plenty others. The rule is : every segment has n vertices from every vertex "grows" a tree similar to the parent ... – Kpym Apr 02 '16 at 16:26
  • @Kpym But it doesn't specify the order in which things grow from the vertices. Why isn't the left-most line of 3 on the far right? Or in the middle? You draw 1. Then 1 from each of that one's vertices: 2, 3, 4. But where does 5 grow from? – cfr Dec 07 '16 at 03:58
  • @cfr I think that the tree is "incomplete" : the most left one is the only one of the level 2, the other three black are forming the level 1, and the red one is the level 0 (the root). The level n should be of size 3^n, so 8 "triple nodes" are missing in level 2. – Kpym Dec 08 '16 at 22:49
  • @Kpym But then 5 is not a valid number of lines, as suggested in the question? – cfr Dec 08 '16 at 23:28

0 Answers0