天天看點

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 分治法