C# "equalize" random points

Well friends,

Imagine a brep with a single face (a trimmed surface) that "approximates" some tensile membrane that may look like this image attached (prior sending stuff to Kangaroo). Not my project: in fact some friend's friend asked that in order to send a collection of random "anchor" points to Kangaroo and ... blah blah.

The requirement is to find anchor points by (a) creating a random set of points (within the projected face in a given plane, in most of cases the global xy) and then (b) "culling" them as follows:

(b.1) no two points are closer than MinDistance.

(b.2) no two points are too far away than MinDistance.
... and then (c) project them on a mesh (derived from the brep)

So this script attempts to "cull" randomly placed points that satisfy(?) the MinMax criteria and do the rest. NOTE: points are few ... so don't stick to algorithm's efficiency.

2 questions for the willing gurus out there:

Script 1:  this "cull" approach is rather wrong - I'm open to any suggestion.

Script 2:  change the MaxDist value and observe the script turning from red to OK status. Why?

NOTE: GH fails to internalize stuff quite frequently. If this is the case, use Rhino file

best, Peter

 

  • up

    Thomas

    Hi!

    Script 1:

    If I understand you correctly you have a list of points and you want to select the points where the shortest distance to all other points is within a given interval.

    A very simple attempt:

    The result might depend on the order of the points (first point -> higher priority).

    13
  • up

    Vicente Soler

    If you reference the Vector.gha assembly in a scripting component you can use the PopulationSolver class that is used in the Populate components. You'll have to create a derived class that inherits it.

    (I don't know if I'm breaking the user agreement doing this.)

    Sample code for a C# scripting component:

    private void RunScript(object x, object y, ref object A)
    {
    var rectangle = new Rectangle3d(Plane.WorldXY, 10, 10);
    int numPoints = 100;
    int seed = 24601;
    var existingPts = new List <Point3d>();

    var rectangleSolver = new RectangleSolver(rectangle, seed);
    A = rectangleSolver.Populate(numPoints, existingPts);

    }

    // <Custom additional code>
    public class RectangleSolver : PopulationSolver
    {
    Rectangle3d rectangle;
    public RectangleSolver(Rectangle3d rectangle, int seed)
    : base(seed)
    {
    this.rectangle = rectangle;
    }
    protected override BoundingBox BoundingBox()
    {
    return this.rectangle.BoundingBox;
    }
    protected override Point3d NextPoint()
    {
    return this.rectangle.PointAt(this.RandomNumber(), this.RandomNumber());
    }
    }
    // </Custom additional code>
    2