Find shortest way to connect curves on different planes (Loop?)

Hey there,

I’m working on a custom slicer for a concrete printer that generates the tool paths for top shells and volumetric infill in different planes.

With the help of this Forum, I was able to generate continuous tool paths (based on sections of a gyroid generated with Crystallon) for each layer. But I struggle to find a method to reliably connect the layers with minimal travel distance. I used „connect curves“ component and the approaches from this topic to create the tool paths for each layer, but for the travel path between the layers they put out inefficient solutions.


My latest idea would be to use kind of a loop definition to iterate step by step from one layer to the next one, testing both curve directions of the next curve to connect start/end point and chose a path based on shortest connection line. See logic below:

  1. Start from end point of curve 1 (E1)

A)
Line from E1 to start point of curve 2 (S2)

B)
Flip curve 2
Line from E1 to start point of curve 2 (S2)

  1. Compare length of created lines
  2. Choose combination with shorter resulting line
  3. Join curve 1, Line, curve 2
  4. Repeat loop

My question would be if someone can think of a better way (without loops) to perform such a toolpath optimization or help me get the logic from above work with Anemone? Any tips highly appreciated, thank you!

find attached a test script. the layer spacing is exaggerated for better visibility.
240217_toolpath_between_layers.gh (74.0 KB)

if we talk of a greedy algorithm, meaning that each step is completed as an optimal solution of that step alone, the final result you would get might not be the most optimized one

at the same time, in a situation lile the one you show in the attached file, sections 3 and 5 both of them have both start / end point on the very same side, and in both cases the previous and the next sections do have one point also on the opposite side… so whatever optimal decision you can make, you will have to travel two times from one side to the other just because of those

the thing of having already well-defined paths to work with, looks to me like the greatest obstacle: is there a way the filling toolpaths could be re-calculated differently, by considering each of their start-point as the end-point of the previous layer, or something similar?

Blue group sets which end of the first group gets the connecting line / path, which makes a difference in the “sum of connect lengths” text panel…


toolpath_between_layers_2024Feb18a.gh (106.9 KB)

1 Like

thank you very much for your responses! @Joseph_Oster the script you shared was exactly what I was looking for, thank you! also helps to understand the loop logic a lot.

apart from that the point you mentioned @inno is of course very relevant when it comes to finding the most efficient toolpath. I will go into it and try to apply a similar loop logic always progressing from items inside branch (curves) to next branch (layer). I’ll post the script with unconnected layer lines in case anyone wants to give it a try.

again thank you very much, helped a lot!