标签: pathgeometry

WP7 PathGeometry错误

我对一个简单的PathGeometry对象有一个奇怪的错误,我似乎无法搞清楚.如果有人能向我解释为什么这不起作用,我将不胜感激.

这是一个工作路径的示例,它绘制一个小三角形:

<Path Data="M 8,4 L 12,12 4,12 8,4 Z" Stroke="White" />
Run Code Online (Sandbox Code Playgroud)

这是一个似乎对我不起作用的Path的示例:

<Path Stroke="White">
    <Path.Data>
        <PathGeometry Figures="M 8,4 L 12,12 4,12 8,4 Z" />
    </Path.Data>
</Path>
Run Code Online (Sandbox Code Playgroud)

Data和Figures属性中的字符串是相同的,但后一个示例导致异常:

属性数字的无效属性值M 8,4 L 12,12 4,12 8,4 Z.

我最想做的是将PathGeometry放入ResourceDictionary并将其作为{StaticResource}引用,以便我可以重复使用我的形状.

编辑:

我的解决方案是尝试使用StaticResource引用PathGeometry,而不是引用字符串资源.

<sys:String x:Key="TriangleShape">M 8,4 L 12,12 4,12 8,4 Z</sys:String>
...
<Path Data={StaticResource TriangleShape}" />
Run Code Online (Sandbox Code Playgroud)

silverlight path pathgeometry windows-phone-7

6
推荐指数
1
解决办法
1091
查看次数

WPF - 路径/几何帮助 - 奇怪的形状

有人知道从Xaml创建这个对象的好方法吗?当在其他控件之上分层时,它还必须以.5 Opacity工作.

它还必须通过水平或垂直对齐来调整大小.

形状http://monitor.utopiaselfscan.com/test.bmp

我遇到了一些困难.我得到的最接近的是2个边框,其中一个具有负边距 - 但是当应用不透明度时它不起作用.

有效的代码:

            <Path Fill="Black">
                <Path.Data>
                    <CombinedGeometry GeometryCombineMode="Exclude">
                        <CombinedGeometry.Geometry1>
                            <RectangleGeometry RadiusX="5" RadiusY="5" Rect="0,0,200,100" />
                        </CombinedGeometry.Geometry1>
                        <CombinedGeometry.Geometry2>
                            <RectangleGeometry RadiusX="5" RadiusY="5" Rect="105,5,90,90" />
                        </CombinedGeometry.Geometry2>
                    </CombinedGeometry>
                </Path.Data>
            </Path>
Run Code Online (Sandbox Code Playgroud)

wpf xaml pathgeometry

5
推荐指数
1
解决办法
3470
查看次数

将自相交Path2D分成几个非自相交路径的算法?

我需要摆脱形状中的自相交.形状由点阵列构成,因此该形状的所有段都是线.(只有线条,没有曲线和弧线)

以前,我尝试从这些点创建Path2D,从中构造一个Area,然后使用它的PathIterator我创建了几个Path2D,它们不知何故是前一个路径的子路径,因此自相交消失了.但这对某些路径不起作用 - 自我交叉仍然存在.

所以你能指点我找到一个好的算法来做类似的事吗?

编辑:我在任何地方都找不到任何有用的东西,所以我编写了自己的算法.看到答案.

java algorithm geometry pathgeometry

5
推荐指数
1
解决办法
1341
查看次数

有没有比PathGeometry.FillContainsWithDetail()检测多边形重叠/交叉更有效的方法?

我有一个方法吞噬了我的CPU时间的25%.我称这种方法每秒约27,000次.(是的,很多电话,因为它经常更新).我想知道是否有人知道更快的方法来检测2个多边形是否重叠.基本上,我必须检查屏幕上的移动物体与屏幕上的静止物体.我正在使用PathGeometry,下面的两个调用占用了我程序使用的cpu时间的25%.我传递的PointCollection对象只包含4个点,表示多边形的4个角.它们可能不会创建矩形区域,但所有点都是连接的.我猜一个trapazoid就是形状.

这些方法很简单,并且很容易实现,但我想如果我能让它比下面的代码更快地运行,我可能会选择更复杂的解决方案.有任何想法吗?

public static bool PointCollectionsOverlap(PointCollection area1, PointCollection area2)
{
    PathGeometry pathGeometry1 = GetPathGeometry(area1);
    PathGeometry pathGeometry2 = GetPathGeometry(area2);
    return pathGeometry1.FillContainsWithDetail(pathGeometry2) != IntersectionDetail.Empty;
}

public static PathGeometry GetPathGeometry(PointCollection polygonCorners)
{
    List<PathSegment> pathSegments = new List<PathSegment> 
                                         { new PolyLineSegment(polygonCorners, true) };
    PathGeometry pathGeometry = new PathGeometry();
    pathGeometry.Figures.Add(new PathFigure(polygonCorners[0], pathSegments, true));
    return pathGeometry;
}
Run Code Online (Sandbox Code Playgroud)

wpf polygon polygons pathgeometry point-in-polygon

5
推荐指数
1
解决办法
4901
查看次数

PathGeometry的非GUI替代方案?

我有两个巨大的(> 100000项)PathGeometry集合我需要使用PathGeometry.Combine进行比较,如下所示:

List<PathGeometry> firstList;
List<PathGeometry> secondList;
[...]

foreach (PathGeometry pg1 in firstList)
  foreach (PathGeometry pg2 in secondList)
  {
    PathGeometry intergeo = PathGeometry.Combine(pg1, pg2, GeometryCombineMode.Intersect, null);
    if (intergeo.GetArea() > 0)
    {
      // do whatever with intergeo.GetArea()
    }
  }
Run Code Online (Sandbox Code Playgroud)

令我惊讶的是,PathGeometry是GUI的一部分并使用调度程序,它有时会导致问题,因为我的计算在没有GUI的情况下在一些后台线程中运行使用Parallel.ForEach()

所以我正在寻找一种没有连接到GUI的PathGeometry的替代品.
我的数字非常复杂,并为PathGeometry.Figures添加了很多PathFigures.

我自己从一些臃肿的政府xml文件创建那些PathGeometries,所以创建其他东西也没有问题.但是我需要一个函数来创建这些几何中的两个(不是相互添加)的交集,以获得两个几何所覆盖的区域,例如此图中的红色区域:

在此输入图像描述

c# wpf .net-4.0 pathgeometry

5
推荐指数
1
解决办法
796
查看次数

在C#/ WPF中获取PathGeometry(行)的长度

如果我有一条封闭的路径,我可以Geometry.GetArea()用来近似我的形状区域.这很棒,节省了我很多时间.但周围有什么可以帮助我找到一条未封闭路径的长度吗?

我现在能够想出的最好PathGeometryGetPointAtFractionLength方法是确保我正在使用并多次调用该方法,获得积分并累加所有这些点之间的距离.

码:

    public double LengthOfPathGeometry(PathGeometry path, double steps)
    {
        Point pointOnPath;
        Point previousPointOnPath;
        Point tangent;

        double length = 0;

        path.GetPointAtFractionLength(0, out previousPointOnPath, out tangent);

        for (double progress = (1 / steps); progress < 1; progress += (1 / steps))
        {
            path.GetPointAtFractionLength(progress, out pointOnPath, out tangent);
            length += Distance(previousPointOnPath, pointOnPath);
            previousPointOnPath = pointOnPath;
        }
        path.GetPointAtFractionLength(1, out pointOnPath, out tangent);
        length += Distance(previousPointOnPath, pointOnPath);

        return length;
    }

    public static double Distance(Point p0, Point p1)
    { …
Run Code Online (Sandbox Code Playgroud)

c# wpf path pathgeometry

4
推荐指数
1
解决办法
5705
查看次数

简化路径的算法

给定一个路径,我想优化它,以便可以删除直线上的所有顶点.

例如:路径:

*******
*      *
*        *
***********
Run Code Online (Sandbox Code Playgroud)

可以优化为:

*-----*
|      \
|        \
*---------*
Run Code Online (Sandbox Code Playgroud)

但是我希望控制斜率的偏差,这样它就不必完全在斜率上.

什么样的算法可以做到这一点?

谢谢

c++ algorithm geometry pathgeometry

4
推荐指数
1
解决办法
1529
查看次数

填充未关闭PathGeometry到底部

假设我有这样PathGeometry线条(例如矩形==面板Grid): 例子 我想将它们填充到面板的底部,如下所示: 在此输入图像描述 我看到的快速且不太好的解决方案是创建额外的曲线,底部有2个额外的点并用于填充.

有没有更好的方法来解决这个任务?像这样的东西(伪代码):

 <Path Data=... FillStyle = "ToTheBottom" Fill="Blue"/>
Run Code Online (Sandbox Code Playgroud)

wpf fill pathgeometry

4
推荐指数
1
解决办法
800
查看次数

如何向PathFigure WPF添加一个矩形

我完全厌倦了添加Rectangle路径图.下面是我尝试过的代码,但它没有正确的结果Rectangle:

PathGeometry geom = new PathGeometry();
Geometry g = new RectangleGeometry(myrectangel);
geom.AddGeometry(g);

PathFigureCollection collection = geom.Figures;
pathfigure = collection[0];
Run Code Online (Sandbox Code Playgroud)

还有其他方法吗?

c# wpf rectangles pathgeometry

4
推荐指数
1
解决办法
3053
查看次数

WPF中的几何绘图

我对所有这些几何部分都是新手,但我可以看到它让我能够绘制基本上我想要的东西.我找不到一本好的手册,教我如何创造我头脑中的任何形象.我真的希望找到一些能为我提取几何数据的画家,但到目前为止还没有运气.

例如,我在网上找到了这个:

<Geometry x:Key="MagnifierIconGeometry">M44,12 C32,12 22,22 22,34 22,46 32,56 44,56 56,56 66,46 66,34 66,22 56,12 44,12z M44,0 C63,0 78,15 78,34 78,53 63,68 44,68 40,68 36.5,67.5 33,66 L32.5,66 14,90 0,79.5 18,55.5 17,55 C13,49 10,42 10,34 10,15 25,0 44,0z</Geometry>
Run Code Online (Sandbox Code Playgroud)

您可以通过名称来判断它绘制的内容,但我想知道如何自己完成它?

如果有人能指出我的手册/任何类型的程序将是太棒了!

谢谢.

wpf pathgeometry

4
推荐指数
1
解决办法
5770
查看次数