ChronoEngine_SwAddin.ConvertToCollisionShapes.SWbodyToConvexHull C# (CSharp) Method

SWbodyToConvexHull() public static method

public static SWbodyToConvexHull ( Body2 swBody, System.Windows.Media.Media3D.Point3D &vertexes, int maxvertexes ) : bool
swBody Body2
vertexes System.Windows.Media.Media3D.Point3D
maxvertexes int
return bool
        public static bool SWbodyToConvexHull(Body2 swBody,
                                          ref Point3D[] vertexes, int maxvertexes)
        {
            bool ishull = false;

            if (swBody.GetVertexCount() <= maxvertexes)
            {
                object[] mfaces = (object[])swBody.GetFaces();
                object[] medges = (object[])swBody.GetEdges();
                object[] mverts = (object[])swBody.GetVertices();

                ishull = true;

                // rejective test 1: are all faces as planes?
                bool allplanes = true;
                for (int i = 0; i < swBody.GetFaceCount(); i++)
                {
                    Face2 aface = (Face2)mfaces[i];
                    Surface msurf = (Surface)aface.GetSurface();
                    if (!msurf.IsPlane())
                    {
                        allplanes = false;
                    }
                }
                if (!allplanes)
                    return false;

                // rejective test 2: are all edges as straight lines?
                bool allstraightedges = true;
                for (int i = 0; i < swBody.GetEdgeCount(); i++)
                {
                    Edge aedge = (Edge)medges[i];
                    Curve mcurve = (Curve)aedge.GetCurve();
                    if (!mcurve.IsLine())
                    {
                        allstraightedges = false;
                    }
                }
                if (!allstraightedges)
                    return false;

                // rejective test 3: are there holes as in tori?
                // Use Euler formula  v + f - e = 2 -2*genus
                if (swBody.GetVertexCount() + swBody.GetFaceCount() - swBody.GetEdgeCount() != 2)
                    return false;

                if (ishull)
                {
                    vertexes = new Point3D[swBody.GetVertexCount()];
                    for (int ip = 0; ip < swBody.GetVertexCount(); ip++)
                    {
                        vertexes[ip] = new  Point3D(((double[])((Vertex)mverts[ip]).GetPoint())[0],
                                                    ((double[])((Vertex)mverts[ip]).GetPoint())[1],
                                                    ((double[])((Vertex)mverts[ip]).GetPoint())[2]);
                    }
                }
            }

            return ishull;
        }

Same methods

ConvertToCollisionShapes::SWbodyToConvexHull ( Body2 swBody, int maxvertexes ) : bool