.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Efficient way to determine whether an area intersecting another area?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
dynamicscope
980 Views, 8 Replies

Efficient way to determine whether an area intersecting another area?

Hi, I need to determine whether an area intersects with another area.

For example, as you can see the picture below...

 

2013-04-15 09;18;24.PNG

 

The left case can be easily determined by Polyline.IntersectWith(Polyline...).

But in the right case, the two polygons intersect/overlap each other while polylines do not intersect.

What would be the effiicient way to determine the right case polygons are intersecting polygons?

 

If someone can help me with a simple sample code (preferably in C#), it would be very appreciated.

Thank you very much in advance.

 

(FYI, I am currently using ObjectARX 2007.)

8 REPLIES 8
Message 2 of 9
Hallex
in reply to: dynamicscope

Not sure about if this will be works in 2007

tested on A2010:

        [CommandMethod("care")] 
        public void checkAreasIntersect()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            bool yeah=false;
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {

                ObjectId id1 = ObjectId.Null;
                ObjectId id2 = ObjectId.Null;

                PromptEntityOptions peo = new PromptEntityOptions("\nSelect first area >>");
                peo.SetRejectMessage("\nSelect Polyline only");
                peo.AddAllowedClass(typeof(Polyline), false);
                PromptEntityResult res;
                res = ed.GetEntity(peo);
                if (res.Status != PromptStatus.OK) return;
                id1 = res.ObjectId;

                peo.Message = "\nSelect second area >>";
                res = ed.GetEntity(peo);
                if (res.Status != PromptStatus.OK) return;
                id2 = res.ObjectId;
               
                        Entity en1 = tr.GetObject(id1, OpenMode.ForWrite) as Entity;
                        if (en1 == null) return;

                        Entity en2 = tr.GetObject(id2, OpenMode.ForRead) as Entity;
                        if (en1 == null) return;

                        DBObjectCollection exids = new DBObjectCollection();
                        en1.Explode(exids);

                        foreach (DBObject obj in exids)
                        {
                            Entity en = obj as Entity;
                            Point3dCollection pts= new Point3dCollection();

                            en.IntersectWith(en2, Intersect.OnBothOperands, pts, 0, 0);
                            if (pts.Count != 0) {  yeah=true;break;  } 
                          
                            }
                        ed.WriteMessage("\nAreas were {0} an intersection", yeah ? "has" : "doesn't have");
                        }

                    }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 9
dynamicscope
in reply to: Hallex

Thank you, Hallex. 

 

I tried with the code, but it couldn't handle the right case.

So, I changed the code a little bit and tried again.

 

//en.IntersectWith(en2, Intersect.OnBothOperands, pts, 0, 0);
en.IntersectWith(en2, Intersect.ExtendThis, pts, 0, 0);

 

Well, this could handle the right case but also creates another issue.

It will consider the following case as the intersecting polygons as well.

 

2013-04-15 17;12;40.PNG

Message 4 of 9
_gile
in reply to: dynamicscope

Hi,

 

What about creating regions from the polylines, operate a boolean union and compare the region area with the sum of the polylines area ?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 9
dynamicscope
in reply to: _gile

That looks working. I will try it out. Thank you.
Message 6 of 9
DiningPhilosopher
in reply to: _gile

Works if the polylines aren't self-intersecting, and you probably can just check for inner-loops in that case
Message 7 of 9
dynamicscope
in reply to: _gile

Do you know if there is any method that is related to Union command? I need to compute the area of intersecting region. So I am planning to do Region1 + Region2 - UnionRegion = IntersectingArea. I need to do this programmatically (no user interaction).
Message 8 of 9
_gile
in reply to: dynamicscope

Hi,

 

Look at the Region.BooleanOperation() method.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 9
dynamicscope
in reply to: _gile

Great~!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost