Rotate multiple elements randomly around own centre

Hi everyone!

I’m very new and I’m not even sure I’m posting in the right place…
I have nearly zero knowledge of grasshopper and I’m not sure where else to look.
I have a series of elements I need to rotate randomly around their own axis, they’re way too many to rotate them one by one and I’m pretty sure grasshopper would be a big help if only I knew how to…

Thanks to you all

What type of geometry. Please post files and read here:

Hi @Michael_Pryor
That’s how new I am, I haven’t figured out how to upload stuff!
Let’s give it another try… It’s a wetransfer file because it seems to be too heavy for the site.

This is my Rhino file, under "surfaces’ I have a bunch of curved surfaces that are the base of the whole thing.
On top of them, I have arrayed the single elements that should compose them, but I don’t want them all flat, it’s a screen, so I need them to rotate each on their own axis, possibly either 30/60 or 90 degrees. Randomly is ok for now
This is a picture of a project where they’ve done it to give an idea…

Hope any of this makes sense…
Thanks again

Since you’re new to Grasshopper, I feel I should tell you that GH typically doesn’t operate on the objects in a 3dm file. You can import shapes from Rhino into Grasshopper, and you can ‘bake’ shapes from Grasshopper into Rhino, but rotating objects in Rhino is not possible with the standard toolset. I think there are plugins that allow you to ‘replace’ the shape inside a Rhino object though.

Still, this may not be an issue for you, perhaps you’re happy to just bake a whole bunch of randomly rotated shapes into a different layer.

The meat of the problem lies in figuring out the axis for each object. If that’s simple, i.e. they are all the same or at least all mathematically easily defined, then you’re good to go. If not, it will depend on the shapes how difficult this will be (haven’t looked at your file yet).

Do you want to rotate the objects through a random angle, or do you want to a random subset of objects through a fixed angle?

Hi David! Thanks a lot for your reply!
Unfortunately, my objects are all arrayed along many curves, all different from each other, so I’m trying to make the panels on grasshopper rather than hope it turns the panels I made before on Rhino.
So far I figured how to make the panel and how to array it along a straight line, no clue how to array it along my curves though.
Rotating them is still a mystery.
Ideally I would like to rotate about half of the panels, chosen randomly, a set angle (90^ to make my life easier for now). If that’s easier, I’m also ok with rotating a random subset of panels for now.

Am I making any sense?

Dangerous question :slight_smile:

“Ideally I would like to rotate about half of the panels, chosen randomly” and “I’m also ok with rotating a random subset of panels” are the same thing, so that’s a bit confusing, but I get what you want now.

Your panels all seem to be box-shaped. They all have the same dimensions? They all have the same gap length between them? Or are the gaps variable and do you want to have panels neatly aligned on both ends of the curves?

The panels are slats of stone or wood, so all the same size (100x500x10mm) and distance between each other (10mm), but they need to repeat along the curves I already designed in Rhino and then some of them should rotate 90^.
So I can’t simply divide the curves, or the panels end up being different from curve to curve. (27.1 KB)

Quite a few steps, but it may be a start. The steps in this algorithm are:

  1. Import or otherwise specify the curves.
  2. Flip curves using a single guide line, so they all point in the same direction. This may or may not be important, I wasn’t sure.
  3. Divide the curves into [panel width] and [gap width] patterns. I used the Dash Pattern component since it makes this really easy, however it measures the length along the curve, not straight in xyz space. You may need to switch to a Divide Distance approach instead, where the distance is panelWidth+gapWidth.
  4. Figure out the start and end-point of all dashes. The panels will be centred on the startpoints and their direction is controlled by the end-points.
  5. Create World XY planes on the start points. I recommend setting your plane preview size to about 50 for a file with these units. You can do this in the Grasshopper Display menu.
  6. Align the planes using the span vector of all the dash curves. This will orient your panels correctly.
  7. Create rectangles of the correct width and height on each aligned plane.
  8. Extrude these rectangles to the correct height, giving you all the panels.
  9. Generate lists of random integers in the range zero to one. So for example if one curve yielded twelve panels, you’d want a list with twelve zeroes and ones, randomly distributed. (There’s a complication here, see bottom of post for further details).
  10. Multiply your zeroes and ones with your rotation angle. This means you now have a list of angles, some of which are zero because they were multiplied by zero, others are the correct angle since they were multiplied by one.
  11. Finally rotate your panels using the angles and the already computed planes.

Randomness (which is important to you in this case) is a lie in computers. It is impossible to generate really random numbers using deterministic machines. Instead, there are algorithms which generate pseudo-random numbers which typically look random enough to pass. We're not concerned with international-bank-transfer-cryptography here so who cares if it's not really random right?

A pseudo random number sequence is associated with a seed value, which is always an integer. Every seed always yields the exact same pseudo-random numbers. This is actually quite handy for people like us since we don’t necessarily want different panels to randomly stay in place or rotate each time we open this file. Repeatability is actually sort of a blessing.

Now, since you have a bunch of facade groups, you’d have to pick different seed values for each one otherwise they’d all exhibit the same ‘random’ pattern. You can absolutely do this, but I chose a different approach. Instead of generating N different lists of random values using N different seeds, I generated a single huge list of random values and then broke that one list into N shorter lists again. This can be done easily using the Unflatten component.

Ok, your explanation is extremely clear and detailed, I actually believe I understood most of it! It’s pretty amazing, thank you so much!!
I honestly thought it would require way less steps, silly noob…
And no, I couldn’t care less about the actual randomness of the elements that rotate, as long as it’s not something like “every third row” or something, I’m a happy bear.

One small thing, though. The panels all rotate around one of the extremities, is there any chance they can rotate around their axis instead? That would be pure perfection…

Either way, you’re my knight in shining armour tonight <3

Sure, you’ll either have to specify a different plane for the rotation, or already specify a different plane for the initial rectangles. If you average the start and end-points of the dash curve segments, you’ll get a point halfway in between them. You will also have to change your rectangle X-size though, it’ll have to go from negative-half-width to positive-half-width instead of from zero to full-width. I already do exactly that for the rectangle Y sizes, so you just have to copy that for X as well.

Oh, I made it!! Thank you so much, you’re a saint!!

Hi again! Any chance I can ask one more stupid question?

I played around with your script yesterday (and probably committed a few crimes against common sense while doing so…) because I needed my panels to have different heights in order to cover all the surfaces and so far it worked. Yes, there was definitely a better way of doing it, but that will be lesson number two…
Now I’m trying a different approach and keeping all my panels 750 high, but arraying them a different amount of times depending on the height of the curve (one to four times, that’s why there are 4 repetitions… if you look at the Rhino model the curves are divided based on height of srf).

I followed a tutorial yesterday and it worked on its own, but I can’t understand how to connect it to my existing script, as soon as I do shapes go wild.
I’m imagining it has to do with the random function, but I really don’t know how to mess with that…
Here are the gh file and the model

panels (27.6 KB)

190122_Op2 curves.3dm (1.9 MB)