Пример #1
0
        /*public List<Point> bucket_sort(Convex_hull arr)
         * {
         *      arr.domain();
         *      List<Point> res = new List<Point>();
         *      List<List<Point>> bucket = new List<List<Point>>();
         *      for(int i=0;i < arr.size; i++)
         *      {
         *              List<Point> tmp = new List<Point>();
         *              bucket.Add(tmp);
         *      }
         *      for (int i = 0; i < arr.size; i++)
         *              bucket[arr.msbits(arr.points[i].y, size)].Add(arr.points[i]);
         *      for (int i = 0; i < size; i++)
         *              bucket[i].Sort(cmp_y);
         *      for (int i = 0; i < size; i++)
         *              res.AddRange(bucket[i]);
         *      return res;
         * }*/
        public Tuple <List <Point>, List <Point> > bucket_sort(Convex_hull arr)
        {
            arr.domain();
            List <Point>         left   = new List <Point>();
            List <Point>         right  = new List <Point>();
            List <List <Point> > bucket = new List <List <Point> >();

            for (int i = 0; i < Convert.ToInt32(max_y) - Convert.ToInt32(min_y) + 1; i++)
            {
                List <Point> tmp = new List <Point>();
                bucket.Add(tmp);
            }
            for (int i = 0; i < arr.size; i++)
            {
                bucket[arr.msbits(arr.points[i].y)].Add(arr.points[i]);
            }
            for (int i = 0; i < Convert.ToInt32(max_y) - Convert.ToInt32(min_y) + 1; i++)
            {
                bucket[i].Sort(cmp_y);
                if (bucket[i].Count > 0)
                {
                    left.Add(bucket[i][0]);
                    right.Add(bucket[i][bucket[i].Count - 1]);
                }
            }
            Tuple <List <Point>, List <Point> > res = new Tuple <List <Point>, List <Point> >(left, right);

            return(res);
        }
Пример #2
0
        static int Main(string[] args)
        {
            Convex_hull              t      = new Convex_hull("points.txt");
            List <Point>             tmp1   = new List <Point>();
            List <Point>             tmp2   = new List <Point>();
            List <Point>             tmp3   = new List <Point>();
            List <Point>             tmp4   = new List <Point>();
            List <Tuple <int, int> > tmp0   = new  List <Tuple <int, int> >();
            List <Line>              visual = new List <Line>();

            tmp1 = t.Grehem();
            tmp2 = t.Kirkpatrick();
            tmp3 = t.Edwin_Jarvis(visual);
            tmp4 = t.Quickhull(visual);
            List <List <Tuple <Line, int> > > tmp = new List <List <Tuple <Line, int> > >();

            tmp  = t.Voronoi();
            tmp0 = t.Delaunay();
            //Console.ReadKey();
            Tuple <List <Point>, List <Point> > r  = t.bucket_sort(t);
            List <Tuple <Line, int> >           t4 = new List <Tuple <Line, int> >();

            t4 = t.Voronoi_cell(4, visual);
            //Console.ReadKey();
            return(0);
        }
Пример #3
0
        public List <Point> Kirkpatrick(Tuple <List <Line>, List <Line>, List <Line> > visual)
        {
            Tuple <List <Point>, List <Point> > tmp = bucket_sort(this);
            Convex_hull  l     = new Convex_hull(tmp.Item1.Count, tmp.Item1);
            Convex_hull  r     = new Convex_hull(tmp.Item2.Count, tmp.Item2);
            List <Line>  vis1  = new List <Line>();
            List <Point> left  = l.Quickhull(vis1);
            List <Line>  vis2  = new List <Line>();
            List <Point> right = r.Quickhull(vis2);

            left.AddRange(right);
            Convex_hull  r_and_l = new Convex_hull(left.Count, left);
            List <Line>  vis3    = new List <Line>();
            List <Point> res     = r_and_l.Quickhull(vis3);

            return(res);
        }
Пример #4
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.R))
     {
         t = new Convex_hull.Convex_hull("tmpPoints.txt");
         for (int i = 0; i < t.Size; ++i)
         {
             float x0 = (float)t.points[i].x - 7.5f;
             float y0 = (float)t.points[i].y - 5f;
             Instantiate(n0, new Vector3(x0 * 10, y0 * 10), Quaternion.identity);
         }
     }
     if (Input.GetKeyDown(KeyCode.G))
     {
         int nn = GameObject.Find("Nodes").transform.childCount;
         for (int i = 0; i < nn; ++i)
         {
             Destroy(GameObject.Find("Nodes").transform.GetChild(i));
         }
         List <Point> tmp = new List <Point>();
         for (int i = 0; i < count; ++i)
         {
             float x0 = Random.Range(-7.5f, 7.5f);
             float y0 = Random.Range(-5f, 5f);
             Instantiate(n0, new Vector3(x0 * 10, y0 * 10), Quaternion.identity);
             tmp.Add(new Point(i, x0 + 7.5f, y0 + 5));
         }
         t = new Convex_hull.Convex_hull(count, tmp);
     }
     if (Input.GetKeyDown(KeyCode.V))
     {
         System.DateTime tt = System.DateTime.Now;
         List <List <System.Tuple <Line, int> > > toVis = t.Voronoi();
         for (int pn = 0; pn < toVis.Count; ++pn)
         {
             //for (int i = 0; i < toVis[pn].Count; ++i)
             //{
             //	int j = 0;
             //	for (int jj = 0; jj < pn; ++jj)
             //		j += toVis[jj].Count;
             //	StartCoroutine(toVisSegm(true, j + i, ((float)toVis[pn][i].Item1.a.x - 7.5f) * 10f, ((float)toVis[pn][i].Item1.a.y - 5) * 10f, ((float)toVis[pn][i].Item1.b.x - 7.5f) * 10f, ((float)toVis[pn][i].Item1.b.y - 5) * 10f));
             //}
             StartCoroutine(toVisAll(pn * 5 / (float)count, "n" + (pn + 1).ToString(), toVis[pn]));
         }
         Debug.Log((System.DateTime.Now - tt).ToString());
     }
     if (Input.GetKeyDown(KeyCode.H))
     {
         Destroy(lr);
         List <Point> visual = t.Grehem();
         StartCoroutine(toVisHull(0, visual, Color.gray));
     }
     if (Input.GetKeyDown(KeyCode.K))
     {
         Destroy(lr);
         List <Point> toVis = t.Kirkpatrick();
         StartCoroutine(toVisHull(0, toVis, Color.magenta));
     }
     if (Input.GetKeyDown(KeyCode.E))
     {
         Destroy(lr);
         List <Line>  toVis  = new List <Line>();
         List <Point> visual = t.Edwin_Jarvis(toVis);
         StartCoroutine(toVisHull(0, visual, Color.red));
     }
     if (Input.GetKeyDown(KeyCode.Q))
     {
         Destroy(lr);
         List <Line>  toVis  = new List <Line>();
         List <Point> visual = t.Quickhull(toVis);
         StartCoroutine(toVisHull(0, visual, Color.blue));
     }
     if (Input.GetKeyDown(KeyCode.D))
     {
         //Destroy(lr);
         t.max_x += 100;
         t.max_y += 100;
         t.min_x -= 100;
         t.min_y -= 100;
         List <System.Tuple <int, int> > toVis = t.Delaunay();
         for (int i = 0; i < toVis.Count; ++i)
         {
             GameObject p = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
             p.transform.position = new Vector3(0, 0, 100);
             StartCoroutine(toVisSegmN(p, i * 5 / (float)toVis.Count, ((float)t.points[toVis[i].Item1].x - 7.5f) * 10f, ((float)t.points[toVis[i].Item1].y - 5f) * 10f, ((float)t.points[toVis[i].Item2].x - 7.5f) * 10f, ((float)t.points[toVis[i].Item2].y - 5f) * 10f));
         }
     }
 }