Пример #1
0
        public Polygon CreatePolygonFromCurve(double from, double to, double padding)
        {
            var curve = new Curve();
            foreach (var point in this.Points)
            {
                curve.Points.Add(new Point(point));
            }

            curve = curve.RemoveOverlappingPoints2D();
            var len = curve.Length;
            curve = CurveStrategies.CutCurve(curve, from * len, to * len);
            curve = curve.RemoveOverlappingPoints2D();

            var curveLeft = curve.LateralOffsetCurve(Enums.LateralPosition.Left, padding).RemoveOverlappingPoints2D();
            var curveRight = curve.LateralOffsetCurve(Enums.LateralPosition.Right, padding).RemoveOverlappingPoints2D();

            var poly = new Polygon();
            foreach (var point in curveLeft.Points)
            {
                poly.Points.Add(point);
            }
            foreach (var point in curveRight.Points.Reverse())
            {
                poly.Points.Add(point);
            }
            poly.Points.Add(curveLeft.Points.First());
            return poly;
        }
Пример #2
0
        private Curve LateralOffsetCurve(
                Enums.LateralPosition? lateralPosition, double offset)
        {
            Curve curve;
            if (this.UpdateOffset(lateralPosition, ref offset, out curve))
            {
                return curve;
            }

            var shiftedPoints = new Curve();
            var cnt = this.Points.Count();
            for (var i = 0; i < cnt - 1; i++)
            {
                var shiftedPointsTmp = CurveStrategies.CreateParallelLine(this.Points[i], this.Points[i + 1], offset);
                shiftedPoints.Points.Add(shiftedPointsTmp.Points[0]);
                shiftedPoints.Points.Add(shiftedPointsTmp.Points[1]);
            }

            shiftedPoints = shiftedPoints.RemoveOverlappingPoints2D();

            var cntShifted = shiftedPoints.Points.Count();
            for (var i = 0; i < cntShifted - 3; i += 2)
            {
                var innerIntersection = CurveStrategies.IntersectionOfCurves(
                    shiftedPoints.Points[i],
                    shiftedPoints.Points[i + 1],
                    shiftedPoints.Points[i + 2],
                    shiftedPoints.Points[i + 3]);

                if (innerIntersection != null && innerIntersection.GetType() == typeof(Point))
                {
                    // inner intersection
                    shiftedPoints.Points[i + 1].X = ((Point)innerIntersection).X;
                    shiftedPoints.Points[i + 1].Y = ((Point)innerIntersection).Y;
                    shiftedPoints.Points[i + 2].X = ((Point)innerIntersection).X;
                    shiftedPoints.Points[i + 2].Y = ((Point)innerIntersection).Y;
                }
                else
                {
                    // outer intersection
                    var outerIntersection = (Point)CurveStrategies.IntersectionOfCurvesInf(
                        shiftedPoints.Points[i],
                        shiftedPoints.Points[i + 1],
                        shiftedPoints.Points[i + 2],
                        shiftedPoints.Points[i + 3]);

                    var angle = MathHelper.RadToDeg(MathHelper.AngleBetweenLines(
                        shiftedPoints.Points[i + 1],
                        outerIntersection,
                        shiftedPoints.Points[i + 2]));

                    if (angle >= 45f && outerIntersection != null && outerIntersection.GetType() == typeof(Point))
                    {
                        shiftedPoints.Points[i + 1].X = ((Point)outerIntersection).X;
                        shiftedPoints.Points[i + 1].Y = ((Point)outerIntersection).Y;
                        shiftedPoints.Points[i + 2].X = ((Point)outerIntersection).X;
                        shiftedPoints.Points[i + 2].Y = ((Point)outerIntersection).Y;
                    }
                }
            }

            return shiftedPoints;
        }