Geometry Nodes connect points to spline (shortest path)

Hello everyone

I got a random point cloud with ~100 points.
I want to connect them to one long spline, but every “next point” should be the closest point (not yet in the spline) to the current point.

I have an approach to randomly connect them, by setting positions to an existing spline, but I am looking for a “closest” approach.

Does anyone have an approach?

Greetings, Mech

Hum !

I didn’t tried that yet, there is a index of nearest node that should give you the closest point , but sadly that’s not enough … Next ingredient is a loop that allow to exclude the points you already processed, and next stuff you need is to pick the first point you want to process.

So basically blender 4.0 got you covered with the repeat zone. The algorithm should be something like that :
first create a spline with enough points,
Pick a point in the point cloud,
loop over the point cloud, find the nearest point of the first point, sample it’s position and assign it to the corresponding spline point,
remove the first point from the cloud, pick the “closest point” you find earlier and look for it’s closest,
Since it’s in the repeat zone you should have the spline fully constructed by then.

That’s the theory , and if you struggle with the practice tell me and I’ll try something during the week or the weekend !

Good luck !

2 Likes

There is a points to curve node in Blender 4 that accepts a weight. Can’t you just put length to nearest point into that weight input?

Tried that, didn’t work, it will not create one spline by definition, because it does only get the greedy nearest with not looking ahead more than one step.

yeah you’re right, went into a similar problem recently. so I guess sozap’s iterative approach might be the way to go

Sounds good. Could you give a screenshot of a node graph? I used Blender 4.0, but am not familiar with the exact functionality.

Hey !

I don’t have the time to look into that, but maybe post a test file showing where you’re at, and me or someone else will give it a shot.

Good luck !

1 Like

Not sure I got it right, but were you thinking something like this?

closestpoint
Point cloud connecting to the closest points on a spline.

7 Likes

If @dan2 is right I’ve got this backward. Starting with the random point cloud and delivering a curve spline that connects all the points. Starting at a point, the next point on the spline is its closest neighbor. My solution is exactly what @sozap described. The result looks like this,

The starting point creates a random point cloud:

The Short Connect node looks like this,

The size of the curve and the number of iterations are determined by the size of the point cloud before entering the repeat zone. The position of some starting index is also set before entering the zone which will have an affect on the path.

9 Likes

Could be interpreted either way but yours may be they way you go :slight_smile: Connecting them to a long spline threw me off at the first read.

This looks good. I will try to apply it to my nodetree. Thanks