Example #1
0
        public void Drg()
        {
            using var stream = typeof(DragTableTest).Assembly.GetManifestResourceStream($"BallisticCalculator.Test.resources.drg.txt");
            var table = DrgDragTable.Open(stream);

            table.Ammunition.Name.Should().Be(".30 Lapua AP492 10.7g");
            table.Ammunition.Ammunition.Weight.In(WeightUnit.Gram).Should().BeApproximately(10.7, 1e-7);
            table.Ammunition.Ammunition.BulletDiameter.Should()
            .NotBeNull()
            .And.Subject.As <Measurement <DistanceUnit>?>()
            .Value.In(DistanceUnit.Millimeter).Should().BeApproximately(7.83, 1e-7);

            table.Ammunition.Ammunition
            .BallisticCoefficient.Value.Should().Be(1);
            table.Ammunition.Ammunition
            .BallisticCoefficient.Table.Should().Be(DragTableId.GC);
            table.Ammunition.Ammunition
            .BallisticCoefficient.ValueType.Should().Be(BallisticCoefficientValueType.FormFactor);
            table.Ammunition.Ammunition
            .GetBallisticCoefficient().Should().BeApproximately(0.2482, 5e-5);

            table.Count.Should().Be(32);
            table[0].DragCoefficient.Should().Be(0.180);
            table[0].Mach.Should().Be(0);

            table[3].DragCoefficient.Should().Be(0.152);
            table[3].Mach.Should().Be(0.5);

            table[31].DragCoefficient.Should().Be(0.210);
            table[31].Mach.Should().Be(5);
        }
Example #2
0
        public void Custom2()
        {
            var template = TableLoader.FromResource("custom2");

            using var stream = typeof(TrajectoryCalculatorTest).Assembly.GetManifestResourceStream($"BallisticCalculator.Test.resources.drg2.txt");
            var table = DrgDragTable.Open(stream);

            const double velocityAccuracyInPercent = 0.015, dropAccuracyInMOA = 0.25;

            var cal = new TrajectoryCalculator();

            ShotParameters shot = new ShotParameters()
            {
                Step            = new Measurement <DistanceUnit>(100, DistanceUnit.Meter),
                MaximumDistance = new Measurement <DistanceUnit>(1500, DistanceUnit.Meter),
                SightAngle      = cal.SightAngle(template.Ammunition, template.Rifle, template.Atmosphere, table),
                ShotAngle       = template.ShotParameters?.ShotAngle,
                CantAngle       = template.ShotParameters?.CantAngle,
            };

            var winds = template.Wind == null ? null : new Wind[] { template.Wind };

            var trajectory = cal.Calculate(template.Ammunition, template.Rifle, template.Atmosphere, shot, winds, table);

            trajectory.Length.Should().Be(template.Trajectory.Count);

            for (int i = 0; i < trajectory.Length; i++)
            {
                var point         = trajectory[i];
                var templatePoint = template.Trajectory[i];

                point.Distance.In(templatePoint.Distance.Unit).Should().BeApproximately(templatePoint.Distance.Value, templatePoint.Distance.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}");
                point.Velocity.In(templatePoint.Velocity.Unit).Should().BeApproximately(templatePoint.Velocity.Value, templatePoint.Velocity.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}");
                if (i > 0)
                {
                    var dropAccuracyInInch = Measurement <AngularUnit> .Convert(dropAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100;

                    point.Drop.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Drop.In(DistanceUnit.Inch), dropAccuracyInInch, $"@{point.Distance:N0}");
                }
            }
        }