Categories
Nature Algorithm

Leaf venation algorithm

I tried to write this algorithm in the simplest so at the start I set two loops. The outer loop is to loop through the iteration where each iteration add a new vein to the tree, the second loop loops through each of the current vein node, check for sources that are near to the vein then add the next vein node. I thought modifying the algorithm that way makes it easier and still achieve the effects. However, the result is as expected, the vein does not grow out. I was consulting Long (the developer of DynaShape) on this algorithm to study what has gone wrong. By flipping the logic, if I visit each node first and see which sources will influence it, one source might influence more than one node. However, if we visit each source first then a source only influence one node.

The logic could go like this:

For each source:
Check for the nearest node:
This source will influence that node
Get the vector that indicate the growth direction of the node toward this source (pt(source) – pt(vein-node) add the vector to the next node growth  (remember one source might only influence one node but each node can be  influence by multiple sources)remove sources from the original list

However, you might wonder, how do we store and match the list of sources/ growth vector associated to a vein node. The trick is to create a list of zero vectors which correspond to the current number of vein nodes. As we loop through each source, we add a new vector direction to this zero vectors. When we finish looping through all the sources, we finish giving each vein node an appropriate growth vector associated with that vein node. The pesudo code is below

pesudoCode