Ejemplo n.º 1
0
        /// <summary>
        /// 13. Constructor for a projectile motion Quantities. Computes an elevation angle based on the duration and the length.
        /// </summary>
        /// <param name="v">An initial velocity.</param>
        /// <param name="l">The length.</param>
        /// <param name="dur">The duration.</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(InitialVelocity v, Length l, Duration dur, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            G = g;
            V = v;
            Α = new ElevationAngle(
                GetResultWithComputeExpection(
                    l.GetBasicVal() == 0 && dur.GetBasicVal() == 0 && V.GetBasicVal() > 0 ?
                    0
                        :
                    Math.Acos(l.GetBasicVal() / (V.GetBasicVal() * dur.GetBasicVal()))
                    ),
                UnitAngle.Basic
                ).Convert(Units.Angle);

            H = new InitialHeight(
                GetResultWithComputeExpection(
                    0.5 * G.GetBasicVal() * Math.Pow(dur.GetBasicVal(), 2.0) -
                    Math.Sin(Α.GetBasicVal()) * V.GetBasicVal() * dur.GetBasicVal()
                    ),
                UnitLength.Basic
                ).Convert(Units.Length);

            UsedAssignmentType = AssignmentsTypes.ElevationAngleByLengthAndDur;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 7. Constructor for a projectile motion Quantities. Computes an elevation angle based on the length.
        /// </summary>
        /// <param name="v">An initial velocity.</param>
        /// <param name="l">The length.</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(Length l, InitialVelocity v, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            V = v;
            H = h;
            G = g;
            Α = new ElevationAngle(
                GetResultWithComputeExpection(
                    l.GetBasicVal() == 0 && H.GetBasicVal() == 0 ?
                    double.NaN
                        :
                    EquationSolver.BisectionFindRoot(
                        a => V.GetBasicVal() * Math.Cos(a) * (
                            V.GetBasicVal() * Math.Sin(a) + Math.Sqrt(Math.Pow(V.GetBasicVal() *
                                                                               Math.Sin(a), 2) + 2.0 * G.GetBasicVal() * H.GetBasicVal())
                            ) / G.GetBasicVal() - l.GetBasicVal(),
                        0,
                        new ElevationAngle(ElevationAngle.ElevationAngleTypes.Right).Val,
                        1E-4
                        )
                    ),
                UnitAngle.Basic
                ).Convert(Units.Angle);

            UsedAssignmentType = AssignmentsTypes.ElevationAngleByLength;
        }
Ejemplo n.º 3
0
    public Vector2 MakeInitDecelerationTargetVector()
    {
        float angle     = Direction.AngleTo(InitialVelocity.Normalized());
        float magnitude = Mathf.Max(0, Mathf.Cos(angle) * InitialVelocity.Length());

        return(magnitude * InitialVelocity.Normalized());
    }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 1. Constructor for a projectile motion Quantities.
        /// </summary>
        /// <param name="v">An initial velocity.</param>
        /// <param name="α">An elevation angle.</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(InitialVelocity v, ElevationAngle α, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            V = v;
            Α = α;
            H = h;
            G = g;

            UsedAssignmentType = AssignmentsTypes.Basic;
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
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();
    }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 4. Constructor for a projectile motion Quantities. Computes an initial height based on the duration.
        /// </summary>
        /// <param name="α">An elevation angle.</param>
        /// <param name="dur">The duration.</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(Duration dur, ElevationAngle α, InitialVelocity v, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

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

            UsedAssignmentType = AssignmentsTypes.InitialHeightByDuration;
        }
Ejemplo n.º 10
0
        protected virtual void Emit(ParticleEmitter emitter, Particle particle)
        {
            Matrix transform = Matrix.CreateRotationZ(emitter.WorldRotation);

            // Generating spawn position.
            float emitAngle  = RandomHelper.Next(0, MathHelper.TwoPi);
            float emitRadius = EmitRadius.GetValue();

            Vector2 p = EmitPosition.GetValue() + new Polar2(emitRadius, emitAngle).ToVector2();

            // Generating initial velocity.
            float initialAngle    = EmitAngle.GetValue();
            float initialVelocity = InitialVelocity.GetValue();

            Vector2 v;

            if (InitialVelocityMode == InitialVelocityMode.AwayFromCenter && p != Vector2.Zero)
            {
                v = Vector2.Normalize(p) * initialVelocity;
            }
            else
            {
                v = new Polar2(initialVelocity, initialAngle).ToVector2();
            }

            particle.Position        = emitter.WorldPosition + Vector2.Transform(p, transform);
            particle.Rotation        = emitter.WorldRotation + InitialRotation.GetValue();
            particle.Velocity        = Vector2.Transform(v, transform);
            particle.AngularVelocity = InitialAngularVelocity.GetValue();
            particle.Duration        = Duration.GetValue();
            particle.Timer           = 0;
            particle.Scale           = InitialScale.GetValue();

            if (SpriteFrames != null)
            {
                particle.Data = RandomHelper.Next(0, SpriteFrames.Length);
            }

            if (ColorMode == ParticleColorMode.Random)
            {
                particle.Color = Colors[RandomHelper.Next(0, Colors.Length)].ToVector4();
            }
            else
            {
                particle.Color = Colors[0].ToVector4();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 3. Constructor for a projectile motion Quantities. Computes an initial velocity based on the duration.
        /// </summary>
        /// <param name="α">An elevation angle.</param>
        /// <param name="dur">The duration.</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(Duration dur, ElevationAngle α, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            Α = α;
            H = h;
            G = g;

            V = new InitialVelocity(
                GetResultWithComputeExpection(
                    dur.GetBasicVal() == 0 && H.GetBasicVal() == 0
                        ? 0
                        :
                    (Math.Pow(dur.GetBasicVal(), 2.0) * G.GetBasicVal() - 2 * H.GetBasicVal()) /
                    (2.0 * Math.Sin(Α.GetBasicVal()) * dur.GetBasicVal())
                    ),
                UnitVelocity.Basic).Convert(Units.Velocity);

            UsedAssignmentType = AssignmentsTypes.InitialVelocityByDuration;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 2. Constructor for a projectile motion Quantities. Computes an elevation angle based on the duration.
        /// </summary>
        /// <param name="v">An initial velocity.</param>
        /// <param name="dur">The duration.</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(Duration dur, InitialVelocity v, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

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

            UsedAssignmentType = AssignmentsTypes.ElevationAngleByDuration;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 11. Constructor for a projectile motion Quantities. Computes an elevation angle for motion with maximum range.
        /// </summary>
        /// <param name="v">An initial velocity.</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(InitialVelocity v, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            V = v;
            H = h;
            G = g;
            Α = new ElevationAngle(
                GetResultWithComputeExpection(
                    Math.Acos(
                        Math.Sqrt(
                            (2.0 * G.GetBasicVal() * H.GetBasicVal() + Math.Pow(V.GetBasicVal(), 2.0)) /
                            (2.0 * G.GetBasicVal() * H.GetBasicVal() + 2.0 * Math.Pow(V.GetBasicVal(), 2.0))
                            )
                        )
                    ),
                UnitAngle.Basic
                ).Convert(Units.Angle);

            UsedAssignmentType = AssignmentsTypes.ElevationAngleGetMaxRange;
        }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 5. Constructor for a projectile motion Quantities. Computes an initial height based on the length.
        /// </summary>
        /// <param name="α">An elevation angle.</param>
        /// <param name="l">The length.</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(Length l, ElevationAngle α, InitialVelocity v, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

            V = v;
            Α = α;
            G = g;

            H = new InitialHeight(
                GetResultWithComputeExpection(
                    Α.IsRight() ?
                    double.NaN
                        : (
                        Math.Pow(l.GetBasicVal(), 2.0) * G.GetBasicVal() /
                        Math.Pow(Math.Cos(Α.GetBasicVal()), 2.0) -
                        2.0 * l.GetBasicVal() * Math.Pow(V.GetBasicVal(), 2.0) * Math.Tan(Α.GetBasicVal())
                        ) / (2.0 * Math.Pow(V.GetBasicVal(), 2.0))
                    ),
                UnitLength.Basic
                ).Convert(Units.Length);

            UsedAssignmentType = AssignmentsTypes.InitialHeightByLength;
        }
Ejemplo n.º 16
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;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 6. Constructor for a projectile motion Quantities. Computes an initial velocity based on the length.
        /// </summary>
        /// <param name="α">An elevation angle.</param>
        /// <param name="l">The length.</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(Length l, ElevationAngle α, InitialHeight h, GravAcceleration g, ProjectileMotionResultsUnits units = null)
        {
            Units = units ?? new ProjectileMotionResultsUnits();

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

            UsedAssignmentType = AssignmentsTypes.InitialVelocityByLength;
        }
Ejemplo n.º 18
0
        public void Write(DocumentWriter dw)
        {
            dw.WriteLine($"{ShrapnelType}", "Shrapnel type");
            InitialVelocity.Write(dw);

            if (ShrapnelType != SmashDataShrapnelType.shards)
            {
                dw.WriteLine($"{InitialPositionType}", "How the shrapnel bits are initially placed in the World");

                if (InitialPositionType == SmashDataInitialPositionType.sphereclumped)
                {
                    dw.WriteLine($"{ClumpingRadius}");
                    dw.WriteLine($"{ClumpingCentre}");
                }
            }

            if (ShrapnelType != SmashDataShrapnelType.noncars)
            {
                dw.WriteLine($"{Time.X},{Time.Y}", "Min time, Max time");
            }

            if (ShrapnelType == SmashDataShrapnelType.shards)
            {
                dw.WriteLine($"{CutLength}", "Min cut length");
                dw.WriteLine($"{Flags}", "flags");
                dw.WriteLine($"{MaterialName}", "name of shrapnel material");
            }
            else if (ShrapnelType == SmashDataShrapnelType.ghostparts)
            {
                dw.WriteLine($"{MinCount},{MaxCount}");
                dw.WriteLine($"{GhostPartActors.Count}");
                foreach (string ghostPartActor in GhostPartActors)
                {
                    dw.WriteLine($"{ghostPartActor}");
                }
            }
            else if (ShrapnelType == SmashDataShrapnelType.noncars)
            {
                dw.WriteLine($"{MinCount},{MaxCount}", "Min number,Max number (-1,-1 means use exactly one of each type of bit)");
                dw.WriteLine($"{ChanceOfFire}", "% Chance of fire/smoke");

                if (ChanceOfFire > 0)
                {
                    dw.WriteLine($"{NumFires}", "Number of fires/smoke column");
                    dw.WriteLine($"{string.Join(",", SmokeLevel)}", "Min,Max smokiness (0 = fire, 1 = black smoke, 2 = grey smoke, 3 = white smoke)");
                }

                dw.WriteLine($"{Actor}", "Name of actor file");
                dw.WriteLine($"{Actors.Count}", "Number of separate actors in file");
                foreach (SmashDataShrapnelActor actor in Actors)
                {
                    dw.WriteLine($"{actor.Name}", "Actor name");
                    dw.WriteLine($"{actor.FileName}", "Non-car text file to use for the above actor");
                }
            }
            else
            {
                dw.WriteLine($"{MinCount}");
                dw.WriteLine($"{MaxCount}");
                dw.WriteLine($"{Actor}");
            }
        }
Ejemplo n.º 19
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));
        }