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.
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 !
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.
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 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.