Grasshopper

algorithmic modeling for Rhino

Hello there,

I´m not new to grasshopper but very new to regular programming Languages.

I have a simple looking Problem:

I have a point Cloud and I have a Grid of  Rectangles.

The point cloud is all over the area of the Rectangles.

Everything is on the same Plane.

What I now need is a list containing sub lists with the points in each rectangle.

I already tried around with the Point in Curves Component, but it unfortunately doesn´t work very well with multiple curves. A friend told me, that it could easily be scripted within C# with a foreach loop, but I just dont get it myself.

Can someone help me?

Views: 991

Replies to This Discussion

It sounds like there's two ways to approach this, the easy slow way and the hard fast way:

  1. Write two loops, the outer one iterates over the rectangles, the inner one iterates over the points. As soon as a point is deemed inside a rectangle it gets added to the appropriate list and removed from the cloud. You can also switch the inner and outer loops, but then you can't shrink the cloud as you assign points so it will take slightly longer still.
  2. If your rectangles represent a tight grid, then each point can be assigned to the appropriate cell using two simple mathematical operations: (int)(N*F*(c - L)), where c is the coordinate component of the point, L is the edge of the grid, N is the number of cells, F is the size of the grid. This is ultra fast but it relies on your rectangles being a perfect rectangular grid with no gaps or overlaps.

I'll upload a file soon that shows these approaches.

--

David Rutten

david@mcneel.com

Incidentally the Point In Curves component should work fine for this. I don't know why it doesn't for you. Perhaps that's worth looking into as well?

--

David Rutten

david@mcneel.com

See attached for two C# scripts.

--

David Rutten

david@mcneel.com

Attachments:

Hello David,

Thank you very much. I will look into the script as soon as i can :)

The point in curve component just shows me all points in all rectangles, with 2 for containment and 0 for not containment. so i have a list with 256 sub lists with 4000 values each. Maybe it does what it should, but it crashes before...

Greetings,

Florian

David, thank you very much. This problem worked my head for a long time...

Best,

Florian

The second output should tell you in which of the regions each point ended up.

--

David Rutten

david@mcneel.com

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service