Rectangle Lines

Anonymous

Rectangle Lines

Anonymous
Not applicable

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

0 Likes
Reply
Accepted solutions (1)
1,127 Views
4 Replies
Replies (4)

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

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

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

 

curveloop.HasPlane() && curveloop.IsRectangular(curveloop.GetPlane())

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

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