Hi everyone,

I tried to cluster points by distance as the Point groups component does.

It is just for learning.

I am able to assign the points that are close enough to eachother to a branch, I got stuck assign the far away ones.

I think I maybe need to get first all distances and then compare against the treshhold- but I am not completly sure how to do this and if this would be the right way?

My attempt so far is this:

```
private void RunScript(List<Point3d> pts, double tresh, ref object Indices, ref object Distances, ref object Groups)
{
//set up the trees to store the data
var distances = new DataTree<double>();
var groups = new DataTree<Point3d>();
var indices = new DataTree<int>();
//loop through every possible combination to get all the possible distances
for (int i = 0; i < pts.Count; i++)
for (int j = i + 1;j < pts.Count; j++)
{
double d = pts[i].DistanceTo(pts[j]);
dists.Add(d);
if (d < tresh) //add points and indices to tree if they are close enough together
{
groups.Add(pts[i], new GH_Path(i));
groups.Add(pts[j], new GH_Path(i));
indices.Add(i, new GH_Path(i));
indices.Add(j, new GH_Path(i));
}
}
Indices = indices;
Distances = dists;
Groups = groups;
}
```

I am quite sure there is a better way, maybe using LINQ or a Hashset, but at the moment I would be ok with any/ a slow solution.

I hope someone could help and I described the problem so anybody can understand.

Regards!

File:20190505_GroupByDistance.gh (5.4 KB)