【问题标题】:How Get The middle point of an ArcSegment in WPF如何在 WPF 中获取 ArcSegment 的中点
【发布时间】:2011-10-20 23:50:00
【问题描述】:

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

【问题讨论】:

  • 好问题。我假设您必须根据半径和中点的某种组合来计算它?
  • 如果弧以某种方式数据绑定到视图模型,那么您可以将具有标签正确位置的属性添加到视图模型,或者实现执行相同操作的转换器。另一方面,如果您不使用数据绑定,那么您可以简单地计算标签的位置,在您计算弧的参数的同一位置。正如 Ritch 指出的,您可以根据端点、半径和角度计算位置...
  • 也许Charle Petzold's blog 会有所帮助。

标签: c# wpf


【解决方案1】:

这应该可行:

        //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);

希望对你有帮助。

干杯

【讨论】:

  • 'GetPointAtFractionLength'。这正是我所需要的!谢谢。
  • 经过几个小时的搜索,我们到了!谢谢!
  • GetPointAtFractionLength 为我解决了很多问题。很棒的发现!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多