Exemple #1
0
        private static List <BridgePoints> GetBridgeByCircle(Circle circle, UnitPoint p1, UnitPoint p2, BridgingModel param)
        {
            List <BridgePoints> retPoints = new List <BridgePoints>();
            var              line         = DrawingOperationHelper.GetLineEquation(p1, p2);
            double           width        = param.Width / 2;
            List <UnitPoint> points       = DrawingOperationHelper.GetIntersectPointByLineAndCircle(line.Item1, line.Item2, line.Item3, circle.Center, circle.Radius);
            var              hasPoints    = points?.Where(p => !p.IsEmpty && HitUtil.IsPointInLine(p1, p2, p, 0.000001f)).ToList();

            if (hasPoints != null && hasPoints.Count > 0)
            {
                //根据宽度求点
                double angle = width / circle.Radius * (circle.IsClockwise ? 1 : -1);
                List <UnitPointBulge> temps = new List <UnitPointBulge>();
                hasPoints?.ForEach(p =>
                {
                    double lineAngle = HitUtil.LineAngleR(circle.Center, p, 0);
                    double angle1    = lineAngle + angle;
                    double angle2    = lineAngle - angle;
                    //第一个位置点
                    UnitPoint retPoint1 = HitUtil.PointOnCircle(circle.Center, circle.Radius, angle1);
                    //第二个位置点
                    UnitPoint retPoint2 = HitUtil.PointOnCircle(circle.Center, circle.Radius, angle2);

                    BridgePoints bridges = new BridgePoints(circle,
                                                            new UnitPointBulge(retPoint1),
                                                            new UnitPointBulge(retPoint2),
                                                            HitUtil.Distance(p1, p));
                    retPoints.Add(bridges);
                });
            }
            return(retPoints);
        }
Exemple #2
0
        private static List <BridgePoints> GetBridgeByArc(ArcBase arc, UnitPoint p1, UnitPoint p2, BridgingModel param)
        {
            List <BridgePoints> retPoints = new List <BridgePoints>();
            var          line             = DrawingOperationHelper.GetLineEquation(p1, p2);
            double       width            = param.Width / 2;
            ArcModelMini arcMini          = new DrawModel.ArcModelMini()
            {
                Center     = arc.Center,
                Radius     = arc.Radius,
                StartAngle = arc.StartAngle,
                EndAngle   = arc.EndAngle,
                SweepAngle = arc.AngleSweep,
                Clockwise  = arc.IsClockwise
            };

            List <UnitPoint> points = DrawingOperationHelper.GetIntersectPointByLineAndCircle(line.Item1, line.Item2, line.Item3, arc.Center, arc.Radius);
            var hasPoints           = points?.Where(p => !p.IsEmpty && (HitUtil.IsPointOnArc(p, 0.000001f, arcMini) && HitUtil.IsPointInLine(p1, p2, p, 0.000001f))).ToList();

            if (hasPoints != null && hasPoints.Count > 0)
            {
                //根据宽度求点
                double angle = width / arc.Radius * (arc.IsClockwise ? 1 : -1);
                hasPoints?.ForEach(p =>
                {
                    double lineAngle    = HitUtil.LineAngleR(arcMini.Center, p, 0);
                    double angle1       = lineAngle + angle;
                    double angle2       = lineAngle - angle;
                    UnitPoint retPoint1 = UnitPoint.Empty;
                    UnitPoint retPoint2 = UnitPoint.Empty;
                    if (HitUtil.IsPointInArc(HitUtil.RadiansToDegrees(angle1), arcMini.StartAngle, arcMini.EndAngle, arcMini.Clockwise))
                    {
                        //第一个位置点
                        retPoint1 = HitUtil.PointOnCircle(arcMini.Center, arcMini.Radius, angle1);
                    }
                    if (HitUtil.IsPointInArc(HitUtil.RadiansToDegrees(angle2), arcMini.StartAngle, arcMini.EndAngle, arcMini.Clockwise))
                    {
                        //第二个位置点
                        retPoint2 = HitUtil.PointOnCircle(arcMini.Center, arcMini.Radius, angle2);
                    }
                    BridgePoints bridges = new BridgePoints(arc,
                                                            new UnitPointBulge(retPoint1),
                                                            new UnitPointBulge(retPoint2),
                                                            HitUtil.Distance(p1, p));
                    retPoints.Add(bridges);
                });
            }
            return(retPoints);
        }
Exemple #3
0
        private static List <BridgePoints> GetBridgeByMultiSegLine(MultiSegmentLineBase multiSegLine, UnitPoint p1, UnitPoint p2, BridgingModel param)
        {
            List <BridgePoints> retPoints = new List <BridgePoints>();
            var    line      = DrawingOperationHelper.GetLineEquation(p1, p2);
            double width     = param.Width / 2;
            var    oriPoints = multiSegLine.Points;

            for (int index = 0; index < oriPoints.Count; index++)
            {
                int            next   = (index + 1 == oriPoints.Count) ? 0 : index + 1;
                UnitPointBulge point1 = oriPoints[index];
                UnitPointBulge point2 = oriPoints[next];
                if (!multiSegLine.IsCloseFigure && index == oriPoints.Count - 1)
                {
                    break;
                }
                if (!double.IsNaN(point1.Bulge))
                {
                    //圆弧
                    ArcModelMini arcMini = DrawingOperationHelper.GetArcParametersFromBulge(point1.Point, point2.Point, (float)point1.Bulge);
                    arcMini.StartAngle = (float)HitUtil.RadiansToDegrees(arcMini.StartAngle);
                    arcMini.EndAngle   = (float)HitUtil.RadiansToDegrees(arcMini.EndAngle);
                    List <UnitPoint> points = DrawingOperationHelper.GetIntersectPointByLineAndCircle(line.Item1, line.Item2, line.Item3, arcMini.Center, arcMini.Radius);
                    var hasPoints           = points?.Where(p => !p.IsEmpty && HitUtil.IsPointOnArc(p, 0.000001f, arcMini) && HitUtil.IsPointInLine(p1, p2, p, 0.000001f)).ToList();
                    if (hasPoints != null && hasPoints.Count > 0)
                    {
                        arcMini.StartAngle = (float)HitUtil.DegreesToRadians(arcMini.StartAngle);
                        arcMini.EndAngle   = (float)HitUtil.DegreesToRadians(arcMini.EndAngle);
                        //根据宽度求点
                        double arcLength = DrawingOperationHelper.GetArcLength(arcMini.Radius, arcMini.SweepAngle);
                        hasPoints?.ForEach(p =>
                        {
                            double percent = DrawingOperationHelper.GetPercentInArcByPoint(arcMini, p);
                            //第一个位置点
                            double length1       = arcLength * (1 - percent) + width;
                            UnitPointBulge retP1 = GetEndPointByLength(oriPoints, index, length1, false);

                            //第二个位置点
                            double length2       = arcLength * percent + width;
                            UnitPointBulge retP2 = GetEndPointByLength(oriPoints, index, length2, true);

                            var bridge = new BridgePoints(multiSegLine, retP1, retP2, HitUtil.Distance(p1, p));
                            retPoints.Add(bridge);
                        });
                    }
                }
                else
                {
                    //直线
                    var       lineABC = DrawingOperationHelper.GetLineEquation(point1.Point, point2.Point);
                    UnitPoint point   = DrawingOperationHelper.GetIntersectionPointBy2Line(line.Item1, line.Item2, line.Item3, lineABC.Item1, lineABC.Item2, lineABC.Item3);
                    if (!point.IsEmpty && HitUtil.IsPointInLine(point1.Point, point2.Point, point, 0.000001f) && HitUtil.IsPointInLine(p1, p2, point, 0.000001f))
                    {
                        //第一个位置点
                        double         lenght1 = HitUtil.Distance(point2.Point, point) + width;
                        UnitPointBulge retP1   = GetEndPointByLength(oriPoints, index, lenght1, false);


                        //第二个位置点
                        double         lenght2 = HitUtil.Distance(point1.Point, point) + width;
                        UnitPointBulge retP2   = GetEndPointByLength(oriPoints, index, lenght2, true);

                        var bridge = new BridgePoints(multiSegLine, retP1, retP2, HitUtil.Distance(p1, point));
                        retPoints.Add(bridge);
                    }
                }
            }
            return(retPoints);
        }