public override CustomPath CalculatePath() { var startOuterPolar = new PolarPoint(PolarOffset, outerRadius); var endOuterPolar = new PolarPoint(PolarOffset + ArcAngle, outerRadius); var startInnerPolar = new PolarPoint(PolarOffset, outerRadius - RingWidth); var endInnerPolar = new PolarPoint(PolarOffset + ArcAngle, outerRadius - RingWidth); return new CustomPath(this) { Data = new PathGeometry { Figures = new PathFigureCollection { new PathFigure { StartPoint = startOuterPolar.ToCartesian().LocalizeInPolarSpace(RenderSize), Segments = new PathSegmentCollection { new ArcSegment { Size = outerSize, Point = endOuterPolar.ToCartesian().LocalizeInPolarSpace(RenderSize), IsLargeArc = ArcAngle > 180 }, new LineSegment { Point = endInnerPolar.ToCartesian().LocalizeInPolarSpace(RenderSize) }, new ArcSegment { Size = innerSize, Point = startInnerPolar.ToCartesian().LocalizeInPolarSpace(RenderSize), SweepDirection = SweepDirection.Clockwise, IsLargeArc = ArcAngle > 180 } } } } } }; }
public static Geometry CalculateArcPath(Size size, double radius, double arcWidth, double angle, double offsetAngle) { if (radius <= 0 || arcWidth <= 0 || radius - arcWidth < 0) return Geometry.Empty; var startOuterPolar = new PolarPoint(offsetAngle, radius); var endOuterPolar = new PolarPoint(offsetAngle + angle, radius); var startInnerPolar = new PolarPoint(offsetAngle, radius - arcWidth); var endInnerPolar = new PolarPoint(offsetAngle + angle, radius - arcWidth); var isLargeArc = angle > 180; var startOuter = startOuterPolar.ToCartesian().LocalizeInPolarSpace(size); var endOuter = endOuterPolar.ToCartesian().LocalizeInPolarSpace(size); var startInner = startInnerPolar.ToCartesian().LocalizeInPolarSpace(size); var endInner = endInnerPolar.ToCartesian().LocalizeInPolarSpace(size); return new PathGeometry { Figures = new PathFigureCollection { new PathFigure { StartPoint = startOuter, Segments = new PathSegmentCollection { new ArcSegment { Size = new Size(radius, radius), Point = endOuter, IsLargeArc = isLargeArc }, new LineSegment { Point = endInner }, new ArcSegment { Size = new Size(radius - arcWidth, radius - arcWidth), Point = startInner, SweepDirection = SweepDirection.Clockwise, IsLargeArc = isLargeArc } } } } }; }