Sweep Plane until Lower Section has a certain volume

This isn’t really correct - Optimisation can give you answers as precise as needed (within the limits of floating point precision), provided everything is set up correctly.

To go back to my earlier point about root finding though - using Kangaroo here feels like a bit of a sledgehammer to crack a nut.

The original question is essentially a 1 dimensional search where we have a single scalar valued parameter to optimise for a single scalar output. So a root-finding algorithm is what’s needed.
What’s more, we know the plane must lie somewhere between the top and bottom of the solid, so we can use bracketing methods which can be very efficient.

The simplest of these is bisection, where you chop the search domain in half each time. For faster convergence we can use various types of interpolation instead of just halving it.
I made an example trying both Bisection and Brent-Dekker root finding:
volumeportion_rootfind.gh (57.0 KB)

Here you can see it finds the plane height to split a shape at to give an accurate volume in a few ms.

(I think this same root finding code could come in handy anywhere you have this sort of optimisation of a single value where the root lies between known bounds. Just replace the ‘SliceVolume’ class here with the thing you want to optimise for)

7 Likes