Beispiel #1
0
        private List <Point3d> CalcOffsetPoints(Point3dCollection points, Extents3d bounds)
        {
            var pline        = new PolylineCurve3d(points);
            var distance     = TechProcess.Tool.Diameter / 2;
            var offsetCurves = pline.GetTrimmedOffset(distance, -Vector3d.YAxis, OffsetCurveExtensionType.Fillet);
            var matrix       = Matrix3d.Displacement(Vector3d.ZAxis.Negate() * distance);

            offsetCurves.ForEach(p => p.TransformBy(matrix));

            var firstPoint     = offsetCurves[0].StartPoint;
            var departurePoint = new Point3d((IsDepartureOnBorderSection ? firstPoint.X : bounds.MinPoint.X) - Departure, firstPoint.Y, firstPoint.Z);
            var offsetPoints   = new List <Point3d> {
                departurePoint, firstPoint
            };

            switch (offsetCurves[0])
            {
            case LineSegment3d line:
                offsetPoints.Add(line.EndPoint);
                break;

            case CircularArc3d arc:
                offsetPoints.Add(GetArcPoints(arc));
                break;

            case CompositeCurve3d curve:
                var c  = curve.GetCurves().ToList();
                var ca = c.OfType <CircularArc3d>().ToList();
                curve.GetCurves().ForEach(p =>
                {
                    if (p is CircularArc3d arc)
                    {
                        offsetPoints.Add(GetArcPoints(arc));
                    }
                    else
                    {
                        offsetPoints.Add(p.EndPoint);
                    }
                });
                break;

            default:
                throw new Exception($"Полученный тип кривой не может быть обработан {offsetCurves[0].GetType()}");
            }

            var lastPoint = offsetPoints.Last();

            offsetPoints.Add(new Point3d((IsDepartureOnBorderSection ? lastPoint.X : bounds.MaxPoint.X) + Departure, lastPoint.Y, lastPoint.Z));
            return(offsetPoints);

            Point3d GetArcPoints(CircularArc3d arc)
            {
                return(offsetPoints.Last().IsEqualTo(arc.StartPoint) ? arc.EndPoint : arc.StartPoint);

                //var num = (int)((arc.EndAngle - arc.StartAngle) / (Math.PI / 36)) + 4;
                //return arc.GetSamplePoints(num).Skip(1).Select(p => p.Point);
            }
        }
        // Polycurve
        // TODO: NOT TESTED FROM HERE DOWN
        public PolylineCurve3d PolylineToNative(Polyline polyline)
        {
            var points = PointListToNative(polyline.value, polyline.units).ToList();

            if (polyline.closed)
            {
                points.Add(points[0]);
            }
            var _polyline = new PolylineCurve3d(new Point3dCollection(points.ToArray()));

            if (polyline.domain != null)
            {
                _polyline.SetInterval(IntervalToNative(polyline.domain));
            }
            return(_polyline);
        }