Fractal Tree 2

While the fractal tree in the previous post was cool and all, it only creates two branches at the end of each segment. So how to add more branches to the beautiful tree?

Fractal Tree with four branches at end of each segment, iteration 1

While I reused most of the code from previous post such as the fractal length ratio, the branch angles needed some rework. Now the Branch Angle sets the overall angle of the whole set of branches from the previous segment (angle still being relative to the previous segments direction). The angle is then divided by the Branch Amount to get the angle rotation for each new branch.

Fractal Tree with four branches at end of each segment, iteration 2

Fractal Tree ‘growth’ with 3 branches per end of segment
Fractal Tree ‘growth’ with 4 branches per end of segment

And with the same visualization style as the previous post we get a fractal tree with a more dense looking branch system, especially at the very top where the branches intersect and creates a more concentrated look.

When the branch amount is more than two, the overall number of branches increases significantly (as well as computation time..). In Grasshoppers Param Viewer component, with a setup of 4 branches per segment for 6 iterations, the final iteration has 4096 branches.

Grasshopper UI of the component
private void RunScript(double startLength, double lengthRatio, int branchAmount, double branchAngle, int iterations, ref object A)
  {

    Point3d startPoint = new Point3d(0, 0, 0);
    Vector3d startVector = new Vector3d(0, 1, 0);
    Vector3d z = new Vector3d(0, 0, 1);


    Line first = new Line(startPoint, startVector, startLength);

    int path = 0;
    GH_Path firstPath = new GH_Path(path);
    DataTree<Line> treeBranches = new DataTree<Line>();

    treeBranches.Add(first, firstPath);


    // branchAngles
    List<double> angleList = new List<double>();
    angleList.Add(branchAngle / -2.0);
    double angleIncrement = branchAngle / (branchAmount - 1);



    for(int i = 0;i < iterations;i++)
    {
      List<Line> branchList = treeBranches.Branch(treeBranches.BranchCount - 1);
      path++;
      GH_Path pth = new GH_Path(path);
      foreach(Line branch in branchList)
      {
        for(int j = 0;j < branchAmount;j++)
        {
          double newAngle = angleIncrement + angleList[j];
          if(j < branchAmount - 1)
          {
            angleList.Add(newAngle);
          }

          Line newBranchLeft = treeBranch(branch, angleList[j], lengthRatio, z);
          treeBranches.Add(newBranchLeft, pth);
        }
      }
    }

    A = treeBranches;



  }

  // <Custom additional code> 
  Line treeBranch (Line Branch, double BranchAngle, double LengthRatio, Vector3d RotationAxis)
  {

    double radianRotation = RhinoMath.ToRadians(BranchAngle);
    Point3d endPoint = Branch.To;
    Vector3d direction = Branch.To - Branch.From;
    direction.Rotate(radianRotation, RotationAxis);

    double length = Branch.Length * LengthRatio;
    Line newBranch = new Line(endPoint, direction, length);

    return newBranch;
  }