Exemple #1
0
        // Get the intersection box formed by two overlapped Cubes
        public static I3dObject CubeIntersec(Cube cube1, Cube cube2)
        {
            // Look and fit for Max and Min cube by it's volume
            Cube maxCube = (cube1.Volume() > cube2.Volume()) ? cube1 : cube2;
            Cube minCube = (cube1.Volume() <= cube2.Volume()) ? cube1 : cube2;

            // Look for any intersection vertex, min cube based
            bool cubesIntersect = false;

            for (short i = 0; i <= 7; i++)
            {
                if (IsInside(maxCube, minCube.Vertex(i)))
                {
                    cubesIntersect = true;
                }
            }

            // If cubes don't intersect, returns null
            if (cubesIntersect == false)
            {
                return(null);
            }

            // Look for intersection volume
            return(new Box(
                       (minCube.MinDimension(Dimension.Axis.x) < maxCube.MinDimension(Dimension.Axis.x)) ? maxCube.MinDimension(Dimension.Axis.x) : minCube.MinDimension(Dimension.Axis.x),
                       (minCube.MaxDimension(Dimension.Axis.x) > maxCube.MaxDimension(Dimension.Axis.x)) ? maxCube.MaxDimension(Dimension.Axis.x) : minCube.MaxDimension(Dimension.Axis.x),

                       (minCube.MinDimension(Dimension.Axis.y) < maxCube.MinDimension(Dimension.Axis.y)) ? maxCube.MinDimension(Dimension.Axis.y) : minCube.MinDimension(Dimension.Axis.y),
                       (minCube.MaxDimension(Dimension.Axis.y) > maxCube.MaxDimension(Dimension.Axis.y)) ? maxCube.MaxDimension(Dimension.Axis.y) : minCube.MaxDimension(Dimension.Axis.y),

                       (minCube.MinDimension(Dimension.Axis.z) < maxCube.MinDimension(Dimension.Axis.z)) ? maxCube.MinDimension(Dimension.Axis.z) : minCube.MinDimension(Dimension.Axis.z),
                       (minCube.MaxDimension(Dimension.Axis.z) > maxCube.MaxDimension(Dimension.Axis.z)) ? maxCube.MaxDimension(Dimension.Axis.z) : minCube.MaxDimension(Dimension.Axis.z)
                       ));
        }
Exemple #2
0
        public void I3dObject_Volume_NonNegative()
        {
            bool failed = false;

            for (int i = 0; i < 100; i++)
            {
                var object1 = new Cubes.Cube(new Point(new Random().NextDouble(), new Random().NextDouble(), new Random().NextDouble()), new Random().NextDouble());
                if (object1.Volume() < 0)
                {
                    failed = true; break;
                }
            }

            Assert.IsFalse(failed);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // Create two cubes
            Cube cube1 = new Cube(new Point(1, 1, 1), 4);
            Cube cube2 = new Cube(new Point(1, 1, 2), 3);

            // Print some info
            Console.WriteLine("First cube's side is {0}, centered at ({1},{2},{3}) and it's Volume is: {4}", cube1.Side, cube1.Center.X, cube1.Center.Y, cube1.Center.Z, cube1.Volume().ToString());
            Console.WriteLine("Second cube's side is {0}, centered at ({1},{2},{3}) and it's Volume is: {4}", cube2.Side, cube2.Center.X, cube2.Center.Y, cube2.Center.Z, cube2.Volume().ToString());

            // Calculate intersection box
            I3dObject intersect = Operators.CubeIntersec(cube1, cube2);

            // Print result
            Console.WriteLine("Intersection Volume is: {0}", (intersect == null) ? "0" : intersect.Volume().ToString());
        }