コード例 #1
0
    static void Main()
    {
        InitialVelocity  v = new InitialVelocity(40, UnitVelocity.KilometrePerHour);
        ElevationAngle   α = new ElevationAngle(41, UnitAngle.Degree);
        InitialHeight    h = new InitialHeight(169, UnitLength.Centimetre);
        GravAcceleration g = new GravAcceleration(GravAcceleration.GravAccelerations.Earth);


        ProjectileMotionResultsUnits units = new ProjectileMotionResultsUnits()
        {
            Length           = UnitLength.Metre,
            Time             = UnitTime.Second,
            Velocity         = UnitVelocity.KilometrePerHour,
            Angle            = UnitAngle.Degree,
            Area             = UnitArea.SquareMetre,
            GravAcceleration = UnitGravAcceleration.MetrePerSquareSecond
        };


        ProjectileMotion motion = new ProjectileMotion(
            new ProjectileMotionSettings(new ProjectileMotionQuantities(v, α, h, g, units))
        {
            RoundDigits         = 4,
            PathToFiles         = "C:\\Users\\oplan\\Documents\\c#\\ProjectileMotions",
            PointsForTrajectory = 160
        });

        motion.Saving.InfoToTxt();



        ProjectileMotionWithResistance motionWithResistance = new ProjectileMotionWithResistance(
            new ProjectileMotionWithResistanceSettings(
                new ProjectileMotionWithResistanceQuantities(
                    v, α, h, g,
                    new Mass(46, UnitMass.Gram),
                    new Density(Density.Densities.Air),
                    new FrontalArea(Math.Pow(new Length(12.9, UnitLength.Centimetre).GetBasicVal(), 2.0) * Math.PI, UnitArea.SquareMetre),
                    new DragCoefficient(DragCoefficient.DragCoefficients.Sphere),
                    units
                    )
                )
        {
            RoundDigits         = 4,
            PathToFiles         = "C:\\Users\\oplan\\Documents\\c#\\ProjectileMotions",
            PointsForTrajectory = 153
        });

        motionWithResistance.Saving.InfoToTxt();
    }
コード例 #2
0
 public ProjectileMotionWithResistanceQuantities(InitialVelocity v, ElevationAngle α, InitialHeight h, GravAcceleration g, Mass m, Density ρ, FrontalArea a, DragCoefficient c, ProjectileMotionResultsUnits units = null) : base(v, α, h, g, units)
 {
     M = m;
     Ρ = ρ;
     C = c;
     A = a;
 }
コード例 #3
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));
        }