An idea for faster multi-attractor curves

Hello everyone, this is my first post on this forum even though I’ve been playing with grasshopper for a while now.

While working on a genetic algorithm approach (Octopus) I found myself very unhappy with the performance of the various distance calculations for attractor methods, especially in the case of multiple attractor curves.

So I tryed another approach with which I have had very nice results : instead of computing a distance for each point to the attractors and taking the smallest, I generate an image by plotting the curves, and then blurring them to get a nice gradient around them (influence zone of the attractor). Once the image is generated, one only has to sample it like the component image sampler. (and the cost does not depend on the number of sampling points !)
temp

Attached is a demo definition showcasing my code (which I’m sure is not up to your expectations as I am a complete beginner in Python) . It runs with GH_Cpython because it relies mostly on Matplotlib and PIL.

pERFORMANCE
It is quite taylor made for my purpose, so I don’t know if it will be of any use for anyone else, but I think the idea is nice and gives good results, so it might inspire someone else to develop it or use similar ideas !

Alternative attractor.gh (26.9 KB)

I’ve used bitmap lookups before to drastically speed up region interior/exterior tests. However the accuracy often needed for distance calculations is difficult if not impossible to encode into the greyscale values of an image. You only get 256 different luminance levels without jumping through a lot of hoops.

Of course you can create a custom bitmap type which uses double precision samples, or you could use the image to speed up closest curve lookup. Assign each curve a unique colour (just convert the index into ARGB integers) and then fill the region closest to each curve with that colour. This allows you to immediately find the closest curve and use only a single closest-point measurement. Although you will run into rounding and accuracy errors at the boundaries.

Here’s a (slow) way to generate such a closest curve lookup map. The idea is to draw each curve in its own special colour using a really thick pen. Then after that draw all curves again using a slightly thinner pen. Repeat until you’re down to a 1 pixel pen: ClosestCurveLookupMap.gh (20.7 KB)

You end up with something looking like this:

1 Like

This method seems to produce a pretty good medial axis. I know, there are other ways to compute medial axis, but is there a way to extract the boundary from your color plot?

Kudos to Luchavy for a new method, by the way.

You can use an edge finding filter on the bitmap, but that will give you at best pixel-accuracy.