Clustering points

Hello all

Im not sure how to approach this one. The idea is to start with a bunch of points (say 100).

I want to find groups of points among the total set. So for example have an input of 5 and the definition finds 5 groups of equal size among the total 100. I am ultimately interested in finding “groups” that are clusters of points such that the cluster is made up of a subset of points that are the close to other points. Ill attach a simplified sketch with 30 points of what I mean below because that might not have been clear.

In the end the idea is to interpolate the external points of a cluster so that each group is enclosed by a curve that isnt intersected by another group’s exterior curve. (Kind of similar to “The Potato Plan” by Kees Christiaanse)

In the future the idea is to apply this to a 3D point cloud with a brep shell around them instead of a curve around a 2D point set, but I think its smart to start simple.

Any ideas how to approach this?

Thank you very much ahead of time to all those that give input :slight_smile:

I don’t have a lot for you but I believe you’re looking for an implementation of K-means clustering. That might help in searching.

or perhaps the Point Group + Convex Hull components will suffice (17.3 KB)

I thought this might be the way to go, but I cant figure out how to use the component or make a definition from it, and theres limited information about it online.

Lets say pop2d > kmeans gives an error of "data failed conversion of points to tensorset.

Any pointers?

Ive read through this

but theres no clear explanation there

I recode the component from your link

It works very well, in 2D or 3D and it is very simple, not many thinks to look at. I will try to rewrite it in C#.

k_mean2.ghx (374.8 KB)

Like advised by David here a version, without random seed, in C#, without datatree as Input. It seems to work well but I had not tested it a lot. It gives the same result as the VB component.

k_mean2.ghx (410.3 KB)


Hi guys! @laurent_delrieu Great job with rewriting the code to c#. I have a problem I struggle few days. Maybe you have some hints :slight_smile:

I would like to cluster the points but in clusters of predefinded number of members.

Lets say I have a group of 100 points and with K-means I want to cluster them in 5 chunks of 20, 10, 15, 5 and 50 elements. And I have no idea how to do it…

Welcome @monikakali,

Check this out:

It’s in Python though and 2D, but it’s easily translatable! Also not k-means, but does clustering in predefined size. :smiley:

Hey thanks for the c# version. I needed a nest-able version of this, so edited your c# component to nest the branches. Nested (15.2 KB)


Hi Laurent,

how can I be sure in your code, that I have always the same number of items in all the groups? Actually, in my case it doesn’t matter how many group I have, but I have to be sure that I have always same number of item in the groups. Can you advise me here?