Exemplo n.º 1
0
    static void Main()
    {
        var input = Console.ReadLine();


        while (!input.Equals("End"))
        {
            var inputArgs = input
                            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            switch (inputArgs[0])
            {
            case "Cube":
                result.AppendLine($"{VolumeCalculator.CubeVolume(new Cube(double.Parse(inputArgs[1]))):F3}");
                break;

            case "Cylinder":
                result.AppendLine($"{VolumeCalculator.CylinderVolume(new Cylinder(double.Parse(inputArgs[1]), double.Parse(inputArgs[2]))):F3}");
                break;

            case "TrianglePrism":
                result.AppendLine($"{VolumeCalculator.TriangularPrismVolume(new TriangularPrism(double.Parse(inputArgs[1]), double.Parse(inputArgs[2]), double.Parse(inputArgs[3]))):F3}");
                break;
            }


            input = Console.ReadLine();
        }

        Console.Write(result);
    }
Exemplo n.º 2
0
    public static void Main()
    {
        string line = Console.ReadLine();

        while (line != "End")
        {
            string[] lineAsArr = line.Split();
            string   figure    = lineAsArr[0];
            switch (figure)
            {
            case "Cube":
                Console.WriteLine("{0:0.000}", VolumeCalculator.Cube(new Cube(double.Parse(lineAsArr[1]))));
                break;

            case "Cylinder":
                Console.WriteLine("{0:0.000}", VolumeCalculator.Cylinder(new Cylinder(double.Parse(lineAsArr[1]), double.Parse(lineAsArr[2]))));
                break;

            case "TrianglePrism":
                Console.WriteLine("{0:0.000}", VolumeCalculator.TriangularPrism(new TriangularPrism(double.Parse(lineAsArr[1]), double.Parse(lineAsArr[2]), double.Parse(lineAsArr[3]))));
                break;
            }

            line = Console.ReadLine();
        }
    }
    private void Start()
    {
        mf                = GetComponent <MeshFilter>();
        water             = GameObject.Find("Water");
        ground            = GameObject.Find("Ground");
        intersectPosition = water.transform.position;
        totalVolume       = VolumeCalculator.GetTotalVolume(mf.mesh);

        Intersection.ConvertToTriangles(mf.mesh, out vertices, out triangles);
    }
Exemplo n.º 4
0
        public void Calculate_Volume_ReturnsVolume()
        {
            //Arrange
            IVolumeCalculator _calculator = new VolumeCalculator();

            //Act
            decimal volume = _calculator.CalculateVolume(12, 6, 3);

            //Assert
            Assert.IsTrue(volume > 0);
        }
Exemplo n.º 5
0
        public void Calculate_Volume_ReturnsVolume_Logic_Test()
        {
            //Arrange
            IVolumeCalculator _calculator = new VolumeCalculator();
            decimal           length = 15, width = 20, height = 3;

            //Act
            decimal volume = _calculator.CalculateVolume(length, width, height);

            //Assert
            Assert.IsTrue(volume == (length * width * height), "Volume correctly calculated");
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var arrayList = new List <IShape>();

            arrayList.Add(new Circle(2));
            arrayList.Add(new Circle(5));
            arrayList.Add(new Circle(6));

            VolumeCalculator areaCalc = new VolumeCalculator(arrayList);


            Console.WriteLine("Sum = " + areaCalc.Sum().ToString());
            Console.ReadLine();
        }
Exemplo n.º 7
0
        public double CalculateZeroBoundaryVolumeCC()
        {
            //double vol = 0;
            var contours = this.Find2DIsodoseLines(new RT.IsodoseLevel()
            {
                Value = 0
            }).FirstOrDefault().SliceContours;

            //for (int z = 0; z < DimensionZ; z++)
            //{
            //    var zPos = ImageToPatientTx(new Vector3(0, 0, z)).Z;
            //    var slice = FloatMat.WindowLevelColor(GetZPlaneBySlice(z));
            //    foreach(var contour in contours.Where(c=>c.Z == zPos))
            //    {
            //        contour.DrawOnSlice(z, PatientTransformMatrix, slice);
            //    }
            //    Cv2.ImShow("Color", slice);
            //    Cv2.WaitKey();
            //}
            //var voxelLocations = this.GetImageGridPointsPatientCoordinates();
            //for (int i = 0; i < contours.Count; i++)
            //{
            //    var contour = contours[i];
            //    contour.ContourPoints = contour.ContourPoints.Select(c =>
            //    {
            //        var index = IndexHelper.LatticeXYToIndex((int)c.X, (int)c.Y, DimensionX);
            //        return voxelLocations[index];
            //    }).ToList();
            //}
            return(VolumeCalculator.CalculateVolume(contours));

            //for (int z = 0; z < DimensionZ; z++)
            //{
            //    using (var slice = GetZPlaneBySlice(z))
            //    {
            //        var iso = slice.Find2DIsodoseLine(new RT.IsodoseLevel() { Value = 0 });
            //    }
            //}
            //return vol;
            var histogram = this.CalcHistogram(5000);
            var negative  = histogram.Count(float.MinValue, -0.001f);

            histogram.Dispose();
            return(negative * this.ZRes * this.YRes * this.XRes / 1000);
        }
Exemplo n.º 8
0
        public void OrtoedroVolumeTest(double width, double length, double depth)
        {
            var decimalWidth  = (decimal)width;
            var decimalLength = (decimal)length;
            var decimalDepth  = (decimal)depth;

            IVolumeCalculator volumeCalculator = new VolumeCalculator();
            Ortoedro          ortoedro         = new Ortoedro()
            {
                Width  = decimalWidth,
                Length = decimalLength,
                Depth  = decimalDepth
            };

            decimal volume = volumeCalculator.CalculateOrtoedroVolume(ortoedro);

            Assert.IsTrue(volume == decimalWidth * decimalLength * decimalDepth, $"Expected volume 8 but received {volume}.");
        }
    private void FixedUpdate()
    {
        if (!dragging && !start)
        {
            velocity += Gravity.Acceleration();

            float time = Time.realtimeSinceStartup;

            // Get Triangle List
            List <Triangle> underWaterTriangles = Intersection.GetTrianglesUnderWater(ref triangles, ref vertices, transform, intersectPosition);

            // Get Volume
            float volumeUnderWater = VolumeCalculator.GetVolume(ref underWaterTriangles, transform, intersectPosition);

            if (UIText != null)
            {
                float totalVolumeRounded      = Mathf.Round(totalVolume * 100f) / 100f;
                float volumeUnderWaterRounded = Mathf.Round(volumeUnderWater * 100f) / 100f;
                UIText.text = transform.name + " - Total Volume:" + totalVolumeRounded + ", Volume Under Water: " + volumeUnderWaterRounded;
            }

            // Calculate drag from air or water
            float   dragDensity = volumeUnderWater > 0f ? densityWater : densityAir;
            Vector3 drag        = Drag.GetDragForce(coefficientOfDrag, dragDensity, velocity, area);
            velocity -= drag / mass;

            // Calculate Lift
            Vector3 bouyancy = Buoyancy.Calculate(transform, intersectPosition, volumeUnderWater, totalVolume);

            // velocity += lift;
            velocity += bouyancy / mass * Time.fixedDeltaTime;

            if (transform.position.y < ground.transform.position.y)
            {
                Vector3 currentPosition = transform.position;
                currentPosition.y  = ground.transform.position.y;
                transform.position = currentPosition;
                velocity           = Vector3.zero;
            }
            //velocity += Lift.CalculateLift(ref myTriangles, ref myVertices, transform, intersectPosition, totalVolume) / mass * Time.fixedDeltaTime;

            ApplyVelocity();
        }
    }
Exemplo n.º 10
0
        public void Calculate_Volume_ReturnsDecimalVolumes()
        {
            //Arrange
            IVolumeCalculator _calculator = new VolumeCalculator();
            int precision = 0;

            //Act
            decimal volume = _calculator.CalculateVolume(12.00050002m, 6.49007002m, 3.045m);


            //Checks how many decimal places the calculation is accurate too
            while (volume * (decimal)Math.Pow(10, precision) !=
                   Math.Round(volume * (decimal)Math.Pow(10, precision)))
            {
                precision++;
            }

            //Assert
            Assert.IsTrue(precision >= 10, "Accurate to at least {0} decimal places", precision);
        }
    public static void Main()
    {
        var input  = Console.ReadLine();
        var result = new StringBuilder();

        while (!input.Equals("End"))
        {
            var    takeData = input.Split();
            string shape    = takeData[0];

            // Creating new objects which I do not save anywhere, and use them as parameter so I can stick to the assignment and use these objects somehow
            switch (shape)
            {
            case "Cube":
                double sideLenght = double.Parse(takeData[1]);
                result.AppendLine(VolumeCalculator.CalculateCubeVolume(new Cube(sideLenght)));
                break;

            case "Cylinder":
                double radius = double.Parse(takeData[1]);
                double height = double.Parse(takeData[2]);
                result.AppendLine(VolumeCalculator.CalculateCylinderVolume(new Cylinder(radius, height)));
                break;

            case "TrianglePrism":
                double baseSide       = double.Parse(takeData[1]);
                double triangleHeight = double.Parse(takeData[2]);
                double length         = double.Parse(takeData[3]);
                result.AppendLine(
                    VolumeCalculator.CalculateTriangularPrismVolume(new TriangularPrism(baseSide, triangleHeight, length)));
                break;
            }

            input = Console.ReadLine();
        }

        Console.WriteLine(result);
    }
        /// <summary>
        /// Handles Volume Calculate Volume(Oil/Gas) and Exit Buttons Interactions
        /// </summary>
        /// <param name="parameter"></param>
        public void ButtonClickCommandHandler(object parameter)
        {
            try
            {
                switch ((parameter.ToString().Trim()))
                {
                case "Calculate Volume":
                    if (m_TopHorizonDepthValues != null && m_TopHorizonDepthValues.Count > 0)
                    {
                        UnitofVolume unitofVolume = UnitofVolume.CubicFeet;
                        if (CubicMeter)
                        {
                            unitofVolume = UnitofVolume.CubicMeter;
                        }
                        else if (Barrel)
                        {
                            unitofVolume = UnitofVolume.Barrel;
                        }
                        if (!m_isValuesReadFromConfig)
                        {
                            ReadConfigurationValues();
                        }
                        InputParameters  objParams = new InputParameters(unitofVolume, m_gridCellArea, m_twoHorizonsDepthDiff, m_fluidContactDepth);
                        VolumeCalculator objVCalc  = new VolumeCalculator(objParams, m_TopHorizonDepthValues);
                        Volume = objVCalc.ComputeVolume();
                    }
                    break;

                case "Exit":
                    Application.Current.Shutdown();
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }