//only works if parts are in correct order public static Polyline drawPolyLine3(DBObjectCollection dbObjCol) { Polyline pLine = new Polyline(); PolylineSegmentCollection collection = new PolylineSegmentCollection(); foreach (DBObject dbo in dbObjCol) { //convert part to polyline if (dbo is Arc) { Arc arcDat = dbo as Arc; double bulge = getArcBulge(arcDat.EndAngle, arcDat.StartAngle); PolylineSegment pSeg = new PolylineSegment(new Point2d(arcDat.StartPoint.X, arcDat.StartPoint.Y), new Point2d(arcDat.EndPoint.X, arcDat.EndPoint.Y), bulge); collection.Add(pSeg); } else if (dbo is Line) { Line lDat = dbo as Line; PolylineSegment pSeg = new PolylineSegment(new Point2d(lDat.StartPoint.X, lDat.StartPoint.Y), new Point2d(lDat.EndPoint.X, lDat.EndPoint.Y)); //add to collection collection.Add(pSeg); } } //convert Collection to polyline collection.Join(); pLine = collection.ToPolyline(); return(pLine); }
/// <summary> /// Creates a new Polyline that is the result of projecting the polyline parallel to 'direction' onto 'plane' and /// returns it. /// </summary> /// <param name="pline">The polyline (any type) to project.</param> /// <param name="plane">The plane onto which the curve is to be projected.</param> /// <param name="direction">Direction (in WCS coordinates) of the projection.</param> /// <returns>The projected Polyline.</returns> internal static Polyline ProjectPolyline(Curve pline, Plane plane, Vector3d direction) { if (!(pline is Polyline) && !(pline is Polyline2d) && !(pline is Polyline3d)) { return(null); } plane = new Plane(Point3d.Origin.OrthoProject(plane), direction); using (var oldCol = new DBObjectCollection()) using (var newCol = new DBObjectCollection()) { pline.Explode(oldCol); foreach (DBObject obj in oldCol) { var crv = obj as Curve; if (crv != null) { var flat = crv.GetProjectedCurve(plane, direction); newCol.Add(flat); } obj.Dispose(); } var psc = new PolylineSegmentCollection(); for (var i = 0; i < newCol.Count; i++) { if (newCol[i] is Ellipse) { psc.AddRange(new PolylineSegmentCollection((Ellipse)newCol[i])); continue; } var crv = (Curve)newCol[i]; var start = crv.StartPoint; var end = crv.EndPoint; var bulge = 0.0; if (crv is Arc) { var arc = (Arc)crv; var angle = arc.Center.GetVectorTo(start).GetAngleTo(arc.Center.GetVectorTo(end), arc.Normal); bulge = Math.Tan(angle / 4.0); } psc.Add(new PolylineSegment(start.Convert2d(plane), end.Convert2d(plane), bulge)); } foreach (DBObject o in newCol) { o.Dispose(); } var projectedPline = psc.Join(new Tolerance(1e-9, 1e-9))[0].ToPolyline(); projectedPline.Normal = direction; projectedPline.Elevation = plane.PointOnPlane.TransformBy(Matrix3d.WorldToPlane(new Plane(Point3d.Origin, direction))).Z; if ( !pline.StartPoint.Project(plane, direction) .IsEqualTo(projectedPline.StartPoint, new Tolerance(1e-9, 1e-9))) { projectedPline.Normal = direction = direction.Negate(); projectedPline.Elevation = plane.PointOnPlane.TransformBy(Matrix3d.WorldToPlane(new Plane(Point3d.Origin, direction))).Z; } return(projectedPline); } }
/// <summary> /// Creates a new Polyline that is the result of projecting the polyline parallel to 'direction' onto 'plane' and returns it. /// </summary> /// <param name="pline">The polyline (any type) to project.</param> /// <param name="plane">The plane onto which the curve is to be projected.</param> /// <param name="direction">Direction (in WCS coordinates) of the projection.</param> /// <returns>The projected Polyline.</returns> internal static Polyline ProjectPolyline(Curve pline, Plane plane, Vector3d direction) { if (!(pline is Polyline) && !(pline is Polyline2d) && !(pline is Polyline3d)) return null; plane = new Plane(Point3d.Origin.OrthoProject(plane), direction); using (DBObjectCollection oldCol = new DBObjectCollection()) using (DBObjectCollection newCol = new DBObjectCollection()) { pline.Explode(oldCol); foreach (DBObject obj in oldCol) { Curve crv = obj as Curve; if (crv != null) { Curve flat = crv.GetProjectedCurve(plane, direction); newCol.Add(flat); } obj.Dispose(); } PolylineSegmentCollection psc = new PolylineSegmentCollection(); for (int i = 0; i < newCol.Count; i++) { if (newCol[i] is Ellipse) { psc.AddRange(new PolylineSegmentCollection((Ellipse)newCol[i])); continue; } Curve crv = (Curve)newCol[i]; Point3d start = crv.StartPoint; Point3d end = crv.EndPoint; double bulge = 0.0; if (crv is Arc) { Arc arc = (Arc)crv; double angle = arc.Center.GetVectorTo(start).GetAngleTo(arc.Center.GetVectorTo(end), arc.Normal); bulge = Math.Tan(angle / 4.0); } psc.Add(new PolylineSegment(start.Convert2d(plane), end.Convert2d(plane), bulge)); } foreach (DBObject o in newCol) o.Dispose(); Polyline projectedPline = psc.Join(new Tolerance(1e-9, 1e-9))[0].ToPolyline(); projectedPline.Normal = direction; projectedPline.Elevation = plane.PointOnPlane.TransformBy(Matrix3d.WorldToPlane(new Plane(Point3d.Origin, direction))).Z; if (!pline.StartPoint.Project(plane, direction).IsEqualTo(projectedPline.StartPoint, new Tolerance(1e-9, 1e-9))) { projectedPline.Normal = direction = direction.Negate(); projectedPline.Elevation = plane.PointOnPlane.TransformBy(Matrix3d.WorldToPlane(new Plane(Point3d.Origin, direction))).Z; } return projectedPline; } }