如何在WPF中获取弧段的中点

10

如何在WPF中获取路径中弧线段的中点并标记它,这是最佳解决方案?

enter image description here


好问题。我会假设你需要根据半径和中点的某种组合来计算它? - Ritch Melton
如果弧线与视图模型进行了数据绑定,那么您可以在视图模型中添加一个属性,该属性包含标签的正确位置,或者实现一个执行相同操作的转换器。另一方面,如果您没有使用数据绑定,则可以在计算弧线参数的同时计算标签的位置。正如Ritch所指出的那样,您可以根据端点、半径和角度计算位置... - Paul Roberts
3
也许Charles Petzold的博客会有所帮助。 - Dmitriy
1个回答

10

应该可以正常工作:

        //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);
希望有所帮助。
祝好。

1
'GetPointAtFractionLength'. 这正是我所需!谢谢。 - ARZ
几个小时的搜索之后,我们终于找到了!谢谢! - Craig
GetPointAtFractionLength为我解决了很多问题。太棒了! - Jon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接