Grasshopper PointGroups RhinoCommon equivalent

Hi,

Is there any RhinoCommon function similar to the ‘PointGroups’ component in grasshopper, or it needs to be written from scratch?

image

Thanks in advance for your help!

I don’t think so? :thinking: but you could use Node in Code to achieve that.

cheers.

Hi Bob,

Thanks! I didn’t knew this.
But as I’m using RhinoCommon via a C# plugin, I won’t have access to this feature :frowning:

Oh I think It’s totally possible in C# you’ll just use the Rhino.NodeInCode namespace and it’s a little different implementation. Check out this post: Using the NodeInCode namespace

Hi, not fully tested but does this do what you’re looking for?

using System;
using System.Collections.Generic;
using System.Linq;
using Rhino.Geometry;

Func<List<Point3d>, double, List<List<Point3d>>> point_groups = (pts, minDist) => {
    var pointGroups = new List<List<Point3d>>();
    List<Point3d> lonePoints = pts;

    bool repeatLoop = true;
    while (lonePoints.Count > 0) {
        var inRangeGroup = new List<Point3d>{lonePoints.First()};
        lonePoints = lonePoints.Skip(1).ToList();
        while (lonePoints.Count > 0 && repeatLoop) {
            repeatLoop = false;
            var tooFarGroup = new List<Point3d>();
            foreach(var lp in lonePoints) {
                if (inRangeGroup.Any(p => p.DistanceTo(lp) <= minDist)) {
                    inRangeGroup.Add(lp);
                    repeatLoop = true;
                }
                else
                    tooFarGroup.Add(lp);
            }
            lonePoints = tooFarGroup;
        }
        pointGroups.Add(inRangeGroup);
        repeatLoop = true;
    }
    return pointGroups;
};

G = point_groups(P.ToList(), D);
3 Likes