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); }
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); }
/// <summary> /// 根据长度获取多段线的点坐标 /// </summary> /// <param name="points">多段线的点</param> /// <param name="index">当前开始的索引位置</param> /// <param name="length">长度</param> /// <param name="isPositive">是否正向计算长度,否则从反向计算长度</param> /// <returns></returns> private static UnitPointBulge GetEndPointByLength(List <UnitPointBulge> points, int index, double length, bool isPositive) { int next = index + 1 >= points.Count ? 0 : index + 1; var p1 = points[index]; var p2 = points[next]; UnitPoint end = UnitPoint.Empty; if (!double.IsNaN(p1.Bulge)) { ArcModelMini arc = DrawingOperationHelper.GetArcParametersFromBulge(p1.Point, p2.Point, (float)p1.Bulge); double curLength = DrawingOperationHelper.GetArcLength(arc.Radius, arc.SweepAngle); if (length < curLength) { float angle = (float)((isPositive ? length : (curLength - length)) / curLength) * arc.SweepAngle; angle = arc.StartAngle + (float)HitUtil.DegreesToRadians(angle); end = HitUtil.PointOnCircle(arc.Center, arc.Radius, angle); } else if (!double.IsNaN(length - curLength)) { int nextIndex = isPositive ? next : (index - 1) < 0 ? points.Count - 1 : (index - 1); return(GetEndPointByLength(points, nextIndex, length - curLength, isPositive)); } } else { double curLength = HitUtil.Distance(p1.Point, p2.Point); if (length < curLength) { if (isPositive) { end = HitUtil.GetLinePointByDistance(p1.Point, p2.Point, length); } else { end = HitUtil.GetLinePointByDistance(p2.Point, p1.Point, length); } } else if (!double.IsNaN(length - curLength)) { int nextIndex = isPositive ? next : (index - 1) < 0 ? points.Count - 1 : (index - 1); return(GetEndPointByLength(points, nextIndex, length - curLength, isPositive)); } } return(new UnitPointBulge(end, bulge: p1.Bulge, position: index)); }