public void TestAssignmentsSpecialCases()
        {
            Duration        nullDur   = new Duration(0, UnitTime.Second);
            Duration        largeDur  = new Duration(20, UnitTime.Second);
            Length          nullLen   = new Length(0, UnitLength.Metre);
            MaximalHeight   nullMaxH  = new MaximalHeight(0, UnitLength.Metre);
            MaximalHeight   smallMaxH = new MaximalHeight(2, UnitLength.Metre);
            Length          smallLen  = new Length(4, UnitLength.Metre);
            InitialVelocity nullV     = new InitialVelocity(0, UnitVelocity.MetrePerSecond);
            ElevationAngle  nullΑ     = new ElevationAngle(ElevationAngle.ElevationAngleTypes.Horizontal);
            ElevationAngle  rightΑ    = new ElevationAngle(ElevationAngle.ElevationAngleTypes.Right);
            InitialHeight   nullH     = new InitialHeight(0, UnitLength.Metre);

            // should not throw the compute exception
            new ProjectileMotionQuantities(Dur, nullΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(Dur, rightΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(Dur, Α, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, Α, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, nullΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, rightΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, nullΑ, V, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, rightΑ, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, Α, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, nullΑ, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullDur, V, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(smallLen, V, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullLen, nullV, H, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(Len, nullΑ, V, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullLen, nullΑ, V, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(smallLen, nullΑ, H, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(smallLen, Α, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullLen, Α, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullLen, Α, H, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullLen, nullΑ, H, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(smallMaxH, V, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(MaxH, V, new InitialHeight(MaxH.GetConvertedVal(UnitLength.Metre), UnitLength.Metre),
                                           G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(MaxH, Α, new InitialHeight(MaxH.GetConvertedVal(UnitLength.Metre), UnitLength.Metre),
                                           G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullMaxH, Α, nullH, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(MaxH, Α, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(MaxH, nullΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(MaxH, rightΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullMaxH, rightΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullMaxH, nullΑ, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullMaxH, Α, nullV, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullMaxH, nullΑ, V, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullΑ, Len, Dur, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(nullΑ, nullLen, Dur, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(Α, nullLen, Dur, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(Α, nullLen, nullDur, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(V, nullLen, nullDur, G, Utilities.UnitsOfResults);
            new ProjectileMotionQuantities(V, nullLen, largeDur, G, Utilities.UnitsOfResults);
        }
예제 #2
0
        /// <summary>
        /// 9. Constructor for a projectile motion Quantities. Computes an initial height based on the maximal height.
        /// </summary>
        /// <param name="α">An elevation angle.</param>
        /// <param name="maxHeight">The maximal height.</param>
        /// <param name="v">An initial velocity.</param>
        /// <param name="g">A gravitation acceleration of the planet.</param>
        /// <param name="units">The units of Quantities. By default metre per second, radian, metre and metre per square second.</param>
        public ProjectileMotionQuantities(MaximalHeight maxHeight, ElevationAngle α, InitialVelocity v, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            V = v;
            Α = α;
            G = g;
            H = new InitialHeight(
                GetResultWithComputeExpection(
                    maxHeight.GetBasicVal() - Math.Pow(V.GetBasicVal() * Math.Sin(Α.GetBasicVal()), 2.0) / (2.0 * G.GetBasicVal())
                    ),
                UnitLength.Basic
                ).Convert(Units.Length);

            UsedAssignmentType = AssignmentsTypes.InitialHeightByMaxHeight;
        }
예제 #3
0
        /// <summary>
        /// 10. Constructor for a projectile motion Quantities. Computes an elevation angle based on the maximal height.
        /// </summary>
        /// <param name="v">An initial velocity.</param>
        /// <param name="dur">The maximal height.</param>
        /// <param name="h">An initial height.</param>
        /// <param name="g">A gravitation acceleration of the planet.</param>
        /// <param name="units">The units of Quantities. By default metre per second, radian, metre and metre per square second.</param>
        public ProjectileMotionQuantities(MaximalHeight maxHeight, InitialVelocity v, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            V = v;
            H = h;
            G = g;
            Α = new ElevationAngle(
                GetResultWithComputeExpection(
                    maxHeight.GetBasicVal() == 0 && H.GetBasicVal() == 0 ?
                    double.NaN
                        :
                    Math.Asin(Math.Sqrt(
                                  2.0 * G.GetBasicVal() * (maxHeight.GetBasicVal() - H.GetBasicVal()) /
                                  Math.Pow(V.GetBasicVal(), 2)
                                  ))
                    ),
                UnitAngle.Basic
                ).Convert(Units.Angle);

            UsedAssignmentType = AssignmentsTypes.ElevationAngleByMaxHeight;
        }
예제 #4
0
        /// <summary>
        /// 8. Constructor for a projectile motion Quantities. Computes an initial velocity based on the maximal height.
        /// </summary>
        /// <param name="α">An elevation angle.</param>
        /// <param name="maxHeight">The maximal height.</param>
        /// <param name="h">An initial height.</param>
        /// <param name="g">A gravitation acceleration of the planet.</param>
        /// <param name="units">The units of Quantities. By default metre per second, radian, metre and metre per square second.</param>
        public ProjectileMotionQuantities(MaximalHeight maxHeight, ElevationAngle α, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            Α = α;
            H = h;
            G = g;
            V = new InitialVelocity(
                GetResultWithComputeExpection(
                    maxHeight.GetBasicVal() == 0 && H.GetBasicVal() == 0 ?
                    Α.GetBasicVal() == 0 ?
                    double.NaN : 0
                        :
                    Math.Sqrt(
                        2.0 * G.GetBasicVal() * (maxHeight.GetBasicVal() - H.GetBasicVal()) /
                        Math.Pow(Math.Sin(Α.GetBasicVal()), 2.0)
                        )
                    ),
                UnitVelocity.Basic
                ).Convert(Units.Velocity);

            UsedAssignmentType = AssignmentsTypes.InitialVelocityByMaxHeight;
        }
예제 #5
0
        public ActionResult Properties(SetPropertiesModel postModel)
        {
            if (ModelState.IsValid)
            {
                SessionStore session = GetSession();

                InitialVelocity  v = new InitialVelocity(postModel.Quantities.InitialVelocity, new UnitsReflectionHelper <UnitVelocity>().GetUnit(postModel.Quantities.InitialVelocityUnit));
                InitialHeight    h = new InitialHeight(postModel.Quantities.InitialHeight, new UnitsReflectionHelper <UnitLength>().GetUnit(postModel.Quantities.InitialHeightUnit));
                GravAcceleration g = new GravAcceleration(postModel.Quantities.GravAcceleration, new UnitsReflectionHelper <UnitGravAcceleration>().GetUnit(postModel.Quantities.GravAccelerationUnit));
                ElevationAngle   α = new ElevationAngle(postModel.Quantities.ElevationAngle, new UnitsReflectionHelper <UnitAngle>().GetUnit(postModel.Quantities.ElevationAngleUnit));

                ProjectileMotionResultsUnits units = new ProjectileMotionResultsUnits()
                {
                    Length           = new UnitsReflectionHelper <UnitLength>().GetUnit(postModel.ResultUnitLength),
                    Time             = new UnitsReflectionHelper <UnitTime>().GetUnit(postModel.ResultUnitTime),
                    Velocity         = new UnitsReflectionHelper <UnitVelocity>().GetUnit(postModel.ResultUnitVelocity),
                    Angle            = new UnitsReflectionHelper <UnitAngle>().GetUnit(postModel.ResultUnitAngle),
                    Area             = new UnitsReflectionHelper <UnitArea>().GetUnit(postModel.ResultUnitArea),
                    GravAcceleration = new UnitsReflectionHelper <UnitGravAcceleration>().GetUnit(postModel.ResultUnitGravAcceleration)
                };

                if (postModel.Quantities.WithResistance)
                {
                    session.SaveProjectileMotionWithResistance(new ProjectileMotionWithResistance(
                                                                   new ProjectileMotionWithResistanceSettings(
                                                                       new ProjectileMotionWithResistanceQuantities(
                                                                           v, α, h, g,
                                                                           new Mass(postModel.Quantities.Mass.Value, new UnitsReflectionHelper <UnitMass>().GetUnit(postModel.Quantities.MassUnit)),
                                                                           new Density(postModel.Quantities.Density.Value, new UnitsReflectionHelper <UnitDensity>().GetUnit(postModel.Quantities.DensityUnit)),
                                                                           new FrontalArea(postModel.Quantities.FrontalArea.Value, new UnitsReflectionHelper <UnitArea>().GetUnit(postModel.Quantities.FrontalAreaUnit)),
                                                                           new DragCoefficient(postModel.Quantities.DragCoefficient.Value),
                                                                           units
                                                                           )
                                                                       )
                    {
                        RoundDigits          = postModel.RoundDigits,
                        PointsForTrajectory  = postModel.PointsForTrajectory,
                        TxtInfoFileName      = postModel.TxtInfoFileName,
                        CsvDataFileName      = postModel.CsvDataFileName,
                        PdfInfoFileName      = postModel.PdfInfoFileName,
                        ChartFileName        = postModel.ChartFileName,
                        HexColorOfTrajectory = postModel.HexColorOfTrajectory,
                        ShowMotionWithoutResistanceTrajectoryToo = postModel.ShowMotionWithoutResistanceTrajectoryToo
                    })).SaveProjectileMotion(null);

                    return(RedirectToAction(nameof(DisplayController.MotionWithResistance), "Display"));
                }


                ProjectileMotionQuantities quantitiesWithoutResistance = null;

                try
                {
                    if (new List <ProjectileMotionQuantities.AssignmentsTypes>()
                    {
                        ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByDuration,
                        ProjectileMotionQuantities.AssignmentsTypes.InitialHeightByDuration,
                        ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByDuration
                    }.Contains(postModel.Quantities.SelectedAssignmentType))
                    {
                        Duration d = new Duration(postModel.Quantities.Duration.Value, new UnitsReflectionHelper <UnitTime>().GetUnit(postModel.Quantities.DurationUnit));

                        switch (postModel.Quantities.SelectedAssignmentType)
                        {
                        case ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByDuration:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(d, v, h, g, units);
                            break;

                        case ProjectileMotionQuantities.AssignmentsTypes.InitialHeightByDuration:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(d, α, v, g, units);
                            break;

                        case ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByDuration:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(d, α, h, g, units);
                            break;
                        }
                    }
                    else if (new List <ProjectileMotionQuantities.AssignmentsTypes>()
                    {
                        ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByMaxHeight,
                        ProjectileMotionQuantities.AssignmentsTypes.InitialHeightByMaxHeight,
                        ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByMaxHeight
                    }.Contains(postModel.Quantities.SelectedAssignmentType))
                    {
                        MaximalHeight maxH = new MaximalHeight(postModel.Quantities.MaxHeight.Value, new UnitsReflectionHelper <UnitLength>().GetUnit(postModel.Quantities.MaxHeightUnit));

                        switch (postModel.Quantities.SelectedAssignmentType)
                        {
                        case ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByMaxHeight:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(maxH, v, h, g, units);
                            break;

                        case ProjectileMotionQuantities.AssignmentsTypes.InitialHeightByMaxHeight:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(maxH, α, v, g, units);
                            break;

                        case ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByMaxHeight:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(maxH, α, h, g, units);
                            break;
                        }
                    }
                    else if (new List <ProjectileMotionQuantities.AssignmentsTypes>()
                    {
                        ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByLength,
                        ProjectileMotionQuantities.AssignmentsTypes.InitialHeightByLength,
                        ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByLength
                    }.Contains(postModel.Quantities.SelectedAssignmentType))
                    {
                        Length l = new Length(postModel.Quantities.Length.Value, new UnitsReflectionHelper <UnitLength>().GetUnit(postModel.Quantities.MaxHeightUnit));

                        switch (postModel.Quantities.SelectedAssignmentType)
                        {
                        case ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByLength:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(l, v, h, g, units);
                            break;

                        case ProjectileMotionQuantities.AssignmentsTypes.InitialHeightByLength:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(l, α, v, g, units);
                            break;

                        case ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByLength:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(l, α, h, g, units);
                            break;
                        }
                    }
                    else if (postModel.Quantities.SelectedAssignmentType == ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleGetMaxRange)
                    {
                        quantitiesWithoutResistance = new ProjectileMotionQuantities(v, h, g, units);
                    }
                    else if (new List <ProjectileMotionQuantities.AssignmentsTypes>()
                    {
                        ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByLengthAndDur,
                        ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByLengthAndDur
                    }.Contains(postModel.Quantities.SelectedAssignmentType))
                    {
                        Length   l = new Length(postModel.Quantities.Length.Value, new UnitsReflectionHelper <UnitLength>().GetUnit(postModel.Quantities.MaxHeightUnit));
                        Duration d = new Duration(postModel.Quantities.Duration.Value, new UnitsReflectionHelper <UnitTime>().GetUnit(postModel.Quantities.DurationUnit));

                        switch (postModel.Quantities.SelectedAssignmentType)
                        {
                        case ProjectileMotionQuantities.AssignmentsTypes.InitialVelocityByLengthAndDur:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(α, l, d, g, units);
                            break;

                        case ProjectileMotionQuantities.AssignmentsTypes.ElevationAngleByLengthAndDur:
                            quantitiesWithoutResistance = new ProjectileMotionQuantities(v, l, d, g, units);
                            break;
                        }
                    }
                    else
                    {
                        quantitiesWithoutResistance = new ProjectileMotionQuantities(v, α, h, g, units);
                    }

                    session.SaveProjectileMotion(new ProjectileMotion(
                                                     new ProjectileMotionSettings(quantitiesWithoutResistance)
                    {
                        RoundDigits          = postModel.RoundDigits,
                        PointsForTrajectory  = postModel.PointsForTrajectory,
                        TxtInfoFileName      = postModel.TxtInfoFileName,
                        CsvDataFileName      = postModel.CsvDataFileName,
                        PdfInfoFileName      = postModel.PdfInfoFileName,
                        ChartFileName        = postModel.ChartFileName,
                        HexColorOfTrajectory = postModel.HexColorOfTrajectory
                    })).SaveProjectileMotionWithResistance(null);

                    return(RedirectToAction(nameof(DisplayController.Motion), "Display"));
                }
                catch (UnableToComputeQuantityException ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }

            postModel.Layout = new LayoutModel("Repair properties");
            postModel.Layout.Menu.SetWithResistance = postModel.Quantities.WithResistance;
            postModel.Layout.Menu.ActiveMenuItem    = LayoutMenuModel.ActiveNavItem.Set;
            return(View(postModel));
        }