コード例 #1
0
        public void TestTable(DragTableId id)
        {
            DragTable table = DragTable.Get(id);

            for (int i = 0; i < table.Count; i++)
            {
                var dataPoint = table[i];
                ((Action)(() => TestDataPoint(dataPoint, table))).Should().NotThrow();
            }
        }
コード例 #2
0
        public void TestTable(DragTableId id)
        {
            DragTable table = DragTable.Get(id);

            for (int i = 0; i < table.Count; i++)
            {
                var dataPoint = table[i];
                TestDataPoint(dataPoint, table);
            }
        }
コード例 #3
0
        private static TrajectoryPoint[] Calculate(double bc, DragTableId id)
        {
            var dragTable = new MyDrag();

            var ammo = new Ammunition(
                weight: new Measurement <WeightUnit>(168, WeightUnit.Grain),
                ballisticCoefficient: new BallisticCoefficient(bc, id),
                muzzleVelocity: new Measurement <VelocityUnit>(555, VelocityUnit.MetersPerSecond),
                bulletDiameter: new Measurement <DistanceUnit>(0.224, DistanceUnit.Inch),
                bulletLength: new Measurement <DistanceUnit>(0.9, DistanceUnit.Inch));

            //define ACOG scope
            var sight = new Sight(
                sightHeight: new Measurement <DistanceUnit>(3.5, DistanceUnit.Inch),
                verticalClick: new Measurement <AngularUnit>(1.0 / 3.0, AngularUnit.InchesPer100Yards),
                horizontalClick: new Measurement <AngularUnit>(1.0 / 3.0, AngularUnit.InchesPer100Yards)
                );

            //M16 rifling
            var rifling = new Rifling(
                riflingStep: new Measurement <DistanceUnit>(12, DistanceUnit.Inch),
                direction: TwistDirection.Right);

            //standard 100 yard ACOG zeroing
            var zero = new ZeroingParameters(
                distance: new Measurement <DistanceUnit>(50, DistanceUnit.Yard),
                ammunition: null,
                atmosphere: null
                );

            //define rifle by sight, zeroing and rifling parameters
            var rifle = new Rifle(sight: sight, zero: zero, rifling: rifling);

            //define atmosphere
            var atmosphere = new Atmosphere(
                altitude: new Measurement <DistanceUnit>(0, DistanceUnit.Foot),
                pressure: new Measurement <PressureUnit>(29.92, PressureUnit.InchesOfMercury),
                pressureAtSeaLevel: false,
                temperature: new Measurement <TemperatureUnit>(59, TemperatureUnit.Fahrenheit),
                humidity: 0.78);

            var calc = new TrajectoryCalculator();

            //shot parameters
            var shot = new ShotParameters()
            {
                MaximumDistance = new Measurement <DistanceUnit>(2000, DistanceUnit.Meter),
                Step            = new Measurement <DistanceUnit>(100, DistanceUnit.Meter),
                //calculate sight angle for the specified zero distance
                SightAngle = calc.SightAngle(ammo, rifle, atmosphere, id == DragTableId.GC ? dragTable : null)
            };

            //calculate trajectory
            return(calc.Calculate(ammo, rifle, atmosphere, shot, null, id == DragTableId.GC ? dragTable : null));
        }
コード例 #4
0
        public BallisticCoefficient(string text)
        {
            Value = 1;
            Table = DragTableId.G1;

            if (TryParse(text, CultureInfo.InvariantCulture, out double value, out DragTableId table))
            {
                Value = value;
                Table = table;
            }
        }
コード例 #5
0
        /// <summary>
        /// Returns the drag table by its identifier
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DragTable Get(DragTableId id)
        {
            return(id switch
            {
#pragma warning disable S1121 // Assignments should not be made from within sub-expressions
                DragTableId.G1 => gG1 ??= new G1DragTable(),
                DragTableId.G2 => gG2 ??= new G2DragTable(),
                DragTableId.G5 => gG5 ??= new G5DragTable(),
                DragTableId.G6 => gG6 ??= new G6DragTable(),
                DragTableId.G7 => gG7 ??= new G7DragTable(),
                DragTableId.G8 => gG8 ??= new G8DragTable(),
                DragTableId.GS => gGS ??= new GSDragTable(),
#pragma warning restore S1121 // Assignments should not be made from within sub-expressions
                _ => throw new ArgumentOutOfRangeException(nameof(id)),
            });
コード例 #6
0
        public void BallisticCoefficient(int accuracy, double value, DragTableId table, string textValue)
        {
            using TestForm tf = new TestForm();
            var control = tf.AddControl <MeasurementControl.MeasurementControl>(13, 13, 300, 28);

            control.MeasurementType = MeasurementType.BallisticCoefficient;
            control.DecimalPoints   = accuracy;

            control.Value = new BallisticCoefficient(value, table);
            control.TextValue.Should().Be(textValue + table.ToString());

            control.Value = new BallisticCoefficient(1, DragTableId.G1);
            control.TextValue.Should().Be("1G1");

            control.TextValue = textValue + table.ToString();
            control.ValueAs <BallisticCoefficient>().Should().Be(new BallisticCoefficient(double.Parse(textValue), table));
        }
コード例 #7
0
        public void ToStringAndParse(double value, DragTableId tableId, string format, string expected, double expectedAccuracy)
        {
            var bc1 = new BallisticCoefficient(value, tableId);

            if (format != null)
            {
                bc1.ToString(format, CultureInfo.InvariantCulture).Should().Be(expected);
            }
            else
            {
                bc1.ToString(CultureInfo.InvariantCulture).Should().Be(expected);
            }

            BallisticCoefficient.TryParse(expected, out BallisticCoefficient bc2).Should().BeTrue();
            bc2.Value.Should().BeApproximately(value, expectedAccuracy);
            bc2.Table.Should().Be(tableId);
        }
コード例 #8
0
        public void Zero1(double ballisticCoefficient, DragTableId ballisticTable, double muzzleVelocity, VelocityUnit velocityUnit, double zeroDistance, DistanceUnit distanceUnit, double sightAngle, AngularUnit sightAngleUnit, double sightAngleAccuracy)
        {
            Ammunition ammunition = new Ammunition(
                weight: new Measurement <WeightUnit>(69, WeightUnit.Grain),
                muzzleVelocity: new Measurement <VelocityUnit>(muzzleVelocity, velocityUnit),
                ballisticCoefficient: new BallisticCoefficient(ballisticCoefficient, ballisticTable)
                );

            Rifle rifle = new Rifle(
                sight: new Sight(sightHeight: new Measurement <DistanceUnit>(3.2, DistanceUnit.Inch), Measurement <AngularUnit> .ZERO, Measurement <AngularUnit> .ZERO),
                zero: new ZeroingParameters(distance: new Measurement <DistanceUnit>(zeroDistance, distanceUnit), ammunition: null, atmosphere: null));

            Atmosphere atmosphere = new Atmosphere();       //default atmosphere

            var sightAngle1 = (new TrajectoryCalculator()).SightAngle(ammunition, rifle, atmosphere);

            sightAngle1.In(sightAngleUnit).Should().BeApproximately(sightAngle, sightAngleAccuracy);
        }
コード例 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="coefficient"></param>
 /// <param name="table"></param>
 /// <param name="valueType"></param>
 public BallisticCoefficient(double coefficient, DragTableId table, BallisticCoefficientValueType valueType)
 {
     ValueType = valueType;
     Value     = coefficient;
     Table     = table;
 }
コード例 #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="value"></param>
 /// <param name="table"></param>
 public BallisticCoefficient(double value, DragTableId table) : this(value, table, BallisticCoefficientValueType.Coefficient)
 {
 }
コード例 #11
0
        private static bool TryParse(string text, CultureInfo cultureInfo, out double value, out DragTableId table, out BallisticCoefficientValueType valueType)
        {
            value     = 0;
            table     = DragTableId.G1;
            valueType = BallisticCoefficientValueType.Coefficient;

            if (text.Length < 3)
            {
                return(false);
            }

            if (text[0] == 'F')
            {
                text = text.Substring(1);
                if (text.Length < 3)
                {
                    return(false);
                }

                valueType = BallisticCoefficientValueType.FormFactor;
            }

            string tableName = text.Substring(text.Length - 2);

            if (!Enum.TryParse <DragTableId>(tableName, out table))
            {
                return(false);
            }
            string v = text.Substring(0, text.Length - 2);

            return(double.TryParse(v, NumberStyles.Float, cultureInfo, out value));
        }
コード例 #12
0
        private static bool TryParse(string text, CultureInfo cultureInfo, out double value, out DragTableId table)
        {
            value = 0;
            table = DragTableId.G1;
            if (text.Length < 3)
            {
                return(false);
            }
            string tableName = text.Substring(text.Length - 2);

            if (!Enum.TryParse <DragTableId>(tableName, out table))
            {
                return(false);
            }
            string v = text.Substring(0, text.Length - 2);

            return(double.TryParse(v, NumberStyles.Float, cultureInfo, out value));
        }
コード例 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="coefficient"></param>
 /// <param name="table"></param>
 public BallisticCoefficient(double coefficient, DragTableId table)
 {
     Value = coefficient;
     Table = table;
 }