# Cell segregation based on Curve Intersection

I am trying to sample an area into hexagonal grids. And based on the where the roadways(shown in green) are I want to separate out those hexagons.
I tried to divide the roadway curves into parts and check if the points fall within any hexagonal cell or not. However I am fairly new to grasshopper and couldn’t figure how work with trees? Also if anyone has any other suggestion on how it could be done I would greatly appreciate. Thank you.

2003.gh (18.2 KB)

You have internalised a file path, but not a shape file.

Sorry about that. I am just uploading a simplified version instead. How can I segregate the cells through which the curve crosses. 2103.gh (4.8 KB)

Try this, you don’t share complex version so you need to modify this simple solution

Thank you very much. It works perfectly. However I didn’t understand why we have to graft the cells while checking for collision and cull pattern.

Try without graft and you see the difference, you can switch between them without using graft
Cells plugged to C and curve plugged to O

Purely for fun get the attached as well: is not suitable - at all - for you (unless you have plans to learn C#) but outlines 3 ways to cluster your hexagons (Note: LunchBox is used for these).

BTW: Open curves are rejected plus hex Polylines with count != 7.

Just a note/tip.
To avoid inconstant width of lines/curves rendered with “hexagons pixels”, you could do like here:

Instead of doing collision with the hexagon itself, use another inscribed hexagon.

Edit:

hex-pixels.gh (12.4 KB)

This was a problem I didn’t anticipate. Thanks for pointing it out and sharing the solution. However I can’t make it work with multiple curves.

Thank you for sharing this alternative. I ll will probably take some time to understand it though.

As I said is just for fun (unless … blah, blah). Plus is a very entry level take (thus is very slow) on a very challenging task: if you have lot’s of curves and lot’s of “pixels” (i.e. hexagons in this case) you’ll need a totally different approach in order to slash elapsed times.

Added an open/close curve support if the policy is CCX.

Hi @maje90 , if you want leave one hexagon culling closest points do the job.

hex-pixels2.gh (14.9 KB)

hex-pixels2_re.gh (15.0 KB)

Closest point seems unreliable to me:
it might miss some hexagon and also sometime pick hexagons almost completely detached from the input curve (see top left).

Doing a distance + vector check might result the same as inscribed hexagon collision but with lighter calc…

Maybe this work by finding 3 duplicate points

hex-pixels3.gh (13.9 KB)

I was able to make it work thanks to all the inputs. But I am still getting inconsistent width in-spite of using the inscribed hexagon method. More so, some hexagons which do not intersect are also being considered. Is it because of the scale of the drawing? Because the shapefile I got was very small. Is there any way i can fix the dimensions?

dharavi.2.gh (26.1 KB)

hex-pixels4.gh (15.6 KB)
(Inside also the failed attempt to solve with “inscribed hexagons” without curve-curve collisions: failed, incostant width and/or missing pixels, also heavier than collision method)

1 Like