Finding the domain of an irregular rectangle

irregular_shape_domain.gh (36.6 KB)

Hi everyone, I couldn’t solve a problem so I created this sample file to ask. So I have the outer inner rectangular boundaries which can change (size and + the movement of the smaller rectangle). And I have a smaller rectangular curve that needs to be placed in this area and never outside even and especially when the size of it changes. I tried to use domain etc. but I couldn’t do it. I’m sure there is a simple solution but can’t find it. Anyone can help?

You’re going to need to draw a diagram…

The object in the .gh file must remain within this designated area. Its movement is restricted to the green hatched region. However, the size and position of R1 (Rectangle 1) and the size of R2 are variable, so the object must always stay within the subtraction of these 2 rectangles. For instance, if the object is too large for certain sections of the area, it should not be able to move there. Ideally, the object’s size could adjust automatically to fit available spaces, but this may be not necessary for now or complicated a bit.

Okay, and it must A) stay as close as possible to a desired point, or B) be centred in the available space?

This is not a complex problem as such, but it’s hard to generalise, so it’s best to know the constraints before making a solution that does more work than necessary!

Yes, it can be adjacent to either R1, R2, or located in the center without any adjacent line. However, its movement should be based on the grid system bay (1.22 x 1.22), as specified in the GH file. For example, a single movement in the x-direction equals 1.22 in x, and the same applies to y. These movements are already defined in the GH file. All changes in the movements and sizes should be minimum 1.22 or multiplication of this value. I actually have more objects like this and I will use the same logic to others. Also, you can think of these R1 and object as rooms and R2 is the house perimeter to better visualise. Thank you!

Ah! If there will be additional objects, then this stops being a simple “which dimension is bigger” question and becomes far more open ended. Each additional room effectively multiplies the number of variables. You might find a solution for A+B that prevents C from fitting, but if you found A+C first, B would fit no problem. Although restricted to a grid, this is the Rectangle Packing Problem, which is not trivial and can’t be solved with standard Grasshopper components. You should check out the OpenNest plug-in, available via the package manager, which I think can do this.

In terms of your grid though, I would do all the logic with 1x1 squares and scale objects up by 1.22 at the very end. It will make things much easier to understand.

Thank you for the suggestion I know the OpenNest. But I just want to restrict the movement of the object only in the green area, nothing else. The other rooms are not the case now.

irregular rectangle

Isn’t that a contradiction in terms?

Yes sorry it should be “irregular shape” not “rectangle” :grin: