Author Topic: how to find itersection points  (Read 1562 times)

0 Members and 1 Guest are viewing this topic.

xsakabsx

  • Guest
how to find itersection points
« on: October 04, 2012, 06:21:54 AM »
how to find intersection point of polyline and cirle ?

Sorry for bad ENG (rus to eng)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: how to find itersection points
« Reply #1 on: October 04, 2012, 06:47:48 AM »
Hi,

Look at the Entity.Intersectwith() method.

Here's a little C# sample:

Code - C#: [Select]
  1.         [CommandMethod("Test")]
  2.         public void Test()
  3.         {
  4.             Document doc = AcAp.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;
  7.             PromptEntityOptions peo = new PromptEntityOptions("\nSelect the first curve: ");
  8.             peo.SetRejectMessage("Only a curve !");
  9.             peo.AddAllowedClass(typeof(Curve), false);
  10.             PromptEntityResult per = ed.GetEntity(peo);
  11.             if (per.Status != PromptStatus.OK) return;
  12.             ObjectId id1 = per.ObjectId;
  13.             peo.Message = "\nSelect the second curve: ";
  14.             per = ed.GetEntity(peo);
  15.             if (per.Status != PromptStatus.OK) return;
  16.             ObjectId id2 = per.ObjectId;
  17.             using (Transaction tr = db.TransactionManager.StartTransaction())
  18.             {
  19.                 Curve curve1 = (Curve)tr.GetObject(id1, OpenMode.ForRead);
  20.                 Curve curve2 = (Curve)tr.GetObject(id2, OpenMode.ForRead);
  21.                 Point3dCollection pts = new Point3dCollection();
  22.                 curve1.IntersectWith(curve2, Intersect.OnBothOperands, pts, 0, 0);
  23.                 BlockTableRecord ms = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  24.                 foreach (Point3d pt in pts)
  25.                 {
  26.                     ed.WriteMessage("\n" + pt.ToString());
  27.                     Circle c = new Circle(pt, Vector3d.ZAxis, 10.0);
  28.                     ms.AppendEntity(c);
  29.                     tr.AddNewlyCreatedDBObject(c, true);
  30.                 }
  31.                 tr.Commit();
  32.             }
  33.         }
Speaking English as a French Frog