public List <Point3d> toPoints() { if (segments == null || segments.Count <= 0) { return(null); } List <Point3d> r = new List <Point3d>(); TBPoint start = this.startPoint; LoopSeg previousSeg = segments[0]; r.Add(start.acPoint); r.AddRange(previousSeg.getInnerPoints()); LoopSeg nextSeg = previousSeg; for (int i = 1; i < segments.Count; i++) { nextSeg = segments[i]; r.Add(nextSeg.startPoint.acPoint); r.AddRange(nextSeg.getInnerPoints()); previousSeg = nextSeg; } r.Add(nextSeg.endPoint.acPoint); return(r); }
public double scanAngle(TBPLineSegment second, TBPoint interPoint) { Point3d p1, p2, p3; TBPLineSegment s1 = null; TBPLineSegment s2 = null; if ((interPoint == this.StartPoint) && (this.StartPoint == second.StartPoint)) { s1 = this.newReverse(); s2 = second; } else if ((interPoint == this.StartPoint) && (this.StartPoint == second.EndPoint)) { s1 = this.newReverse(); s2 = second.newReverse(); } else if ((interPoint == this.EndPoint) && (this.EndPoint == second.StartPoint)) { s1 = this; s2 = second; } else if ((interPoint == this.EndPoint) && (this.EndPoint == second.EndPoint)) { s1 = this; s2 = second.newReverse(); } p1 = s1.acPline.GetPointAtParameter(this.acPline.EndParam - 1); p2 = s1.EndPoint.acPoint; p3 = s2.acPline.GetPointAtParameter(1); return(AngleUtil.scanAngle(p1, p2, p3)); }
public TBPoint nextPoint(TBPoint previousPoint) { TBPoint r; nextPointDic.TryGetValue(previousPoint, out r); if (r != null) { this.nextPointDic[previousPoint] = null; } return(r); if (previousPoint == this.StartPoint) { if ((hadProcessed & 1) == 1) { return(null); } return(this.EndPoint); } else if (previousPoint == this.EndPoint) { if ((hadProcessed & 2) == 2) { return(null); } return(this.StartPoint); } else { throw new System.Exception("TBPLineSegment 117"); } }
public TBPLineSegment(Polyline3d pl, TBPoint s, TBPoint e) { acPline = pl; startPoint = s; endPoint = e; nextPointDic = new Dictionary <TBPoint, TBPoint>(); nextPointDic.Add(startPoint, endPoint); nextPointDic.Add(endPoint, startPoint); }
public static Loop getBoundary(TBPLineSegment startSeg, object userData) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Loop resultLoop = new Loop(); resultLoop.userData = userData; List <LoopSeg> loopSegs = resultLoop.segments; //result2 = new List<Point3d>(); //result.Add(startSeg); double scanAngle = 0; TBPLineSegment previousSeg = startSeg; TBPoint startPoint; TBPoint nextp = startSeg.nextPoint(out startPoint); if (nextp == null) { return(null); } scanAngle += startSeg.scanAngle(startPoint); //result2.Add(startPoint.acPoint); loopSegs.Add(new LoopSeg(startSeg, startPoint)); resultLoop.startPoint = startPoint; while (nextp != null) { TBPLineSegment nextSeg = nextp.nextSegment(previousSeg); if (nextSeg == startSeg) { throw new System.Exception("TraceBoundary 39"); } scanAngle += nextSeg.scanAngle(nextp); scanAngle += previousSeg.scanAngle(nextSeg, nextp); loopSegs.Add(new LoopSeg(nextSeg, nextp)); nextp = nextSeg.nextPoint(nextp); if (nextp == null) { return(null); //throw new System.Exception("TraceBoundary 44"); } previousSeg = nextSeg; if (nextp == startPoint) { scanAngle += previousSeg.scanAngle(startSeg, startPoint); break; } } resultLoop.scanAngle = scanAngle; if (resultLoop.segments.Count <= 1) { } if (scanAngle <= 0) { ed.WriteMessage("\nangle:" + scanAngle + "\n" + startSeg.toString()); } return(resultLoop); }
public void calcIntersection(TBPLine tbpline) { Point3dCollection result = new Point3dCollection(); acPline.IntersectWith(tbpline.acPline, Intersect.OnBothOperands, new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)), result, (IntPtr)0, (IntPtr)0); for (int i = 0; i < result.Count; i++) { Point3d p = result[i]; TBPoint tbp = TBPoint.getNewTBPoint(p); this.addIntersectPoint(tbp); tbpline.addIntersectPoint(tbp); } }
public LoopSeg(TBPLineSegment seg, TBPoint startP) { segment = seg; if (startP == seg.StartPoint) { direction = LineDirection.positive; } else if (startP == seg.EndPoint) { direction = LineDirection.negtive; } else { throw new System.Exception("BoundarySeg.cs 39"); } }
public double scanAngle(TBPoint startp) {//闭合情况下,没有计算末尾到开始的角度 if (startp == this.StartPoint) { return(this.scanAngle()); } else if (startp == this.EndPoint) { TBPLineSegment reverse = this.newReverse(); return(reverse.scanAngle()); } else { throw new System.Exception("TBPLineSegment 69"); } }
public List <Point3d> getInnerPoints(TBPoint startp) { TBPLineSegment seg = this; if (startp == this.StartPoint) { } else if (startp == this.EndPoint) { seg = this.newReverse(); } else { return(null); } return(seg.getInnerPoints()); }
private void caclParams() { for (int i = 0; i < intersectPoints.Count; i++) { TBPoint p = intersectPoints[i]; double param = this.acPline.GetParameterAtPoint(p.acPoint); if (param < 0) { //throw new System.Exception("TBPLine 97"); } if (Math.Abs(param) < 1e-10) { param = 0; } p.TempParam = param; } }
public void addIntersectPoint(TBPoint p) { int i = intersectPoints.FindIndex(item => { TBPoint p2 = item as TBPoint; if ((Math.Abs(p.acPoint.X - p2.acPoint.X) < 1e-10) && (Math.Abs(p.acPoint.Y - p2.acPoint.Y) < 1e-10)) { return(true); } return(false); }); if (i < 0) { intersectPoints.Add(p); return; } }
public TBPoint nextPoint(int i, out TBPoint start) { start = null; if (i != 1 && i != 2) { return(null); } TBPoint p = null; hadProcessed |= i; if (i == 1) { p = this.EndPoint; start = this.StartPoint; } else if (i == 2) { p = this.StartPoint; start = this.EndPoint; } return(p); }
public TBPoint nextPoint(out TBPoint start) { TBPoint r = null; start = null; r = this.nextPointDic[startPoint]; if (r != null) { start = startPoint; this.nextPointDic[startPoint] = null; } else { r = this.nextPointDic[endPoint]; if (r != null) { start = endPoint; this.nextPointDic[endPoint] = null; } } return(r); if ((hadProcessed & 1) == 0) { r = nextPoint(1, out start); if (r == null) { r = nextPoint(2, out start); } } else if ((hadProcessed & 2) == 0) { r = nextPoint(2, out start); } return(r); }
public TBPLineComparer(TBPoint p) { startPoint = p; }
public void divide() { this.SegmentedPlines = new List <TBPLineSegment>(); ObjectId layerId = My.LayerUtil.CreateLayer("segment", 255, false); try { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; /*using (Transaction tran = acCurDb.TransactionManager.StartTransaction()) * { * BlockTable bt = tran.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; * BlockTableRecord modelSpace = tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;*/ if (intersectPoints.Count <= 0) { return; } for (int i = 0; i < intersectPoints.Count - 1; i++) { TBPoint p1 = intersectPoints[i]; TBPoint p2 = intersectPoints[i + 1]; Point3dCollection vertexes = new Point3dCollection(); //My.MyDBUtility.addPolyline3d(segmentedPl, layerId); //ObjectId oid = modelSpace.AppendEntity(segmentedPl); //tran.AddNewlyCreatedDBObject(segmentedPl, true); vertexes.Add(p1.acPoint); //segmentedPl.AppendVertex(vertex); int n = 0; int vertexCount = 1; while (true) { double nextP; if (Math.Ceiling(p1.TempParam) - p1.TempParam < 1e-10) { nextP = Math.Ceiling(p1.TempParam) + (++n); } else { nextP = Math.Ceiling(p1.TempParam) + (n++); } if (nextP - p2.TempParam > 1e-10) { break; } else if (Math.Abs(nextP - p2.TempParam) <= 1e-10) { break; } //segmentedPl.AppendVertex(new PolylineVertex3d(acPline.GetPointAtParameter(nextP))); vertexes.Add(acPline.GetPointAtParameter(nextP)); vertexCount++; } //segmentedPl.AppendVertex(new PolylineVertex3d(p2.acPoint)); vertexes.Add(p2.acPoint); vertexCount++; if (vertexCount >= 2) { Polyline3d segmentedPl = new Polyline3d(Poly3dType.SimplePoly, vertexes, false); TBPLineSegment tbpline = new TBPLineSegment(segmentedPl, p1, p2); //tbpline.StartPoint = p1; //tbpline.EndPoint = p2; this.SegmentedPlines.Add(tbpline); //p1.SegmentedPLines.Add(tbpline); //p2.SegmentedPLines.Add(tbpline); p1.addSegment(tbpline); p2.addSegment(tbpline); } } if (this.isClosed || this.IsLooped) { TBPoint p1 = intersectPoints[intersectPoints.Count - 1]; Point3dCollection vertexes = new Point3dCollection(); vertexes.Add(p1.acPoint); My.PolylineUtil.getPointsBetween2Point(acPline, p1.TempParam, acPline.EndParam, vertexes); vertexes.Add(acPline.StartPoint); TBPoint p2 = intersectPoints[0]; My.PolylineUtil.getPointsBetween2Point(acPline, 0, p2.TempParam, vertexes); vertexes.Add(p2.acPoint); if (vertexes.Count >= 2) { Polyline3d segmentedPl = new Polyline3d(Poly3dType.SimplePoly, vertexes, false); TBPLineSegment tbpline = new TBPLineSegment(segmentedPl, p1, p2); this.SegmentedPlines.Add(tbpline); p1.addSegment(tbpline); p2.addSegment(tbpline); } } //tran.Commit(); //} } catch (System.Exception ex) { } }
public bool equalTo(TBPoint p2) { bool r = (Math.Abs(this.acPoint.X - p2.acPoint.X) < 1e-10) && (Math.Abs(this.acPoint.Y - p2.acPoint.Y) < 1e-10); return(r); }
public TBPLineSegmentComparer(TBPoint p) { startPoint = p; }
public TBPLineSegment(Polyline3d pl) { this.acPline = pl; startPoint = TBPoint.getNewTBPoint(pl.StartPoint); endPoint = TBPoint.getNewTBPoint(pl.EndPoint); }