Draw Largest Rectangle Possible Within Space

Draw Largest Rectangle Possible Within Space

Anonymous
Not applicable
1,154 Views
11 Replies
Message 1 of 12

Draw Largest Rectangle Possible Within Space

Anonymous
Not applicable

Hey Guys,

 

I don't know if this can be done but I figured I would ask. I am looking for a lisp that will ask a user to select a closed polyline and then have it draw the largest rectangle possible within said closed shape. I need this new rectangle to also account for any existing line/layer/shape within said shape. Essentially I am looking to click the red layer in image 1 and then have the new rectangle pop up (layer black) in image 2 after it is done calculating everything and taking all other layers into account. I guess it's just a big if statement on setting the proposed rectangle to a set layer and then while drawing within the p-line it's set to avoid any intersection with any layer that is not the originally set one? I found some base code here https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/draw-largest-rectangle-within-a-limi... but what it doesn't work on my end and even if it did it doesn't account for other layers/shapes/lines that could be within said p-line. Any assistance is much appreciated!

LispHunt42_0-1626444164998.png

 

0 Likes
1,155 Views
11 Replies
  • Lisp
Replies (11)
Message 2 of 12

LyleHardin
Advisor
Advisor

Sorry this reply will not be helpful, but I find this to be a fascinating exercise. I'm sure someone will come up with something clever. Also, does the rectangle have to be 'horizontal' ? A better fit may be a rotated rectangle. I wonder if Civil 3D's Generative Design feature and Dynamo may be useful for this situation. Won't do much good for plain AutoCAD, though.

 

0 Likes
Message 3 of 12

Anonymous
Not applicable

Any rotation would work!

0 Likes
Message 4 of 12

Shneuph
Collaborator
Collaborator

Interesting... and likely very difficult.  W/o having the dwg.. I wonder if this rectangle may actually have a larger area than the one you drew in?  Definitely longer but narrower.  I also won't be much help in the task of automating this task.  But I'm interested to see what people come up with.

Shneuph_0-1626447645572.png

 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 5 of 12

Anonymous
Not applicable

No DWG needed you could literally just draw any p-line shape and drop some shapes inside, as long as the layers are all different than the rectangle being drawn. Also yes, my point exactly that rectangle probably is bigger (total sqr footage) but that's what I want the command to figure out and do. It will see ideal spots for the largest rectangle that are harder to spot.

0 Likes
Message 6 of 12

LyleHardin
Advisor
Advisor
The more I look at this, the more I think Generative Design is the best solution. (Not the only one, of course.)
It will draw thousands of rectangles based on certain constraints and find the one with the maximum area for you.
Alas, I've not done any Generative Design programming, so I'm of no help there. Sorry.
0 Likes
Message 7 of 12

hak_vz
Advisor
Advisor

@Anonymous 

 

In post that you mention, you may find lisp codes from @CodeDing @marko_ribar and my own try on the subject. From the length of that post you can guess I took us a lot of time and effort to make something that really works. Code was made in accordance to @hs800150 request. At the end solution from @marko_ribar was rightfully selected as final, since he has spent a lot of time bulletproofing  his code. All posted solutions produced similar results regarding largest inscribed rectangle and OP request, and all deserved to be selected as a solution.

Adding test for collisions with internal object is really complex task. To use above mentioned lisps create a single  boundary that joins internal obstacles and you will for sure get largest inscribing rectangle.

I remember that this was one of really interesting requests and I enjoyed working on it, but I probably won't participate in writing more code to fulfill  your request. For a start try my proposal with boundary.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 8 of 12

Anonymous
Not applicable

Very true. I figured it would be very complex. How can I get the referenced code to work though? Even just that part I try it and it just gives me a bundle of scribbles within the pline.

0 Likes
Message 9 of 12

hak_vz
Advisor
Advisor

Based on your sample images your request is really hard to solve. Method that I described in my previous post would work for aligned rectangle and probably give correct answer. Adding rotated rectangle into it really rises level of complexity.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 12

Anonymous
Not applicable

I'm trying to get your old code to work. I want to work off it but I can't get the base command to work properly. Below is a random closed p-line I drew and then I used your "ripl" command and got the following result. Same kind of thing as last time just a jumble.

LispHunt42_0-1626457989967.png

 

0 Likes
Message 11 of 12

hak_vz
Advisor
Advisor

@Anonymous wrote:

I'm trying to get your old code to work. I want to work off it but I can't get the base command to work properly

 


Download code at this link  (post no 37) and use command maxalignedrect. It should work correctly for closed lwpolyline that may contain arc sements (not as aligning edge)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 12 of 12

jadranko
Contributor
Contributor

And criterion for "the largest rectangle possible" is the area, right?

0 Likes