예제 #1
0
        public static List <Vector2> MinLeastSquare(List <Vector2> polygonPoints, float threshold = 0.1f)
        {
            GeoPolygonUtils.ReverseIfCW(ref polygonPoints);
            List <Vector2> temp   = new List <Vector2>();
            List <Vector2> result = new List <Vector2>();

            temp.AddRange(polygonPoints);
            int count = polygonPoints.Count;

            for (int i = 0; i < temp.Count;)
            {
                result.Add(temp[i]);
                int n = i + 2;
                while (n < temp.Count && CalculateLeastSquare(i, n, temp, threshold))
                {
                    ++n;
                }
                i = n - 1;
            }
            if (result.Count != count)
            {
                result = MinLeastSquare(result);
            }
            return(result);
        }
예제 #2
0
        public static List <Vector3> CalculateConvexHull(List <Vector3> vertices, bool use2d, int ignore = 1)
        {
            List <Vector3> temp = new List <Vector3>();

            if (use2d)
            {
                int x = 0;
                int y = 1;
                if (ignore == 0)
                {
                    x = 1;
                    y = 2;
                }
                else if (ignore == 1)
                {
                    x = 0;
                    y = 2;
                }
                else
                {
                    x = 0;
                    y = 1;
                }
                List <Vector2> temp2 = new List <Vector2>();
                foreach (Vector3 v in vertices)
                {
                    temp2.Add(new Vector2(v[x], v[y]));
                }
                temp2 = JarvisConvex.BuildHull(temp2);
                GeoPolygonUtils.ReverseIfCW(ref temp2);
                foreach (Vector2 v in temp2)
                {
                    temp.Add(vertices.Find((Vector3 v3) => { return(v3[x] == v[0] && v3[y] == v[1]); }));
                }
            }
            else
            {
                temp = QuickHull.BuildHull(vertices);
            }
            return(temp);
        }