How to check if a curve is a rectangle


check if polyline is rectangle.gh (8.8 KB)

I only want to select the closed polygons which are rectangles. I tried checking for number of segments but some of the curves have control points which are colinear, thus increasing the segment number. How should I approach this?

compare the area (and centroid as area might give false positives) of the polygon with its bounding box

1 Like

You could count the discontinuities:

2 Likes

Both areas and centroids are giving false positives. Tolerances are causing issues :confused:

Thank you so much this works perfectly!

1 Like

you have MANY of these non-rectangular shapes… do you want those to be considered rectangles? or are those the ones you are trying to delete?

1 Like

I would want them to be considered rectangles only. These are drafting errors that I do forsee happening by users of the script. @Baris idea to use discontinuities gives what I expect to consider a ‘rectangle’ even though it might not mean the actual geometric definition (90 degrees and equal adjacent sides)

This is obviously not a rectangle, eh.

Neither is this:

1 Like

Haha true true. Well this script is a small part of a much larger script for automating room labels in architecture plans. The kind of spaces my users will be dealing with right now will always resemble rectangles (even if they aren’t rectangles) so this will work for now.

Over the course of developing this script I have found that I don’t need to consider every possible edge case right at the beginning of developing a feature, because most of the times the edge cases are geometry related and the script will mostly always be operating on orthogonal geometries.

But thanks a lot, I have much more clarity on discontinuities now, and when something messes up I will know what it is!

are you playing the ok, now use your script with this data game?
The script was inteded for the provided test data and not for any possibly imanigable data.

I just checked, a lot of objects are far awya from the origin, which is never good. Maybe use the Similiarity module, which allows you to set a threshold. They are necessary anyway, if you have slightly off 90° angles and want to capture them.

No, but if that’s your game…


detect_rectangles_2024Oct9a.gh (31.1 KB)

check if polyline is rectangle.gh (18.0 KB)

Or maybe this one? But the text panel list of True / False isn’t very useful without labels…


detect_rectangles_2024Oct9b.gh (30.8 KB)

Create a Bounding Box around each rectangle and check if the area of the rectangle matches the area of his corresponding Bounding Box.
check if polyline is rectangle.gh (16.8 KB)

Looks like only the items 2 and 5 from your list are perfect square rectangles.

they also could be rotated, since BBox is aligned with the world coordinates.
Maybe creating a rectangle from 3 pts and check the area/Length could work.

This one uses a Vipers component to create a rotated Minimal BoundingBox. I also replaced the Equality with similarity with tolerance.


check if polyline is rectangle_re.gh (15.7 KB)

1 Like

Hi @Kyuubimode,

This cluster checks for a closed four sided curve where all angles are around 90 degrees.

Only {0}(2) is a rectangle.

CurveIsRectangle.gh (10.9 KB)

Doing comparisons in serial instead of in parallel should perform better on a huge model.

CurveIsRectangle-Serial.gh (19.2 KB)

1 Like