示例#1
0
文件: DelTri.cs 项目: hnjm/TileMap2D
        public List <Triangule> Triangulate()
        {
            res.Clear();
            Triangule      root = new Triangule();
            Pair           pair;
            List <Point2D> leftOverPointsTemp = new List <Point2D>(leftOverPoints);
            List <Point2D> leftOverPoints2    = new List <Point2D>(leftOverPoints);

            foreach (Point2D[] p in GetRandomPoints())
            {
                if (!HasPointsInside(p[0], p[1], p[2]))
                {
                    root = new Triangule(p[0], p[1], p[2]);
                    res.Add(root);
                    leftOverPointsTemp.Remove(p[0]);
                    leftOverPointsTemp.Remove(p[1]);
                    leftOverPointsTemp.Remove(p[2]);
                    pair = Triangulate(leftOverPointsTemp, res);
                    if (pair.ok)
                    {
                        return(pair.res);
                    }
                    else
                    {
                        res.RemoveAt(0);
                        leftOverPointsTemp = leftOverPoints2;
                    }
                }
            }
            return(null);
        }
示例#2
0
文件: DelTri.cs 项目: hnjm/TileMap2D
        private bool HasPointsInside(Point2D point2D, Point2D point2D_2, Point2D point2D_3)
        {
            List <Triangule> list = new List <Triangule>();
            Triangule        t    = new Triangule(point2D, point2D_2, point2D_3);

            list.Add(t);
            Dictionary <Triangule, Circle> dict = GetCircumcicles(list);

            foreach (Point2D p in points)
            {
                if (!p.Equals(point2D) && !p.Equals(point2D_2) && !p.Equals(point2D_3))
                {
                    if (Math.Pow(p.x - dict[t].center.x, 2) + Math.Pow(p.y - dict[t].center.y, 2) <= Math.Pow(dict[t].radius, 2))
                    {
                        return(true);
                    }
                }
            }
            return(false);
            //float[,] matrix = new float[3, 3];
            //Triangule t = new Triangule(point2D, point2D_2, point2D_3);
            //foreach (Point2D p in points)
            //{
            //    //if (res.Find(t => t.a.Equals(p) || t.b.Equals(p) || t.c.Equals(p)) == null && !p.Equals(point2D) && !p.Equals(point2D_2) && !p.Equals(point2D_3))
            //    if (!p.Equals(point2D) && !p.Equals(point2D_2) && !p.Equals(point2D_3))
            //    {
            //        matrix = new float[3, 3];
            //        matrix[0, 0] = t.a.x - p.x;
            //        matrix[0, 1] = t.a.y - p.y;
            //        matrix[0, 2] = (float)(Math.Pow(matrix[0, 0], 2) + Math.Pow(matrix[0, 1], 2));
            //        matrix[1, 0] = t.b.x - p.x;
            //        matrix[1, 1] = t.b.y - p.y;
            //        matrix[1, 2] = (float)(Math.Pow(matrix[1, 0], 2) + Math.Pow(matrix[1, 1], 2));
            //        matrix[2, 0] = t.c.x - p.x;
            //        matrix[2, 1] = t.c.y - p.y;
            //        matrix[2, 2] = (float)(Math.Pow(matrix[2, 0], 2) + Math.Pow(matrix[2, 1], 2));

            //        if (CalculateDeterminant(matrix) > 0)
            //            return true;
            //    }
            //}
            //return false;
        }
示例#3
0
文件: DelTri.cs 项目: hnjm/TileMap2D
        public override bool Equals(object obj)
        {
            Triangule other = obj as Triangule;

            return(other.a.Equals(a) && other.b.Equals(b) && other.c.Equals(c));
        }