Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
rosti

Largest rectangle within polygon or polyline

Recommended Posts

I would like to know the largest orthogonal rectangle to fit within any handled polygon or polyline. 

Within that one might fit a textblock or other. 

 

Could I script this using VectorScript?

Edited by rosti

Share this post


Link to post

Can an Vectorscript solve this problem? The answer is yes.

If you ask for a Vectorscript function for that: The answer is no.

 

And the task is not really clear. You want to find the widest rectangle with the height x? Or you want the have the rectangle with the largest area? Or the widest Rectangle which height is minimum 20% (or some kind like this) of the width?

 

I think the simplest way would be, to make a grid over your polygon. Then you have rows and columns. With that, you could generate the biggest, the widest and the highest recangle. 

 

Not sure, but I think this could be a possible approach. I would do that with python script. There seems to be solutions available on the net. As example here:

https://gist.github.com/zed/776423

 

This code for that looks quite simple. Maybe that script has to be adjusted. As example store the start endpoint of the rectangle inside the script. At the moment this just returns max area, width and height not the position.

 

Interesting and useful task ...  

 

 

Which rectangle?.png

Share this post


Link to post

Thank you for replying,

 

Nice image too. 

I had a look at the python script, and it might take me in between a day or maybe a year to understand. 

I will try, but I don't know when I can react on that. 

I assume there are matrix-steps add by each loop until a border is hit somewhere. 

Is that how  a program like Vectorworks renders the fills of polys on screen? 

 

 

 

As a routine for a task like this could serve many cases, I tried not to be that clear. 

In my case I was thinking of a way to find the ideal location of a generated text informing about different rooms or spaces.

If you want the text to be as large as possible, in a circle or square you might locate it at its center.

If you think of a L-shaped room or curved space, the ideal location, could be found by the eye, but to calculate it might be harder.  

 

So for instance for the L-shaped room, using the eye, you would opt between 2 rectangles, and pick the largest and maybe rotate the text 90 degrees. 

 

In case of your image you might opt for the red one.  

 

Looking at the image, I would say as next step could be to compare some initial ratio of the text, by knowing its content, and try to fit such a rectangle best.

So:

Say a rectangle like the green one might have the best ratio, then have the actual text object centered at that green rectangles midpoint. 

After that size of the green rectangle and the text block might reduce the font size, to have it fit, or if the font would get to small to read, you have to, still, move it outside the area by using a pointing device of choise.

yo.png.8a11e4a6b530f02bd756b946ced0d5cb.png

Maybe someone might want to place a symbol within the room. Maybe there might be a hole in the room, or worse.

 

design-by-btrdv.png.5957ba808d70c4185544f305f94152fd.png

 

 

 

 

 

Edited by rosti

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×