Grasshopper

algorithmic modeling for Rhino

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

 

Views: 2220

Attachments:

Replies to This Discussion

Guideline for resolving all things: (a) set mode to sport, (b) ride

Attachments:

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>

This is not a violation of the license agreement, you are allowed to reference any assembly that ships with Grasshopper and use the methods provided therein.

Yes, although I used a reflector to find the class and see how it was implemented.

In this case the implementation was pretty trivial, so hopefully it doesn't count as copy-pasting the code of a private class.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service