Set Input number such that Calculations Output equals some constant?

Hello,
I’m wondering if there is a way to set a slider (or any number input) to whatever number will result in a predetermined outcome after some calculations.

I’m trying to use grasshopper to calculate the waterline on the hull of a boat.
Here’s my thought process on getting the waterline:
First I calculate the weight of the boat and any added weight to the boat. This is converted into cubic feet of water displaced.

Then a plane is created offset from the origin such that everything below the plane has a volume equal to the volume of water displaced that was previously calculated.

Right now everything works well enough, but I have to manually adjust the plane offset distance (Waterline Height) until the volume under the plane matches the volume calculated in step 1, and then the Brep|Plane intersecting curve is my waterline.

I’m wondering if there is a way I can automate this process so that the plane offset distance is contingent on the outcome of the volume calculation. In addition to being much simpler, it would be far more accurate than I can get with my current system.

Heres the file:
Waterline Calculation Example.gh (27.6 KB)

Any and all ideas are welcome! Thanks!

the answer you are looking for is called ‘Galapagos’ You can find it in Grasshopper (native).
Its a bit hard to explain - best look up some videos and generally ‘Evolutionary Solvers’.
Its made for this kind of problems - and quite easy to use - most of the intimidating interface is decorative if I may say so (sorry david!)

1 Like

in this case I would do something like this:

and after a couple of minutes you will get this result: click on the best genome → reinstate → OK
this will reinstate the slider value that produced that (best) result

2 Likes

dear @Ellsworth_Tocci
a common approach to solve things like this is nested intervals

and this is mostly implemented with recursion.
i would do it with coding / scripting.
But you can do in in grasshoper using for example Anemone | Food4Rhino
kind regards -tom

1 Like

Yes! I’m looking into Anemone now, I think that’s closer to what I had in mind. I can walk the offset distance up in a loop until it passes the threshold volume. Simpler than the narrowing down of Galapagos. Although now I’m also looking into Galapagos for optimizing hull shape! Great tools, great solutions! Thanks everyone!

dear @Ellsworth_Tocci

i would recommand to use solids / closed polysurfaces from the beginning.
Then booleanIntersection (solid intersection in grasshopper) is fast to get a volume.
I read somewhere, that Anemone is having problems with clusters - so i did not use them to organize the script inside the loop.
notice that volume calculation is not accurate for open polysurfaces

my definition does the following:
given a closed Brep
it searches for a z-level, to have a certain percentage of volume above.
the current parameter is set to 0.30 - so 30% of the volume is above the result

you can give a maximum number of loops. currently 14.
you can give a tolerance / threshold - that is currently a percentage of the entire height - did not spent more time on this.

i hope that my nameing / grouping in the file explains more.

search_z_to_split_volume.gh (49.2 KB)

kind regards -tom

1 Like

Hi all!
I’ve put up a short dumb script that change a slider value searching for the minimum “score”.
Like a small galapagos, but for a single slider.
Max 500 attempts, n=number of initial division of the slider full interval.
Always minimize score, to maximise just put a negative components before.
Works best when the relation between slider value and score is a nott-too-much-complex function.
If the function have a lot of similar “turning points” or “Inflection points” it is harder for this script… give a starting high n if so.
Accuracy limited to slider decimals.
Grasshopper numbers would be much more accurate.

(making /100000 to use the full accuracy of a slider to find nearest to Pi…)

simple searcher V0.1.gh (9.3 KB)

Waterline Calculation Example.gh (31.4 KB)

PS
Passing numbers through panels will make you lose precision.

Panels do not show all decimals, and if you use the panel output as number, what was removed is removed.

4 Likes