"Random" Looped Curves with Rules

Hello

I am trying to create a “random” set of looped curves within a specific volume area. I put random in parenthesis because while I want to generate different sets of curves based on a seed input, but they each need to follow a set of rules / kangaroo goals:

  1. The curves must ‘close’ to create what would be a loop.
    image

  2. The angle between each ‘pair’ of curves must be either 40, 50, or 60 degrees.

  3. I need to be able to control the height variation of the vertices that are used to create the lines. More specifically, I need to be able to specify if they should all be on the same horizontal plane OR have a specified range to move up / down to give some variation between z positions.

I have attached what I have achieved in Grasshopper so far but having some continuous errors.

Loop_Fixed Lengths Angles and Heights.gh (46.6 KB)

Better way to achieve this? Different goals?

Thanks

Well … the only tricky part is the angles related thing:

  1. Assume that you have a pool of random poly angles. Assume that you are after N segments (meaning that the sum of angles is (N-2)*Math.PI).
  2. So the question is: how to sample items (with a user defined flag/option: allow repetitions or not) from the pool where their sum is a given number (or better: the sum is within a given Interval). Obviously IF there’s a possible solution (not a given) around. Very easy via code … rather impossible without.
  3. See this classic “conditional combos” case: given a rnd collection of numbers (cyan List) … find all the combos where their sum is withing some user defined Interval.

The code for that is rather elementary:

So if you are interested for a C# solution (meaning pure code, no components etc etc) I could provide an entry level one.

I am very new to C# so if you could provide somewhere to start that would be great!

Thank you

Er … hmm … the combination Methods captured above are rather simple/entry level … but are NOT the thing for a novice - by any means. So start walking the C# walk and forget LINQ stuff like that (at present time).

In the mean time practice:

  1. Do some closed Polyline and take care to be clockwise.
  2. Get the Vertices (as V List). Get their count as VC.
  3. For (int i = 0; i < VC; i++) define triads of pts: the prev as V[(i+VC-1)%VC], the curr as V[i] and the next as V[(i+1)%VC).
  4. Define a plane as Plane.WorldXY and 2 vectors: v1 = prev-curr, v2 = next-curr. The triad angle is Vector3d.VectorAngle(v1,v2, plane). The sum of angles is (N-2)*Math.PI.

So post here a C# that does the above and we’ll see where to go next.

In the mean time get a very naive take on the SubArraySum (with repetitions) problem. Observe that works … when it works (any fate value yields a C# re-execultion) meaning that is rather the wrong girl to date. As a challenge try to “better” the logic.

Combinations_SubArraySums_ForAmateurs_V1.gh (116.5 KB)