天天看点

win10 uwp 分治法

其实我想说Path,因为最近在做一个简单的分治。

算法涉及到了一个平面几何的知识。就是三角形p1p2p3的面积等于以下行列式的二分之一: % <![CDATA[ \begin{array}{cccc} | x1 & y1 & 1 & | \\ | x2 & y2 & 1 & | &=\\ | x3 & y3 & 1 & | \\ \end{array} %]]>

x1*y2+x3*y1+x2*y3-x3*y2-x2*y1-x1*y3 = x1*y2-x2*y1+x3*(y1-y2)+y3*(x2-x1)

而且当点P3 在射线P1P2的左侧的时候,表达式为正,右侧表达式为负,三点同线的话表达式为0;算法中就利用该几何特性判断一个点在一条线的左侧还是右侧。

参见:http://www.cnblogs.com/Booble/archive/2011/03/10/1980089.html

我们有了一个后台,他可以有很多点,和得到边,我们如何从拿到的

List<Point> point

画出,和拿到的边的点画出

其实我们可以用简单的Path,如何从Path画点

我们可以使用EllipseGeometry

EllipseGeometry是Geometry,看到Geometry大家会看到Path的Data,是的,我们可以使用

Windows.UI.Xaml.Shapes.Path path = new Windows.UI.Xaml.Shapes.Path
                {
                    Data = new EllipseGeometry()
                };           

复制

为什么画点我会使用EllipseGeometry,因为我就需要一个点作为中心,X的大小和Y的,然后就是点

Windows.UI.Xaml.Shapes.Path path = new Windows.UI.Xaml.Shapes.Path
                {
                    Data = new EllipseGeometry()
                    {
                        Center = point,
                        RadiusX = 5,
                        RadiusY = 5
                    }
                };           

复制

那么我们需要给点颜色

断句不要弄错,是给 点 ,颜色

实心:Fill = new SolidColorBrush(Colors.Gray),因为我们可以使用简单Colors,如果需要RBG,那么可以使用

Fill = new SolidColorBrush(new Color()
                    {
                        R = 0,
                        B = 0,
                        G = 0
                    })           

复制

然而这样觉得还是不好,我们本来不用十进制

Fill = new SolidColorBrush(new Color()
                    {
                        R = 0x23,
                        B = 0x54,
                        G = 0xa
                    })           

复制

博客:blog.csdn.net/lindexi_gd

如果觉得上面代码多:

Fill = new SolidColorBrush(Color.FromArgb(0xff,0xff,0xa,0x2))           

复制

我们这样还是好多,不过垃圾的wr没有给我们string转Color,工藤给我微软的自带可以把string转为Color因为简单,我就没有写,现在想要,找了很久,如果需要可以进: 53078485

我们现在已经弄好画点,但是空心没画

Stroke = new SolidColorBrush(Colors.Gray)           

复制

这样我们就可以画空心和实心

用之前的代码作为我们后台

win10 uwp 分治法

我们需要连线

连线

n = point.Count;

            PathFigure figures = new PathFigure();

            for (int i = 0; i < n; i++)
            {
                figures.Segments.Add(new LineSegment()
                {
                    Point = point[i]
                });
            }
            figures.Segments.Add(new LineSegment()
            {
                Point = point[0]
            });
            figures.StartPoint = point[0];

            Windows.UI.Xaml.Shapes.Path path_figure = new Path()
            {
                Data = new PathGeometry()
                {
                    Figures = new PathFigureCollection()
                    {
                        figures
                    }
                },
                Stroke = new SolidColorBrush(Colors.Gray)
            };           

复制

如果觉得这样太快了,我们可以弄个差

PathGeometry path_figure = new PathGeometry();
            for (int i = 0; i < point.Count; i++)
            {
                PathFigure path_segment = new PathFigure()
                {
                    StartPoint = point[i]
                };
                i++;
                LineSegment line = new LineSegment()
                {
                    Point = point[i]
                };
                path_segment.Segments.Add(line);
                path_figure.Figures.Add(path_segment);
            }           

复制

PathFigure第一个点

StartPoint = point[i]

,LineSegment第二个,

path_segment.Segments.Add(line);

,把

path_segment

放在我们外面定义

path_figure

这样比第一个会多了

path_segment

,这个变量命名不对,但是我现在不想去改

代码:https://github.com/lindexi/Algorithm

做完我来运行

win10 uwp 分治法