zoukankan      html  css  js  c++  java
  • 2018-2-13-win10-uwp-分治法

    title author date CreateTime categories
    win10 uwp 分治法
    lindexi
    2018-2-13 17:23:3 +0800
    2018-2-13 17:23:3 +0800
    Win10 UWP

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

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

    $$x1y2+x3y1+x2y3-x3y2-x2y1-x1y3 = x1y2-x2y1+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)

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

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

    这里写图片描述

    我们需要连线

    连线

                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

    做完我来运行

    这里写图片描述

  • 相关阅读:
    第六周 组合数据类型
    第五周 函数和代码复用
    第四周 程序的控制结构
    第三周 Python基本数据类型
    python库
    sublime text3自定义设置及快捷键大全
    Sublime Text3插件安装教程
    Linux 标准目录结构
    快学Scala-10--List 和Set
    快学Scala-09--模式匹配
  • 原文地址:https://www.cnblogs.com/lindexi/p/12085584.html
Copyright © 2011-2022 走看看