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:
The curves must ‘close’ to create what would be a loop.
The angle between each ‘pair’ of curves must be either 40, 50, or 60 degrees.
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.
Well … the only tricky part is the angles related thing:
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).
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.
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.
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:
Do some closed Polyline and take care to be clockwise.
Get the Vertices (as V List). Get their count as VC.
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).
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.