如何在WPF中获取ArcSegment的中间点

时间:2011-10-15 16:01:31

标签: c# wpf

在路径中获取ArcSegment的中间点并在WPF中标记它的最佳解决方案是什么?

enter image description here

1 个答案:

答案 0 :(得分:7)

这应该有效:

        //the given arc (or any other segments)
        var arc = new ArcSegment(
            point: new Point(200, 100),
            size: new Size(100, 50),
            rotationAngle: 90,
            isLargeArc: true,
            sweepDirection: SweepDirection.Counterclockwise,
            isStroked: true);

        //compose one or more segments into a collection
        var pathcoll = new PathSegmentCollection();
        pathcoll.Add(arc);

        //create a figure based on the set of segments
        var figure = new PathFigure();
        figure.Segments = pathcoll;

        //compose a collection of figures
        var figcoll = new PathFigureCollection();
        figcoll.Add(figure);

        //create a path-geometry using the figures collection
        var geom = new PathGeometry(figcoll);

        double fraction = 0.5;  //the relative point of the curve
        Point pt;               //the absolute point of the curve
        Point tg;               //the tangent point of the curve
        geom.GetPointAtFractionLength(
            fraction,
            out pt,
            out tg);

希望它有所帮助。

干杯