Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int  x1, x2, y1, y2, z1, z2;
            int  dim1, dim2;
            bool finish = true;

            while (finish)
            {
                Console.WriteLine("Write the coordinates of the first figure:");
                Console.WriteLine("X:");
                x1 = int.Parse(Console.ReadLine());
                Console.WriteLine("Y:");
                y1 = int.Parse(Console.ReadLine());
                Console.WriteLine("Z:");
                z1 = int.Parse(Console.ReadLine());
                Console.WriteLine("Write the dimension of the first figure:");
                dim1 = int.Parse(Console.ReadLine());
                Cube cube1 = new Cube(x1, y1, z1, dim1);

                Console.WriteLine("Write the coordinates of the second figure:");
                Console.WriteLine("X:");
                x2 = int.Parse(Console.ReadLine());
                Console.WriteLine("Y:");
                y2 = int.Parse(Console.ReadLine());
                Console.WriteLine("Z:");
                z2 = int.Parse(Console.ReadLine());
                Console.WriteLine("Write the dimension of the first figure:");
                dim2 = int.Parse(Console.ReadLine());
                Cube cube2 = new Cube(x2, y2, z2, dim2);

                if (cube1.Collided(cube2))
                {
                    Prism prism = cube1.CalculateCollision(cube2);
                    prism.Display();
                }
                else
                {
                    Console.WriteLine("These two figures don't collide!");
                }
            }
        }
Exemplo n.º 2
0
        public Prism CalculateCollision(Cube cube2)
        {
            decimal b, h, w;

            //Calculate base
            if (cube2.Center_x >= Center_x)
            {
                b = (Center_x + Dimensions / 2) - (cube2.Center_x - cube2.Dimensions / 2);
            }
            else
            {
                b = (cube2.Center_x + cube2.Dimensions / 2) - (Center_x - Dimensions / 2);
            }
            //Calculate height
            if (cube2.Center_y >= Center_y)
            {
                h = (Center_y + Dimensions / 2) - (cube2.Center_y - cube2.Dimensions / 2);
            }
            else
            {
                h = (cube2.Center_y + cube2.Dimensions / 2) - (Center_y - Dimensions / 2);
            }

            //Calculate width
            if (cube2.Center_z >= Center_z)
            {
                w = (Center_z + Dimensions / 2) - (cube2.Center_z - cube2.Dimensions / 2);
            }
            else
            {
                w = (cube2.Center_z + cube2.Dimensions / 2) - (Center_z - Dimensions / 2);
            }

            Prism result = new Prism(b / 2, h / 2, w / 2, b, h, w);

            return(result);
        }