Beispiel #1
0
 public Triangle(Tin_Point mp1, Tin_Point mp2, Tin_Point mp3, Circle circle)
 {
     this.p1        = mp1;
     this.p2        = mp2;
     this.p3        = mp3;
     this.outcircle = circle;
 }
Beispiel #2
0
 public int Division(List <Tin_Point> list, int left, int right)
 {
     while (left < right)
     {
         double    num  = list[left].X;
         Tin_Point tnum = list[left];
         if (num > list[left + 1].X)
         {
             list[left]     = list[left + 1];
             list[left + 1] = tnum;
             left++;
         }
         else
         {
             double    temp  = list[right].X;
             Tin_Point ttemp = list[right];
             list[right]    = list[left + 1];
             list[left + 1] = ttemp;
             right--;
         }
         //Console.WriteLine(string.Join(",", list));
     }
     //Console.WriteLine("---------------\n");
     return(left);
 }
Beispiel #3
0
 public Triangle(Tin_Point mp1, Tin_Point mp2, Tin_Point mp3)
 {
     this.p1 = mp1;
     this.p2 = mp2;
     this.p3 = mp3;
 }
Beispiel #4
0
        public List <Triangle> ConstructionDelaunay(List <Tin_Point> vertices)
        {
            int num = vertices.Count;

            if (num < 3)
            {
                return(null);
            }
            QuickSort qs = new QuickSort();

            qs.Mysort(vertices, 0, num - 1);//vertices已经按照x从小到大排序
            Console.WriteLine("排序完成!");
            Triangle super = SuperTriangle(vertices);

            Console.WriteLine("supertriangle" + super.ToString());
            Console.WriteLine("超级三角形构建完成!");
            List <Triangle> open   = new List <Triangle>();
            List <Triangle> closed = new List <Triangle>();
            List <Edges>    edges  = new List <Edges>();

            open.Add(super);
            Console.WriteLine("超级三角形p1,p2,p3:" + super.p1.X + "," + super.p1.Y + " ; " + super.p2.X + "," + super.p2.Y + " ; " + super.p3.X + "," + super.p3.Y);
            Console.WriteLine("已将超级三角形加入未确定三角形列表");

            /*for(int i = 0; i < vertices.Count; i++)
             * {
             *  Console.WriteLine(vertices[i].Num + ":" + vertices[i].X + "," + vertices[i].Y);
             * }*/
            //Console.ReadKey();
            for (int i = 0; i < num; i++)
            {
                edges.Clear();
                Console.WriteLine("i: " + i + "num: " + num);
                Tin_Point thepoint = vertices[i];
                for (int j = 0; j < open.Count; j++)
                {
                    Console.WriteLine("j: " + j + " , open.num: " + open.Count);
                    Console.WriteLine("p1: " + open[j].p1.Num + " , p2: " + open[j].p2.Num + " , p3: " + open[j].p3.Num);
                    //Console.WriteLine("thepointx:" + thepoint.X + " , " + "open[j].outcircle.X:" + open[j].outcircle.X);
                    //Console.ReadKey();
                    double dx = thepoint.X - open[j].outcircle.X;
                    if (dx > 0.0 && dx * dx > open[j].outcircle.R_pow)
                    {
                        Console.WriteLine("点" + thepoint.Num + "在圆的右侧,该三角形是Delaunay三角形,将此三角形从open加入到close!");
                        closed.Add(open[j]);
                        open.RemoveRange(j, 1);
                        j--;
                        continue;
                    }
                    double dy = thepoint.Y - open[j].outcircle.Y;
                    if (dx * dx + dy * dy - open[j].outcircle.R_pow > EPSILON)
                    {
                        Console.WriteLine("点" + thepoint.Num + "在圆的外且非右侧,该三角形不确定是Delaunay三角形,不做任何操作!");
                        continue;
                    }
                    Console.WriteLine("点" + thepoint.Num + "在圆的内侧,该三角形必不是delaunary三角形,移除三角形,并将三边加入边的集合!");
                    edges.Add(new Edges(open[j].p1, open[j].p2));
                    edges.Add(new Edges(open[j].p1, open[j].p3));
                    edges.Add(new Edges(open[j].p2, open[j].p3));
                    //问题在于查重和移除
                    open.RemoveRange(j, 1);
                    j--;
                }
                Update(edges);
                for (int j = 0; j < edges.Count; j++)
                {
                    Triangle newtriangle = new Triangle(edges[j].p1, edges[j].p2, thepoint);
                    newtriangle.outcircle = Out_Circle(newtriangle);
                    open.Add(newtriangle);
                }
            }
            Console.WriteLine("完成整体三角形选择!");
            //Console.ReadKey();
            Console.WriteLine("closed:");

            /*for (int k = 0; k < closed.Count; k++)
             * {
             *  Console.WriteLine(closed[k].ToString());
             * }
             * Console.WriteLine("closed:");
             * for (int k = 0; k < open.Count; k++)
             * {
             *  Console.WriteLine(open[k].ToString());
             * }*/
            for (int i = 0; i < open.Count; i++)
            {
                closed.Add(open[i]);
            }
            open.Clear();
            for (int i = 0; i < closed.Count; i++)
            {
                if (!RemoveSuper(closed[i], super))
                {
                    open.Add(closed[i]);
                }
            }
            return(open);
        }
Beispiel #5
0
 public Edges(Tin_Point mp1, Tin_Point mp2)
 {
     this.p1 = mp1;
     this.p2 = mp2;
 }