
This article is a byproduct of an article Solid-state topography with layers. This algorithm has no practical application by itself, but can be at the core of many needed solutions. Its main function is to create links between elements in order to group and sort them according to a complex principle. It also works so beautifully that I had to write this article!
Script and test file:
Mesh_cluster.rar


🌴Much more than a game. Why is it necessary?
- Creating unfolded geometry
- Grouping points into clusters of equal size
- Construction of paths of minimal length through a set of points.
Is it needed directly in Revit?
**Practically not.**🤦
However, it will definitely come in handy in GIS systems and in programs that work with free geometry.
Work logic
-
The first thing to do is to turn a triangle into a container with different data :
Points, faces, indexes in list...
-
Introduce concepts such as
- Tree - tree of elements (A chain is a special case of a tree)
- Generation - The birth number of a new branch, counting from the root of the tree. The root of the tree has a generation number of 0, its branches -1, etc.
- Parent - The element from which the branches grow
- Child - The element that was added to the tree when the parent adopted it
-
Next you need to write a loop that:
- Finds a child for each parent
- Deletes the reference to the child so that other parents cannot adopt the child and so that the parent does not accidentally adopt the child twice when searching for another child
- Transfers the qualities of the parents to the child (Number of a Tree)
- When all children from all parents are found, the children become parents and the cycle repeats.
Tests:
What would happen if we painted each generation in individual color

Radial sorting, branching

Sorting by X, branching

Random, branching
No branching