Author Topic: Overlapping closed polylines  (Read 2538 times)

0 Members and 1 Guest are viewing this topic.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Overlapping closed polylines
« on: October 18, 2011, 03:48:02 PM »
Wondering what the best way to find over lapping polylines is.  All lines are at the same elevation and same layer. I want them to be touching on at least one side but not over lapping. Any ideas?

Right now I'm leaning toward creating elevated solids on top of each polyline and checking interference. Just wondering how the pros would do it.
« Last Edit: October 18, 2011, 04:00:45 PM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

BuckoAk

  • Newt
  • Posts: 69
Re: Overlapping closed polylines
« Reply #1 on: October 18, 2011, 10:35:27 PM »
Give the command "Overkill" a try

kaefer

  • Guest
Re: Overlapping closed polylines
« Reply #2 on: October 20, 2011, 05:37:00 PM »
Right now I'm leaning toward creating elevated solids on top of each polyline and checking interference. Just wondering how the pros would do it.

Talk about overkill.

Never dreamed of how easy it is to perform boolean operation on Regions. I wouldn't consider myself pro, but even for this part-timer your proposal was one dimension too much. There may be other approaches like checking for transversality at intersection points, and I may be missing something here; but provided for coplanarity we'll just check the intersection area.

Code: [Select]
        double? plIntersect(ObjectId oid0, ObjectId oid1)
        {
            double? area = null;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            using (DBObjectCollection csc0 = new DBObjectCollection())
            using (DBObjectCollection csc1 = new DBObjectCollection())
            {
                Polyline pl0 = (Polyline)tr.GetObject(oid0, OpenMode.ForRead);
                Polyline pl1 = (Polyline)tr.GetObject(oid1, OpenMode.ForRead);
                try
                {
                    pl0.Explode(csc0);
                    pl1.Explode(csc1);
                    using (DBObjectCollection rec0 = Region.CreateFromCurves(csc0))
                    using (DBObjectCollection rec1 = Region.CreateFromCurves(csc1))
                    {
                        if (rec0.Count == 1 && rec1.Count == 1)
                        {
                            Region re0 = (Region)rec0[0];
                            re0.BooleanOperation(BooleanOperationType.BoolIntersect, (Region)rec1[0]);
                            area = new double?(re0.Area);
                        }
                    }
                }
                catch
                {
                }
                tr.Commit();
            }
            return area;
        }

Since we're dealing with a tri-state value, the calling site could be like this:
Code: [Select]
                        double? res = plIntersect(per0.ObjectId, per1.ObjectId);
                        string msg =
                            res == null ? "\nThere's a problem somewhere. " :
                            res > 0.0 ? "\nThe polylines do intersect. " :
                                "\nThe polylines don't intersect  ";


MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Overlapping closed polylines
« Reply #3 on: October 21, 2011, 09:59:51 AM »
Thanks kaefer, you saved me a step. I was taking the regions and creating solids with them but if your code works I can stop and just compare the regions.

I found through studying different polygon algorithims this week that this is the easiest way of doing it in autocad. Hey, but I now understand the Vatti algorithim and the Greiner Hormann algorithim.
Revit 2019, AMEP 2019 64bit Win 10