Beispiel #1
0
        private void sq(List <Point> q)
        {
            Point p0 = hul(q);

            q.Remove(p0);
            Point pn = hpn(q);

            q.Remove(pn);


            List <Point> hup = new List <Point>()
            {
                p0,
                pn
            };
            line t = new line()
            {
                x = p0,
                y = pn
            };
            line dy = new line()
            {
                x = pn,
                y = p0
            };

            sq(q, hup, t);
            sq(q, hup, dy);

            print(hup);
        }
Beispiel #2
0
        /// <summary>
        /// 分治法 快包
        /// </summary>
        /// <param name="point">所有点</param>
        /// <returns>围住</returns>
        public List <Point> divide_conquer(List <Point> point)
        {
            Point p0 = hul_long(point); //最左边点
            Point pn = hup_long(point); //最右边的点

            point.Remove(p0);
            point.Remove(pn);

            List <Point> round_point = new List <Point>()
            {
                p0,
                pn
            };

            line _line = new line()
            {
                x = p0,
                y = pn
            };

            divide_conquer(point, round_point, _line);
            _line = new line()
            {
                x = pn,
                y = p0
            };
            divide_conquer(point, round_point, _line);

            round_point = divide_conquer(round_point, true);
            return(round_point);
        }
Beispiel #3
0
        private static void divide_conquer(IList <Point> point, ICollection <Point> hup, line _line)
        {
            if (point.Count < 1)
            {
                return;
            }
            Point[] temp = new Point[point.Count];
            point.CopyTo(temp, 0);
            point = temp.ToList();

            Point p;

            p.X = -1;
            p   = divide_conquer(point, _line, p);

            if (p.X < 0)
            {
                return;
            }

            hup.Add(p);
            line dy = new line()
            {
                x = _line.x,
                y = p
            };

            divide_conquer(point, hup, dy);
            dy = new line()
            {
                x = p,
                y = _line.y
            };
            divide_conquer(point, hup, dy);
        }
Beispiel #4
0
        private void sq(List <Point> q, List <Point> hup, line t)
        {
            if (q.Count < 1)
            {
                return;
            }
            Point p;

            p.X = -1;
            t.n = 0;

            for (int i = 0; i < q.Count; i++)
            {
                double n = sq(t, q[i]);
                if (n > 0)
                {
                    if (p == null || t.n < n)
                    {
                        p   = q[i];
                        t.n = n;
                    }
                }
                else
                {
                    q.RemoveAt(i);
                    i--;
                }
            }

            if (p.X < 0)
            {
                return;
            }

            hup.Add(p);
            line dy = new line()
            {
                x = t.x,
                y = p
            };

            sq(q, hup, dy);
            dy = new line()
            {
                x = p,
                y = t.y
            };
            sq(q, hup, dy);
        }
Beispiel #5
0
        private static Point divide_conquer(IList <Point> point, line t, Point p)
        {
            t.n = 0;

            for (int i = 0; i < point.Count; i++)
            {
                double n = pointline(t, point[i]);
                if (n > 0)
                {
                    if (p.X < 0 || t.n < n)
                    {
                        p   = point[i];
                        t.n = n;
                    }
                }
                else
                {
                    point.RemoveAt(i);
                    i--;
                }
            }

            return(p);
        }
Beispiel #6
0
 private double sq(line t, Point p)
 {
     return(t.x.X * t.y.Y + p.X * t.x.Y + t.y.X * p.Y - p.X * t.y.Y - t.y.X * t.x.Y - t.x.X * p.Y);
 }
Beispiel #7
0
 /// <summary>
 /// 点到直线
 ///
 /// </summary>
 /// <param name="t"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 private static double pointline(line t, Point p)
 {
     return(t.x.X * t.y.Y + p.X * t.x.Y + t.y.X * p.Y - p.X * t.y.Y - t.y.X * t.x.Y - t.x.X * p.Y);
 }