Hitesh Sahu
3 min readMay 29, 2019

ON TREE GENERATION ALGORITHM

I always have been fascinated with patterns in Nature:

  • Networks that keep on Branching like veins, leaf, rivers, lightning.
  • Self repeating infinite fractal geometry like trees, cells, tissues, ferns etc.
  • Entropy & noises in all forms of matter like landscape, liquid diffusion, Brownian motion etc.

I think what I enjoy the most is that how complex & chaotic this patterns might look like from the outside but internally they are governed by a set of simple mathematical rules.

Recently I’ve been particularly interested in Fractal generation algorithms. Since my background was in mobile applications I had limited knowledge of visual imagery. There was no way to test if my Procedural generation algorithms are correct(Procedural generation is method of creating random visual pattern with the help of algorithms)

In spite of that I had edge in JavaScript. So I learned to create my little three-dimensional sand box using WebGL. Now I have I’ve been experimenting quite a lot to guess mathematical logic behind this patterns & mimic them using generative algorithms.

Sometimes I manage to recreate the phenomenon and I end up finding something new.

Last week I was trying to crack logic behind tree generation algorithm.

GENERATING 2 DIMENSION TREE

In two dimension world we can describe next branch of a tree using polar coordinate system.

In polar coordinate a point can be defined by a distance(r) from a reference point and an angle (θ). where

  • θ(Theta/azimuthal angle) : counterclockwise angle from the x- axis
  • r (radius): distance from a point to the origin.

For a branch its length can be consider as r. The angle θ can be defined by sum of inclination angle of previous branch from origin + deviation from previous branch.

Hence we can generalize coordinates of nth branch of tree using this formula:

RESULT: implementing it with Three js gave this result

Interesting thing here is that if I remove Xn-1 & Yn-1 in the above equations I ended up building inverted tree which resembles root of a tree:

GENERATING 3 DIMENSION TREE

Similarly, in three-dimensional world next branch vectors can be located with the help of Spherical Coordinates. Spherical quadrants are defined by 3 parameters:

  • θ(Theta/azimuthal angle) : projection angle in the xy-plane from the x-axis
  • φ(Phi/polar angle):angle measured from the z-axis
  • r (radius): distance from a point to the origin.

Using θ, φ and r we can define x,y and z quadrants like this

x = r*Cos(θ)Sin(φ)

y = r*Sin(θ)Sin(φ)

z = r*Cos(φ)

Comparison of quadrant systems:

Result of first attempt:

Result of Second attempt :

See it as video:

See Live Demo & Source code:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response