Hi, I need to determine whether an area intersects with another area.
For example, as you can see the picture below...
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.)
Solved! Go to Solution.
Solved by _gile. Go to Solution.
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"); } }
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.