Find best fitting rectangle to closed planar curve

Hi there,

I have multiple closed curves that are roughly rectangular like this:
image

As the title suggest, I’m wondering if someone already has a script or ideas for one, which basically replaces these with “perfect” 4-point rectangles with the same orientation and total surface.
I was going to find the curve center and create a rectangle with the given size, but got stuck finding an elegant way to find the correct rotation angle.

Thanks in advance for any suggestions. :slight_smile:

It wouldn’t be very difficult in Grasshopper.

1 Like

FWIW, here is a flat 2d rectangular minimum bounding box script.

XYMinBoundingRectangle.py (3.4 KB)

2 Likes

@martinsiegrist @helvetier I’ll look into your example, but at first glance it obviously does not yield the same area as the original curve.
Again, I’m not looking for the smallest bounding box, but for the one with the same area. Although I guess I could probably scale down your results slightly and get a good result.

So thanks! :slight_smile:

1 Like

I didn’t read carefully and didn’t notice the surface goal.

Here’s an adjusted definition using Galapagos to minimize the difference in area.

polyline_to_rectangle_galapagos.gh (23.1 KB)