public static bool Create3D(IList <Vector3> points, out int[] indices, out int dimension, float epsilon = 1E-05f)
 {
     if (points == null || points.Count == 0)
     {
         indices   = null;
         dimension = -1;
         return(false);
     }
     epsilon = ((epsilon >= 0f) ? epsilon : 0f);
     return(ConvexHull3.Create(points, epsilon, out dimension, out indices));
 }
        public static bool Create(IList <Vector3> vertices, float epsilon, out int dimension, out int[] indices)
        {
            Vector3ex.Information information = Vector3ex.GetInformation(vertices, epsilon);
            if (information == null)
            {
                dimension = -1;
                indices   = null;
                return(false);
            }
            int count = vertices.Count;

            if (information.Dimension == 0)
            {
                dimension = 0;
                int[] array = new int[1];
                indices = array;
                return(true);
            }
            if (information.Dimension == 1)
            {
                float[] array2 = new float[count];
                Vector3 origin = information.Origin;
                Vector3 vector = information.Direction[0];
                for (int i = 0; i < count; i++)
                {
                    Vector3 value = vertices[i] - origin;
                    array2[i] = vector.Dot(value);
                }
                ConvexHull1.Create(array2, epsilon, out dimension, out indices);
                return(true);
            }
            if (information.Dimension == 2)
            {
                Vector2[] array3  = new Vector2[count];
                Vector3   origin2 = information.Origin;
                Vector3   vector2 = information.Direction[0];
                Vector3   vector3 = information.Direction[1];
                for (int j = 0; j < count; j++)
                {
                    Vector3 value2 = vertices[j] - origin2;
                    array3[j] = new Vector2(vector2.Dot(value2), vector3.Dot(value2));
                }
                return(ConvexHull2.Create(array3, epsilon, out dimension, out indices));
            }
            dimension = 3;
            Vector3[] array4 = new Vector3[count];
            Vector3   min    = information.Min;
            float     d      = 1f / information.MaxRange;

            for (int k = 0; k < count; k++)
            {
                array4[k] = (vertices[k] - min) * d;
            }
            Query3 query = new Query3(array4);
            int    v     = information.Extreme[0];
            int    num   = information.Extreme[1];
            int    num2  = information.Extreme[2];
            int    num3  = information.Extreme[3];

            ConvexHull3.Triangle triangle;
            ConvexHull3.Triangle triangle2;
            ConvexHull3.Triangle triangle3;
            ConvexHull3.Triangle triangle4;
            if (information.ExtremeCCW)
            {
                triangle  = new ConvexHull3.Triangle(v, num, num3);
                triangle2 = new ConvexHull3.Triangle(v, num2, num);
                triangle3 = new ConvexHull3.Triangle(v, num3, num2);
                triangle4 = new ConvexHull3.Triangle(num, num2, num3);
                triangle.AttachTo(triangle2, triangle4, triangle3);
                triangle2.AttachTo(triangle3, triangle4, triangle);
                triangle3.AttachTo(triangle, triangle4, triangle2);
                triangle4.AttachTo(triangle2, triangle3, triangle);
            }
            else
            {
                triangle  = new ConvexHull3.Triangle(v, num3, num);
                triangle2 = new ConvexHull3.Triangle(v, num, num2);
                triangle3 = new ConvexHull3.Triangle(v, num2, num3);
                triangle4 = new ConvexHull3.Triangle(num, num3, num2);
                triangle.AttachTo(triangle3, triangle4, triangle2);
                triangle2.AttachTo(triangle, triangle4, triangle3);
                triangle3.AttachTo(triangle2, triangle4, triangle);
                triangle4.AttachTo(triangle, triangle3, triangle2);
            }
            HashSet <ConvexHull3.Triangle> hashSet = new HashSet <ConvexHull3.Triangle>();

            hashSet.Add(triangle);
            hashSet.Add(triangle2);
            hashSet.Add(triangle3);
            hashSet.Add(triangle4);
            for (int l = 0; l < count; l++)
            {
                if (!ConvexHull3.Update(hashSet, l, query))
                {
                    dimension = -1;
                    indices   = null;
                    return(false);
                }
            }
            ConvexHull3.ExtractIndices(hashSet, out indices);
            return(true);
        }