`
lindexi-gd
  • 浏览: 140103 次
社区版块
存档分类
最新评论

win10 uwp 分治法

 
阅读更多

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

算法涉及到了一个平面几何的知识。就是三角形p1p2p3的面积等于以下行列式的二分之一:

<nobr><span class="math" id="MathJax-Span-1" style="width: 10.509em; display: inline-block;"><span style="display: inline-block; position: relative; width: 8.376em; height: 0px; font-size: 125%;"><span style="position: absolute; clip: rect(-0.051em 1000em 4.216em -0.211em); top: -2.344em; left: 0.003em;"><span class="mrow" id="MathJax-Span-2"><span class="mtable" id="MathJax-Span-3" style="padding-right: 0.163em; padding-left: 0.163em;"><span style="display: inline-block; position: relative; width: 8.056em; height: 0px;"><span style="position: absolute; clip: rect(2.563em 1000em 6.776em -0.371em); top: -4.904em; left: 0.003em;"><span style="display: inline-block; position: relative; width: 1.389em; height: 0px;"><span style="position: absolute; clip: rect(1.869em 1000em 3.203em -0.371em); top: -4.211em; left: 50%; margin-left: -0.691em;"><span class="mtd" id="MathJax-Span-4"><span class="mrow" id="MathJax-Span-5"><span class="texatom" id="MathJax-Span-6"><span class="mrow" id="MathJax-Span-7"><span class="mo" id="MathJax-Span-8" style="font-family: MathJax_Main;">|</span></span></span><span class="mi" id="MathJax-Span-9" style="font-family: MathJax_Math-italic;">x</span><span class="mn" id="MathJax-Span-10" style="font-family: MathJax_Main;">1</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.869em 1000em 3.203em -0.371em); top: -2.771em; left: 50%; margin-left: -0.691em;"><span class="mtd" id="MathJax-Span-23"><span class="mrow" id="MathJax-Span-24"><span class="texatom" id="MathJax-Span-25"><span class="mrow" id="MathJax-Span-26"><span class="mo" id="MathJax-Span-27" style="font-family: MathJax_Main;">|</span></span></span><span class="mi" id="MathJax-Span-28" style="font-family: MathJax_Math-italic;">x</span><span class="mn" id="MathJax-Span-29" style="font-family: MathJax_Main;">2</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.869em 1000em 3.203em -0.371em); top: -1.277em; left: 50%; margin-left: -0.691em;"><span class="mtd" id="MathJax-Span-45"><span class="mrow" id="MathJax-Span-46"><span class="texatom" id="MathJax-Span-47"><span class="mrow" id="MathJax-Span-48"><span class="mo" id="MathJax-Span-49" style="font-family: MathJax_Main;">|</span></span></span><span class="mi" id="MathJax-Span-50" style="font-family: MathJax_Math-italic;">x</span><span class="mn" id="MathJax-Span-51" style="font-family: MathJax_Main;">3</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span></span><span style="display: inline-block; width: 0px; height: 4.909em;"></span></span><span style="position: absolute; clip: rect(2.509em 1000em 6.563em -0.477em); top: -4.744em; left: 2.403em;"><span style="display: inline-block; position: relative; width: 1.016em; height: 0px;"><span style="position: absolute; clip: rect(1.976em 1000em 3.149em -0.477em); top: -4.211em; left: 50%; margin-left: -0.477em;"><span class="mtd" id="MathJax-Span-11"><span class="mrow" id="MathJax-Span-12"><span class="mi" id="MathJax-Span-13" style="font-family: MathJax_Math-italic;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-14" style="font-family: MathJax_Main;">1</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.976em 1000em 3.149em -0.477em); top: -2.771em; left: 50%; margin-left: -0.477em;"><span class="mtd" id="MathJax-Span-30"><span class="mrow" id="MathJax-Span-31"><span class="mi" id="MathJax-Span-32" style="font-family: MathJax_Math-italic;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-33" style="font-family: MathJax_Main;">2</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.976em 1000em 3.149em -0.477em); top: -1.277em; left: 50%; margin-left: -0.477em;"><span class="mtd" id="MathJax-Span-52"><span class="mrow" id="MathJax-Span-53"><span class="mi" id="MathJax-Span-54" style="font-family: MathJax_Math-italic;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-55" style="font-family: MathJax_Main;">3</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span></span><span style="display: inline-block; width: 0px; height: 4.749em;"></span></span><span style="position: absolute; clip: rect(2.349em 1000em 6.243em -0.371em); top: -4.584em; left: 4.429em;"><span style="display: inline-block; position: relative; width: 0.536em; height: 0px;"><span style="position: absolute; clip: rect(1.976em 1000em 2.936em -0.371em); top: -4.211em; left: 50%; margin-left: -0.264em;"><span class="mtd" id="MathJax-Span-15"><span class="mrow" id="MathJax-Span-16"><span class="mn" id="MathJax-Span-17" style="font-family: MathJax_Main;">1</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.976em 1000em 2.936em -0.371em); top: -2.771em; left: 50%; margin-left: -0.264em;"><span class="mtd" id="MathJax-Span-34"><span class="mrow" id="MathJax-Span-35"><span class="mn" id="MathJax-Span-36" style="font-family: MathJax_Main;">1</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.976em 1000em 2.936em -0.371em); top: -1.277em; left: 50%; margin-left: -0.264em;"><span class="mtd" id="MathJax-Span-56"><span class="mrow" id="MathJax-Span-57"><span class="mn" id="MathJax-Span-58" style="font-family: MathJax_Main;">1</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span></span><span style="display: inline-block; width: 0px; height: 4.589em;"></span></span><span style="position: absolute; clip: rect(2.563em 1000em 6.776em -0.371em); top: -4.904em; left: 5.923em;"><span style="display: inline-block; position: relative; width: 0.323em; height: 0px;"><span style="position: absolute; clip: rect(1.869em 1000em 3.203em -0.371em); top: -4.211em; left: 50%; margin-left: -0.157em;"><span class="mtd" id="MathJax-Span-18"><span class="mrow" id="MathJax-Span-19"><span class="texatom" id="MathJax-Span-20"><span class="mrow" id="MathJax-Span-21"><span class="mo" id="MathJax-Span-22" style="font-family: MathJax_Main;">|</span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.869em 1000em 3.203em -0.371em); top: -2.771em; left: 50%; margin-left: -0.157em;"><span class="mtd" id="MathJax-Span-37"><span class="mrow" id="MathJax-Span-38"><span class="texatom" id="MathJax-Span-39"><span class="mrow" id="MathJax-Span-40"><span class="mo" id="MathJax-Span-41" style="font-family: MathJax_Main;">|</span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span><span style="position: absolute; clip: rect(1.869em 1000em 3.203em -0.371em); top: -1.277em; left: 50%; margin-left: -0.157em;"><span class="mtd" id="MathJax-Span-59"><span class="mrow" id="MathJax-Span-60"><span class="texatom" id="MathJax-Span-61"><span class="mrow" id="MathJax-Span-62"><span class="mo" id="MathJax-Span-63" style="font-family: MathJax_Main;">|</span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span></span><span style="display: inline-block; width: 0px; height: 4.909em;"></span></span><span style="position: absolute; clip: rect(3.523em 1000em 4.163em -0.424em); top: -3.997em; left: 7.256em;"><span style="display: inline-block; position: relative; width: 0.803em; height: 0px;"><span style="position: absolute; clip: rect(2.243em 1000em 2.883em -0.424em); top: -2.771em; left: 50%; margin-left: -0.371em;"><span class="mtd" id="MathJax-Span-42"><span class="mrow" id="MathJax-Span-43"><span class="mo" id="MathJax-Span-44" style="font-family: MathJax_Main;">=</span></span></span><span style="display: inline-block; width: 0px; height: 2.776em;"></span></span></span><span style="display: inline-block; width: 0px; height: 4.003em;"></span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.349em;"></span></span></span><span style="border-left-width: 0.003em; border-left-style: solid; display: inline-block; overflow: hidden; width: 0px; height: 5.07em; vertical-align: -2.197em;"></span></span></nobr>
<script type="math/tex; mode=display" id="MathJax-Element-1"> \begin{array}{cccc} | x1 & y1 & 1 & | \\ | x2 & y2 & 1 & | &=\\ | x3 & y3 & 1 & | \\ \end{array} </script>

<nobr><span class="math" id="MathJax-Span-64" style="width: 27.683em; display: inline-block;"><span style="display: inline-block; position: relative; width: 22.136em; height: 0px; font-size: 125%;"><span style="position: absolute; clip: rect(3.949em 1000em 7.949em -0.424em); top: -4.744em; left: 0.003em;"><span class="mrow" id="MathJax-Span-65"><span style="display: inline-block; position: relative; width: 22.136em; height: 0px;"><span style="position: absolute; clip: rect(3.203em 1000em 4.376em -0.424em); top: -3.997em; left: 0.003em;"><span class="mi" id="MathJax-Span-66" style="font-family: MathJax_Math-italic;">x</span><span class="mn" id="MathJax-Span-67" style="font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-68" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mi" id="MathJax-Span-69" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-70" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-71" style="font-family: MathJax_Main; padding-left: 0.216em;">+</span><span class="mi" id="MathJax-Span-72" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-73" style="font-family: MathJax_Main;">3</span><span class="mo" id="MathJax-Span-74" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mi" id="MathJax-Span-75" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-76" style="font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-77" style="font-family: MathJax_Main; padding-left: 0.216em;">+</span><span class="mi" id="MathJax-Span-78" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-79" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-80" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mi" id="MathJax-Span-81" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-82" style="font-family: MathJax_Main;">3</span><span class="mo" id="MathJax-Span-83" style="font-family: MathJax_Main; padding-left: 0.216em;">−</span><span class="mi" id="MathJax-Span-84" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-85" style="font-family: MathJax_Main;">3</span><span class="mo" id="MathJax-Span-86" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mi" id="MathJax-Span-87" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-88" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-89" style="font-family: MathJax_Main; padding-left: 0.216em;">−</span><span class="mi" id="MathJax-Span-90" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-91" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-92" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mi" id="MathJax-Span-93" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-94" style="font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-95" style="font-family: MathJax_Main; padding-left: 0.216em;">−</span><span class="mi" id="MathJax-Span-96" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-97" style="font-family: MathJax_Main;">1</span><span style="display: inline-block; width: 0px; height: 4.003em;"></span></span><span style="position: absolute; clip: rect(3.096em 1000em 4.429em -0.424em); top: -2.611em; left: 0.003em;"><span class="mo" id="MathJax-Span-98" style="font-family: MathJax_Main;">∗</span><span class="mi" id="MathJax-Span-99" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-100" style="font-family: MathJax_Main;">3</span><span class="mo" id="MathJax-Span-101" style="font-family: MathJax_Main; padding-left: 0.269em;">=</span><span class="mi" id="MathJax-Span-102" style="font-family: MathJax_Math-italic; padding-left: 0.269em;">x</span><span class="mn" id="MathJax-Span-103" style="font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-104" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mi" id="MathJax-Span-105" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-106" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-107" style="font-family: MathJax_Main; padding-left: 0.216em;">−</span><span class="mi" id="MathJax-Span-108" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-109" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-110" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mi" id="MathJax-Span-111" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-112" style="font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-113" style="font-family: MathJax_Main; padding-left: 0.216em;">+</span><span class="mi" id="MathJax-Span-114" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-115" style="font-family: MathJax_Main;">3</span><span class="mo" id="MathJax-Span-116" style="font-family: MathJax_Main; padding-left: 0.216em;">∗</span><span class="mo" id="MathJax-Span-117" style="font-family: MathJax_Main; padding-left: 0.216em;">(</span><span class="mi" id="MathJax-Span-118" style="font-family: MathJax_Math-italic;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-119" style="font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-120" style="font-family: MathJax_Main; padding-left: 0.216em;">−</span><span class="mi" id="MathJax-Span-121" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-122" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-123" style="font-family: MathJax_Main;">)</span><span class="mo" id="MathJax-Span-124" style="font-family: MathJax_Main; padding-left: 0.216em;">+</span><span class="mi" id="MathJax-Span-125" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">y<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span><span class="mn" id="MathJax-Span-126" style="font-family: MathJax_Main;">3</span><span style="display: inline-block; width: 0px; height: 4.003em;"></span></span><span style="position: absolute; clip: rect(3.096em 1000em 4.429em -0.424em); top: -1.171em; left: 0.003em;"><span class="mo" id="MathJax-Span-127" style="font-family: MathJax_Main;">∗</span><span class="mo" id="MathJax-Span-128" style="font-family: MathJax_Main; padding-left: 0.216em;">(</span><span class="mi" id="MathJax-Span-129" style="font-family: MathJax_Math-italic;">x</span><span class="mn" id="MathJax-Span-130" style="font-family: MathJax_Main;">2</span><span class="mo" id="MathJax-Span-131" style="font-family: MathJax_Main; padding-left: 0.216em;">−</span><span class="mi" id="MathJax-Span-132" style="font-family: MathJax_Math-italic; padding-left: 0.216em;">x</span><span class="mn" id="MathJax-Span-133" style="font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-134" style="font-family: MathJax_Main;">)</span><span style="display: inline-block; width: 0px; height: 4.003em;"></span></span></span></span><span style="display: inline-block; width: 0px; height: 4.749em;"></span></span></span><span style="border-left-width: 0.003em; border-left-style: solid; display: inline-block; overflow: hidden; width: 0px; height: 4.803em; vertical-align: -3.863em;"></span></span></nobr><script type="math/tex" id="MathJax-Element-2">x1*y2+x3*y1+x2*y3-x3*y2-x2*y1-x1*y3 = x1*y2-x2*y1+x3*(y1-y2)+y3*(x2-x1) </script>

而且当点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

做完我来运行

这里写图片描述

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics