private Point3d?getInnerBoPoint() { Point3d?innerP = Utility2d.getPoint("\n请指定内边界内一点:"); if (innerP == null) { return(null); } return(innerP); }
public static KeyValuePair <Point3d, Vector2d>?getLeftMost(Point3d innerP, List <Autodesk.AutoCAD.DatabaseServices.Line> ll, PLDictionary plDic) { try { Point3d? startP = Utility2d.getBoStartPoint(innerP, ll, plDic); Vector2d?startV = plDic.getStartVector(startP); if (startV == null) { return(null); } return(new KeyValuePair <Point3d, Vector2d>(startP.Value, startV.Value)); } catch (System.Exception ex) { } return(null); }
//从直线集合中计算外围边界,直线在相交处都是打断的。得出的边界用点列表表示 public static List <Point3d> getOuterBoundaryFromLine(ObjectId[] ids, Point3d?innerP) { List <Point3d> ret = null; try { PLDictionary plDic = new PLDictionary(); // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor ed = acDoc.Editor; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // Open the Block table record Model space for write BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; List <Autodesk.AutoCAD.DatabaseServices.Line> ll = new List <Autodesk.AutoCAD.DatabaseServices.Line>(); DBObjectCollection acDBObjColl = new DBObjectCollection(); for (int i = 0; i < ids.Length; i++) { if (ids[i].ObjectClass != RXClass.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line))) { continue; } Autodesk.AutoCAD.DatabaseServices.Line line = acTrans.GetObject(ids[i], OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Line; ll.Add(line); } ll = ll.Distinct(new My.CompareLine()).ToList();// as List<Autodesk.AutoCAD.DatabaseServices.Line>; plDic.Add(ll); KeyValuePair <Point3d, Vector2d>?kvp = null; if (innerP == null) { kvp = plDic.getLeftMost();//外部边界起始 } else { //内部边界起始 kvp = Utility2d.getLeftMost(innerP.Value, ll, plDic); } if (kvp == null) { return(null); } Point3d startP = kvp.Value.Key; Point3d curP = kvp.Value.Key; Vector2d curV = kvp.Value.Value; List <Point3d> plist = new List <Point3d>(); plist.Add(curP); int maxLoopCount = plDic.Count; while (maxLoopCount-- > 0) { Point3d?p = plDic.getMaxAnglePoint(curP, curV); //ed.DrawVectors() if (p == null) { break; } if (p.Value == startP) { break; } curV = new Vector2d(curP.X - p.Value.X, curP.Y - p.Value.Y); curP = p.Value; plist.Add(p.Value); } ret = plist; acTrans.Commit(); } } catch (System.Exception ex) { } return(ret); }