How to combine several objects into groups at a certain distance

Hi all. I could not find a solution to my problem on my own. Help group objects that are at a certain distance from each other or less. Group it means to allocate certain objects to a separate branch. I’m still a beginner and don’t quite understand if this can be done.
Thank you all in advance.

Group.gh (4.0 KB)

Hmm … some sort of “extended” K-Means so to speak

The general case of this (GeometryBase Type of objects > Clustering by prox dist <= a given value) requires code - for instance if your objects are Breps there’s no R Method for Brep/Brep closest dist (*) in the way that a Crv/Crv closest dist Method is available.

(*) That is very easy via code.

Anyway if your objects are Curves I expect someone to provide some sort of Clustering solution using native stuff (not my game - at all).

If not … I’ll post here a Clustering C# for the general case.

I can’t code, so I didn’t understand much of your answer. :grinning:
In general, these objects are three-dimensional, I just simplified the task a little, but the meaning remains the same.

Get some images to get the gist: Given a Brep List, find prox distances (all VS all). So in order to Cluster your items you’ll need a Method like this “included” to a classic Clustering Method.



1 Like

What you could try to do is to get a specific point for each of the rectangles and make use of the “Point Groups” component. It doesn’t do excatly what you want but maybe it’s enough for your use case.
Group-sorted.gh (7.4 KB)

Another approach could be to get the bounding boxes of every object, enlarge it by half the desired distance and test the boxes of collision (use “Clash” or “Collision Many|Many”).

1 Like

This is a cool solution, but unfortunately it does not really work for me, the distance from the center of mass can be large for both large and small objects and because of this you need to manually adjust this distance.
With the second option, which you suggested, I do not understand how to work.
I am currently working with my version, where I scale these objects and if they overlap, I merge them into one area and check how many of the original objects are in it.
Thank you for your help to everyone involved

My second suggestions is pretty much what you did :slight_smile:

As I said that’s not that simple.

Imagine a Class (GeometryBase) that accepts a variety of “base” Types. Let’s simplify the whole thing and stick to Points (P), Curves (C), Breps (B) and Meshes (M). Meaning that your List of objects - general case - can contain any item of these 4.

So we have to check for proximity 10 Type permutations : P-P (easy), P-C (easy), P-B (easy), P-M (easy), C-C (easy), C-B (needs code) … blah, blah.

Result: we need to write 10 Methods. I have high perf code for all … but various pieces are strictly internal (notably for B-B, B-M). I’ll try to remove the sensitive stuff (if possible). Obviously if 2 objects yield Ccx Events (see demo used)… their prox distance is 0 … meaning that are sampled in a given Cluster.

In the mean time get a WIP thingy that - in this version - works only with Curves (it does that by asking a basic question - to any item in the geom List - prior the Clustering: are you a Curve? if not don’t play ball here).

For the record your “grouping” is called Flat Hard Clustering (HFC).

Clusters_GeomBaseProximity_V1.gh (129.1 KB)

It’s hard for me to understand what you wrote about “check for proximity 10 Type permutations” because I haven’t delved that far into such things yet. But I can write what I have achieved now and what is the task in front of me.

  • In general, there is a wall of a certain radius, which goes to the height of several floors.
  • I have a file with holes, which is a JSON file with control points.
  • I was able to remove duplicates and other small holes that I do not need.
  • I was able to reproduce these holes in volume.
  • Now I need to merge them by a certain parameter:
  1. If the faces of the hole are less than a certain length - these are small holes and I need to combine them into a group.
  2. If the faces of the hole are longer than a certain length, they are large holes and I don’t need to merge them.
    I was able to scale them according to my length parameter by height and width, but now I have another problem - I cannot merge some of the holes. Grasshopper gives an error: boolean union set is empty.
    I found a couple of solutions that helped other people, but they were all simple cases where the holes were not separated into branches. These solutions didn’t work for me and now the main problem is combining these unscaled holes.

Well … I’m engineer meaning that I ALWAYS deal with the general case of things when I write something (C#, components is not my game).

So the general object Proximity Clustering case should work with a mix of object Types … and the most common real-life Types are Points, Curves, Breps and Meshes thus the permutations. What means this? it means that a Point/Point Proximity is a different animal to a Point/Brep Proximity that is a different animal to Mesh/Mesh Proximity … blah, blah.

So regardless of your specific “layout”/case … this “grouping” (called Hard Flat Clustering - HFC) is just a very simple Clustring task based on some very simple question: given any current object are you (i.e. some other object) prox enough? if yes join the party (and never examined again) if no … next object.

So … above all we have the Clusering thing (a very entry level/naive one is used in the above C#).

This means: some freaky lines of C# code that do the job. But in order to do the job ONE question is asked: the proximity question, that is. And because we MAY have different Types of objects … this question is “splitted” in 10 “sub-questions”.

That sort of freaky (or rather simple if you can code) stuff.

Like this?


erase.gh (17.5 KB)

1 Like

Group.Edited V0gh.gh (13.3 KB)
Plugin Viper 7(github), Clipper.

1 Like