Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Rectangle Lines

Anonymous
1,157 Views
4 Replies
Message 1 of 5

Rectangle Lines

Anonymous
Not applicable

Any simple method to check whether a polyline or (set of 4 lines) is a rectangle?

0 Likes
Accepted solutions (1)
1,158 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Any code simpler than this?

 

                                bool blnRectangle = false;
                                if (polyline.NumberOfCoordinates == 5) {
                                    if (PointsAreEqual(polyline.GetCoordinate(0), polyline.GetCoordinate(4))) {
                                        Line line1 = Line.CreateBound(polyline.GetCoordinate(0), polyline.GetCoordinate(1));
                                        Line line2 = Line.CreateBound(polyline.GetCoordinate(1), polyline.GetCoordinate(2));
                                        Line line3 = Line.CreateBound(polyline.GetCoordinate(2), polyline.GetCoordinate(3));
                                        Line line4 = Line.CreateBound(polyline.GetCoordinate(3), polyline.GetCoordinate(4));
                                        if (DoubleValuesAreEqual(line1.Length,line3.Length) && DoubleValuesAreEqual(line2.Length, line4.Length)) {
                                            double dblRad = line1.Direction.AngleTo(line2.Direction)/Math.PI;
                                            if (DoubleValuesAreEqual(dblRad, 0.5))
                                                blnRectangle = true;
                                        }
                                    }
                                }
0 Likes
Message 3 of 5

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

You can create curveloop from your lines, than perform a check:

 

curveloop.HasPlane() && curveloop.IsRectangular(curveloop.GetPlane())
Message 4 of 5

Anonymous
Not applicable

The method is simple. Thanks.

Anyway to check lines is a curve loop is not so simple, right? Smiley Sad

0 Likes
Message 5 of 5

aignatovich
Advisor
Advisor

Yep, but It depends on your task, may be some factors will help you.

 

Polyline coordinates are subsequent, so they form the curveloop, but it can be open, check curveloop.IsOpen() also