Ejemplo n.º 1
0
    public void AlgorithmHullFaces()
    {
        var triangles = mConvexHull3.Triangles;
        var dataCloud = mConvexHull3.DataCloud;
        var points    = mConvexHull3.Vertices;

        if (triangles.Count < 4)
        {
            Debugger.Get.Log("Insufficient points to form a tetrahedron.", DebugOption.SBB3);
            return;
        }

        mVolume = float.MaxValue;
        foreach (Triangle triangle in triangles)
        {
            List <Vector3> localPoints = new List <Vector3>(triangles.Count * 3);

            float farthestDistance = -float.MaxValue;
            foreach (int point in points)
            {
                Vector3 dataCloudPoint = dataCloud[point];

                float distance = Mathf.Abs(triangle.CalculateDistance(dataCloudPoint));
                farthestDistance = Mathf.Max(farthestDistance, distance);

                localPoints.Add(triangle.ToLocal(dataCloudPoint));
            }

            ConvexHull2 ch2 = new ConvexHull2(localPoints);
            ch2.AlgorithmQuickhull();

            OBB2 obb2 = new OBB2(ch2);
            obb2.AlgorithmRotatingCalipers();

            float newVolume = obb2.Area * farthestDistance;
            if (newVolume < mVolume)
            {
                mVolume = newVolume;

                var worldRect = new {
                    BottomLeftCorner  = triangle.ToWorld(obb2.Rectangle.Corner),
                    BottomRightCorner = triangle.ToWorld(obb2.Rectangle.Corner + obb2.Rectangle.X * obb2.Rectangle.Extents.x),
                    TopLeftCorner     = triangle.ToWorld(obb2.Rectangle.Corner + obb2.Rectangle.Y * obb2.Rectangle.Extents.y)
                };

                mBox.Extents = new Vector3(obb2.Rectangle.Extents.x, obb2.Rectangle.Extents.y, farthestDistance);
                mBox.Corner  = worldRect.BottomLeftCorner;
                mBox.X       = (worldRect.BottomRightCorner - mBox.Corner).normalized;
                mBox.Y       = (worldRect.TopLeftCorner - mBox.Corner).normalized;
                mBox.Z       = -triangle.N; // Triangle normal always points outside convex hull.
            }
        }
    }
Ejemplo n.º 2
0
    void On2D()
    {
        wireframeCube.Clear();
        ch2.DataCloud = mDataCloud;

        ch2.AlgorithmQuickhull();
        obb2.AlgorithmRotatingCalipers();

        displayDataCloud.dataCloud = mDataCloud;
        meshFilter.mesh            = ch2.GetMesh();
        wireframeRectangle.FromRectangle(obb2.Rectangle);
    }