Beispiel #1
0
 private static BoundingBox Find_via_MC_ApproachOne(TessellatedSolid ts)
 {
     BoundingBox minBox = new BoundingBox();
     var minVolume = double.PositiveInfinity;
     foreach (var convexHullEdge in ts.ConvexHullEdges)
     {
         var rotAxis = convexHullEdge.Vector.normalize();
         var n = convexHullEdge.OwnedFace.Normal;
         var numSamples = (int)Math.Ceiling((Math.PI - convexHullEdge.InternalAngle) / MaxDeltaAngle);
         var deltaAngle = (Math.PI - convexHullEdge.InternalAngle) / numSamples;
         var edgeBBs = new BoundingBox[numSamples];
         for (var i = 0; i < numSamples; i++)
         {
             double[] direction;
             if (i == 0) direction = n;
             else
             {
                 var angleChange = i * deltaAngle;
                 var invCrossMatrix = new[,]
                 {
                     {n[0]*n[0], n[0]*n[1], n[0]*n[2]},
                     {n[1]*n[0], n[1]*n[1], n[1]*n[2]},
                     {n[2]*n[0], n[2]*n[1], n[2]*n[2]}
                 };
                 direction = invCrossMatrix.multiply(rotAxis.multiply(Math.Sin(angleChange)));
             }
             edgeBBs[i] = FindOBBAlongDirection(ts.ConvexHullVertices, direction);
             if (edgeBBs[i].Volume < minVolume)
             {
                 minBox = edgeBBs[i];
                 minVolume = minBox.Volume;
             }
         }
     }
     return minBox;
 }
Beispiel #2
0
        /// <summary>
        ///     Adjusts the orthogonal rotations.
        /// </summary>
        /// <param name="convexHullVertices">The convex hull vertices.</param>
        /// <param name="minOBB">The minimum obb.</param>
        /// <returns>BoundingBox.</returns>
        private static BoundingBox AdjustOrthogonalRotations(IList <Vertex> convexHullVertices, BoundingBox minOBB)
        {
            var failedConsecutiveRotations = 0;
            var k = 0;
            var i = 0;

            do
            {
                //Find new OBB along OBB.direction2 and OBB.direction3, keeping the best OBB.
                var newObb = FindOBBAlongDirection(convexHullVertices, minOBB.Directions[i++]);
                if (newObb.Volume.IsLessThanNonNegligible(minOBB.Volume))
                {
                    minOBB = newObb;
                    failedConsecutiveRotations = 0;
                }
                else
                {
                    failedConsecutiveRotations++;
                }
                if (i == 3)
                {
                    i = 0;
                }
                k++;
            } while (failedConsecutiveRotations < 3 && k < MaxRotationsForOBB);
            return(minOBB);
        }