Culling Curves based on Density

I am trying to clean up Stress Lines that are produced by Karamba so that I can 3d print them. Curves should be culled that overlap or that become denser than the width of the 3d printed filament.

I’ve written a C# script that iterates through the list of curves, and measures the distance to other curves in the same list, and removes a curve from the list if the distance to other curves is too small. I used the Curve.GetDistanceBetweenCurves method to find curves that were within a certain distance. This works okay, but it is definitely not an optimized result and is computationally heavy. (admittedly I don’t know entirely what this component is doing, maybe I can decrease tolerance significantly).

This is first attempt was so heavy in part because the list of curves is unsorted. I think what I want to do is just measure the distance to the neighboring curves in the list. However, the adjacent curves in the list are not the adjacent curves in Cartesian space. So I had to measure the distance to all other curves in the list. Shhheesshhh, definitely not ideal.

So I am attempting to sort the list of curves. I want to sort the curves based on the x-coordinate of some point on the curve. Because of the boundary condition, I don’t use end points, but instead I sort based on mid points. This works fairly well (see image below), but it is still error prone. It tends to have its highest accuracy towards the middle of the surface where the lines converge. But the outliers still introduce errors.

So then, I did a similar Curve.GetDistanceBetweenCurves method, but this time, only between a curve and its neighbor in the list. This made the computation much lighter and more rapid.

I am still far from having stress lines evenly spaced at 2mm from each other. Hopefully, you all have some advice to help guide me down a better path.

Curves output from Karamba:
image

Culling curves that become too close together:
image

Curves get sorted fairly well in the middle, but the edge conditions are still a mess.

culling lines based on density.gh (2.0 MB)

I would (manually) pick a starting curve that looks like in the “middle” of the whole thing
then I would loop this way:
Curve Proximity from this curve to the remaining ones → if distance is minor than 2 then → Cull those

I’m kind of running, but this is a very dirty, very incomplete prototype just to explain the basic idea

I stopped it at iteration 11 because the next one it just deletes everything :slight_smile: as I said… it’s just a dirty incomplete prototype, but it might work if refined enough
culling lines based on density_Re.gh (601.7 KB)

1 Like

Thanks Inno,
This is a really cool solution. I haven’t used anemone before, so this is interesting for me. I think the reason it stops at 12 is because there are no more possible solutions. So it appears your script works 100%. I will have to test this gh script on different stress line patterns, and test its robustness.

Your loop:

  1. Finds curve Proximities between current curve, and all other curves
  2. Culls out the curves that have a proximity greater than 2
  3. Selects the curve with closest proximity (and greater than 2), and begins the next loop using this curve

I suppose anemone stores the solutions, and prevents those from being future solutions. Effectively, preventing the algorithm from working backwards, or being caught in an infinite loop.


because these two booleans are inverted, everything that is < than 2 = True becomes False for the culling pattern (it’s the very same of just using the “Larger” component… don’t know why I have picked Smaller :smiley: )
so from the list of “available curves” (in D0) the Culling removes all the ones that have distance smaller than 2 units from the current one
then the curve (chosen among the remaining -already culled- ones) that has the lowest distance from the current one is output to D1

then the loop restarts:
D0 has only the curves already culled in the previous step
D1 carries the single closest curve found on previous step
all the curves in D0 closer than 2 units from the current D1 are culled and become the next D0
the closest curve to current D1 in next D0 becomes next D1… and so on