# How to nest Loops? Stability Problem

Hí to all, I´ve been trying to solve a stability problem, where I need a range of situations to be calculated. For a 3D body, I aim to analize its behaviour floating at several heeling (angled repect base state) positions. To that end I did a loop that rotates a plane a certain angle several times (heeling cases) and nested to it a second loop that elevates this plane until the volume of the body its larger than a specific volume (the displacement).

However, the loops do not work as expected, first the plane rotates all at once an once finished its loop the other starts and elevates the plane.
Does the loopsneed some kind of switch that lets the second loop work before repeating one loop? Like a trafic light?

Grasshopper isn’t really designed to play nicely with looping structures. It’s designed to be functional in nature flowing data from left to right without having to worry about complex recursive structures. Some plugins exist to try and force that functionality into it, but in my experience they usually fall apart in some edge cases.

I’m not sure what exactly isn’t working in this particular implementation, but I will give the advice that I’ve always given up troubleshooting loop components in favour of just writing whatever iterative thing I want in a C# component, which doesn’t have the same restrictions.

As Jcb said.

Anyway this (very easy to deal with) is rather pointless to attempt without code (for various reasons).

Given the opportunity what we use in similar problems is a bounce solver approach. For a given target value we start from some “estimated” value (that is extracted - at each later attempt - explicitly via some Method [like Ccx Brep/Mesh/Plane for your case]) and we set a grow/srink state using some start step value . If state is grow (meaning value+= step) and Math.Abs (target - value) > someTolerance and value > target then state is set to srink and step is divited by 2.0 (value -= step) … etc etc. So for each attempt the found value “bounces” around the target value (while the diff/delta becomes smaller and smaller) until the diff/delta is less than the desired tolerance.

Notify if you want an entry level demo C# (but could be 100% useless if you want to address that issue via components).

Concept:

What you want: red is the target volume per Mesh (using Breps>Meshes for speed):

2 Likes

I was aimming to try to solve it using the fancy boxes GH provides . Nevertheless,Thank you very much, I´ll give it a try.

BTW: Better start from some elementary bounce solver task: given Curves that define a BrepFace (the black) and a random pos Splitter (the blue) … find a Splitter pos that yields pieces (the light blue) where their Area Sum is a given value (within soma rational tolerance). All that IF there’s a possible solution around.

Try to “mimic” (hope dies last) this sort of logic: