4

Intro

Shortest Path is very well documented if you want to generate Start / End path specified by two points. Like here Start at index 0 and End at index 3 ...

enter image description here enter image description here

Note: Specifically in my case I will use some obstacles blocking the direct connection ...

enter image description here

My question

Is it possible to generate shortest path passing through a several points? Like in this example (with randomly selected vertices) ... the path should start at index 1 find shortest path to index 14, than shortest path to 40, than 44, 58, 61, 70, 74 and end at index 80.

enter image description here

Sorry for old version of blend (3.4 alpha) home workstation limit :) at work I use the latest version.

Note: I already tried connect bunch of points by a spline and thanks to Markus's answer I could let a curve to push from an obstacle, but there are a lot of splines penetrating an obstacles for some reason. So I would like to try a different approach (also recommended in my original post).

vklidu
  • 36,165
  • 1
  • 61
  • 135
  • Hi, there.. would 'Shortest path through an ordered list of points' be a more accurate title? Just quibbling, might be wrong.. – Robin Betts Oct 29 '23 at 19:25
  • Sure ... Thanks :) It is already a few days I'm scratching not only my head for this topic ... trying to find right direction from many directions :) so I'm loosing control and my healthy distance. – vklidu Oct 29 '23 at 19:35
  • sounds like you answered your own question in your question: why don't you make several "shortest path" for every "subpath" and then connect them? – Chris Oct 30 '23 at 08:22
  • 1
    @Chris Because I don't have a clue how to automate such process :) ... and also I thought there could be probably much better way. – vklidu Oct 30 '23 at 09:58
  • 1
    If I understand correctly you want to connect via shortest path the indices pairwise: 0>14,14>40, 40>44, 44>58, 58>61, 61>70, 70>74, 74>80. This can't be done with a single Shortest Path node set up. You need exactly one start vertex and one end vertex to force a pair connection. That means you need 8 Node setups with the current algorithm. If there is a way to define a set of points as mandatory to pass through then that would be great. The only way with the current algorithm I see is via manipulating the Edge Cost values. Not sure how to that yet, but its worth exploring. – Rumen Belev Oct 30 '23 at 10:02
  • As i said, just use a repeat zone and pass the start and end values. Then you get something like this: [1]: https://i.stack.imgur.com/9VTT1.png i added a few more obstacles to make it more interesting. - and yes, i didn't make the last step and connected the several splines, but i think that is the easiest part of it. – Chris Oct 30 '23 at 10:36
  • just a hint how to do it: you shouldn't use the distance as edge cost, but the proximity value (fine tuned with a map range value) to your obstacles. So the cost should be high very close to obstacles, everywhere else zero. Mine looks like this through the viewer: [1]: https://i.stack.imgur.com/MDtR1.png – Chris Oct 30 '23 at 10:38
  • all i did was a) changing the cost b) using your node tree and adding a repeat zone which changes the start and end values. – Chris Oct 30 '23 at 10:40
  • Thanks :) I didnt noticed you were speaking about "repeat zone" ... Sounds good to me ... any reason you hesitate to create your answer? :) ... so it can be credited :) – vklidu Oct 30 '23 at 11:30
  • yes - my time - maybe tomorrow i can write one. – Chris Oct 30 '23 at 11:48
  • Sure I would appreciate that ... I don't think I get it how to use the repeat zone and mainly ho to feed the list of indexes to it (I hope you are not speaking about situation I would have to manually set indexes 0>14,14>40, 40>44, 44>58, 58>61, 61>70, 70>74, 74>80 ... the real model looks way complicated :) – vklidu Oct 30 '23 at 12:06
  • no, not manually – Chris Oct 30 '23 at 12:09
  • @Chris ... if you don't have a time for answer I would appreciate if you can share just your blend file with your test, so I can try to learn from that file. Thanks – vklidu Oct 31 '23 at 10:30
  • @vklidu It seems the Edge Cost is a little be tricky to handle across multiple points. Also I think selecting a Grid as a plane is not a good choice. The random points when connected look like zig-zag also there is a serious backtracking (overlapping shortest paths). I think it is better to choose a triangulated mesh. Here is the result I am getting so far: With Grid (https://i.stack.imgur.com/Mux0n.png), With triangulated plane (https://i.stack.imgur.com/w9z6e.png). Based on joining paths between each pair of points and smoothing the result - so repetition of modules is unavoidable. – Rumen Belev Oct 31 '23 at 23:33
  • @RumenBelev ... right, the triangulation is better (I didnt focuse on that since I mainly wanted to know if it is possible to work with shortest path guided by other specified points). Even I'm still interested how does it can be done ... you spotted probably one of the issue - the path will be probably quite straight so I would have to move distort plane by some texture (or use a texture to mix it as a value for Edge Cost). Anyway it seems to me I'm the only one who didnt understand how to achieve it? :) Thanks for more info. ... BTW We are close to Chat Room :) – vklidu Nov 01 '23 at 10:22
  • @vklidu I would suggest opening a thread on Blenderartists if you have an account there. Or we can set up a chat via https://chat.stackexchange.com – Rumen Belev Nov 01 '23 at 16:46
  • Yes I have the account on BA (same name) ... I was there quite active before I noticed BSE make more sence :) – vklidu Nov 01 '23 at 18:54

1 Answers1

2

This is my approach to solve this problem without simulations. Let's give it a name - Constrained Shortest Path.

In summary, the idea is to force a path [edge selection] via iteration of the Shortest Path algorithm that passes through select set of points (in ascending index number order) from a Mesh grid, giving the resulting path a tangled cable appearance.

Here is the result so far:

enter image description here

The Mesh grid will be added for clarity. As you can see holes are implemented via points deletion using a control Empty object.

enter image description here

Here is the node set up, however it is too complicated to explain in detail here. A .blend file is provided at the end of the post for your own studies.

enter image description here

Here is the short description:

  1. Initial Point selection - Select points from the Mesh plane via random value generation to speed up the testing process. As it is hard to control the exact number of selected points or generate a good point distribution this way other methods for selection initializing should be considered.

enter image description here

  1. Plane with Hole(s) - this is the mesh from which we select the initial points. The plane has an option for vertex deletion (single hole) . The hole widens with scaling the Empty object.

There are few types of input Geometry grids tested:

  • Ordered quad grid - separate object, when the random points are connected they produce a zig-zag like pattern and are not a good candidate.
  • Quad grid - separate object with vertex index randomization
  • Triangulated grid via modifiers - the host Plane object with modifiers stack before the Geometry Nodes modifier.
  • Triangulated grid - separate object with vertex index randomization

Here is a comparison:

enter image description here

All grids are available for testing in the file

  1. Elevate the initial point selection - The selected points are moved slightly above the surface, the end points - even higher.

enter image description here

  1. Shortest Edge Path Modules - The process is as follows:

a) Select first two vertices from the selection (in ascending order) - Output shortest path via curve

b) Remove the smaller index vertex from the selection.

c) Pass the resulting selection to the next module.

d) Repeat the process.

There are 1+20 operations currently. The file will work best with about 21 selected vertices or less. Add more modules for larger number of selected vertices.

Blender 3.6 doesn't have looping nodes, A Repeat zone is expected to be released in Blender 4.0. This will make the iteration over repetitive processes so much easier.

  1. Distribute Mesh Line on Paths - All generated paths are joined in specific order so the indices are in ascending order. A Mesh Line is generated to match the point count of the curve and the positions of these points thus forming a continuous single thread. The Mesh Line is then converted to Curve.

enter image description here

6 Randomize slightly Z positions - just to decrease the amount of overlapping points due to path backtracking.

7 Resampled Auto Handle Curve to Cable - giving the curve a Bezier type with Automatic point handles gives best cable like appearance. Lastly a simple Curve to Mesh node is applied to generate the cable.

You are welcome to explore the .blend file:

enter image description here

Edit: As requested by @vklidu I am including the setup for the upcoming Blender v4.0 using the Utilities > Repeat Zone instead of connecting / removing modules for different amount of selected points:

enter image description here

and a close-up:

enter image description here

You can change the number of Iterations manually or plug the number of selected points to control it automatically.

This should work for Blender Versions 4+. I can't guarantee the Repeat Zone will change after release, but it is most likely to remain the same.

Rumen Belev
  • 3,388
  • 10
  • 25