Geometry nodes: How to capture nearest curve point?

Hi!

I’m overlooking something here, so I could use some help. I have various cyclic curves in the scene and when running each through repeat zone, I add to them bounding box and the goal is to select nearest curve point closest to BB’s index No.7, which is located on the top right or each bounding box. Each circle represents roughly where I’d expect the sampled curve point to be located, but for now only getting almost the opposite of that and in some cases not even exact opposite, but somewhere in the middle (middle qustion mark).

Clearly, I don’t understand well enough how to capture curve points yet…

For those interested for why to do this, I figured I could force all curves to have same direction by looking up one index via BB and then following curve index’s location would determine if the curve is running the correct of the opposite way. Since I don’t generally know where those curves begin or end and neither I know their direction, as they are generated from a mesh boolean. My goal is to unify the direction of all curves clockwise this way.

If anyone has a better idea how to approach this, I’m all ears!

Hi Radek,
you could calculate the Winding Number to check if the curve goes clockwise or counter clockwise:

However you need to specify a “center point” which needs to be inside the curve… could be the center of the bounding box for example but that’s not always 100% inside :man_shrugging:

3 Likes

But to answer your initial question:
Instead of looping over all curves, you could use the new Split To Instances node to convert them to instances first. Then we can realize the Bounding Box of each Instance and sample the position of one of its vertices (e.g. index #7). After that we can convert our inital curves to points and make use of the Sample Nearest node to get the point of the curve that is closest to the bounding box vertex like so:

And this is the result:

Hopefully we can get a Group ID input for the Attribute Statistic node… this would make this setup way easier.

4 Likes

Maybe I’m too tired for this again, but I believe I had to loop it anyway, as I need to do other things with each spline individually later on anyway. So, for sake of this particular operation I’m going for, following works.

Each spline gets it’s point located towards BB’s index No.7, then that vert’s location get compared to the location of following vert (sample index + 1) and depending on if curve’s next index is either on the right or left (comparing position of each vert on X axis only), entire spline gets reversed. Creating uniformed look for all normals generated from these splines.

Before

After

It’s not bulletproof and I can imagine some extreme scenarios where this wouldn’t be 100% reliable, but from all these random samples, all turned out fine, so I don’t complain.

So my base for terrain decals seems to work out ok now. Now to do some tweaking and randomization. Appreciate the advice, guys!

1 Like