Bi(tri, quad)furcating lines (without iteration)

This was fun to figure out :slight_smile:

It’s for generating 2D branching patterns, with no looping - just simple maths, repeating data and a clever bit mask method to untangle overlapping lines. Everything fits in a 1x1 square (or adjust X/Y to suit) ready for sporphing or whatever. Doesn’t even have to be a grid really, so long as you present a list of coordinates that make sense read from left to right.

The branching controls are a sequence of numbers, which say how many branches there are at that level of the tree. So 1,1,2 means

Start with 1 root
Add 1 trunk
Split in 2
= 1x1x2 leaves

2,2,3 means

Start with 2 roots
Branch in 2
Branch in 3
= 2x2x3 = 12 leaves

While 3,2,3,1,3,1,4,2,3
= 3x2x3x1x3x1x4x2x3 = 1296 leaves
Mass Multiplication gets big fast, so be careful!

There’s two output types:

  1. A polyline for each leaf to its root, from left to right. They overlap.
  2. A polyline from each leaf to its root, or a preceding polyline, whichever comes first. This eliminates overlaps.

The 2nd type works great for Multipipe, Here NodeSize is proportional to 1/(no of branches at that level)

Help yourself:

branching lines v1.gh (24.7 KB)

Planned for v2: Surfaces spanning between adjacent branches (with optional “wrapping” parts to fill up to the sides when Spoprhing onto surfaces of revolution or similar topology).

Version 2:

branching lines v2.gh (43.2 KB)

Now with easy adjustable X and Y bounds, and Ridge/Valley output.

This goes well Sporphed onto a target surface with a similar geometric increase in width.

Okay… well, let’s simplifiy it now then:


1D tree VR 01.gh (47.0 KB)

This is phenomenal :))

You’re a wizard, Volker :slight_smile: Very nice use of Domains in the setup phase.
My first version also operated on line segments instead of vertices, but doing the valley-ridge part worked out easier if I hung on to the vertex positions so I could keep the Ridge connected to the “fork”.

“Surely there’s an easier way of doing this” I would say to myself doing (Graft, Repeat Data, Trim Tree) over and over again. Yes, yes there is, and it’s called Stack :tired_face:

I’m still proud of my “bit mask” method for assembling the non-overlapping polylines, although I’m sure that’s also possible to simplify!


Now, for the Hard Mode challenge
Can this be done with arbitrary numbers of nodes at each level?

The current implementation always multiplies the previous node count by some integer, but what happens if you allow fractional increases? So eg. instead of A: 1 x 2 x 2 x 3 to make a tree with 2, then 4, then 12 nodes, is there a deterministic way of making B: 1 x 2 x 1.5 x 4 to make a tree with 2, then 3, then 12 nodes? Or to go even further, C: a list of the number of nodes at each level?

I think C is impossible without loops. For example, in the above diagram, how do you decide what is the parent node of the 4th leaf? I used up a lot of ink and brain cells and couldn’t find a way.

But maybe if B is possible, you can just divide the sequential c values to get the equivalent i values?

I don’t know about arbitrary, but perhaps by other rules. There are entire production grammars out there, like L-systems that define different branch generation algorithms. Maybe some of the more mathematically minded individuals like @laurent_delrieu could help you out here.


Some results from a search for "L-system" on the forum:

Oh sure, I’ve played with L systems and recursion before. But they needs loops!
The “fun” is trying to do it wthout loops :slight_smile:

EDIT: Added quotation marks to the word fun.