コード例 #1
0
        /// <summary>
        /// Read calibration settings inputs, loads them into a new Trajectory Calculator and calculates the new offsets.
        /// </summary>
        private void btnCalibrate_Click(object sender, EventArgs e)
        {
            // Reads data from the inputs
            int padX = Util.readInt(txtInPadLocX);
            int padY = Util.readInt(txtInPadLocY);
            int calX = Util.readInt(txtInCalLocX);
            int calY = Util.readInt(txtInCalLocY);

            // Reads bearing, elevation and power settings
            float calBearing   = Properties.Settings.Default.selectedBearing;
            float calElevation = Properties.Settings.Default.selectedElevation;
            int   calPower     = Properties.Settings.Default.selectedPower;

            // Calculates the offsets based on the data
            trajcalc = TrajectoryCalculator.createCalculator(padX, padY, calX, calY, calPower, calBearing, calElevation, TrajectoryCalculator.CalculationOptionsList[Properties.Settings.Default.selectedServer].CalcType);
            trajcalc.calcOffsets();

            // Shows the result to the user
            lblCalBe.Text  = trajcalc.bearingOffset.ToString();
            lblCalPow.Text = trajcalc.powerOffset.ToString();
            setStatus("Calibrated");

            // Enables the compute box, initially disabled due the lack of a valid TrajectoryCalculator object.
            grpCompute.Enabled = true;

            uses         = 0;
            lblUses.Text = uses.ToString();
        }
コード例 #2
0
        public void WhenCombineTrajectories_TreeCountIsCorrect()
        {
            var calculator = new TrajectoryCalculator();
            var combiner   = new TrajectoryCombiner(calculator);

            combiner
            .CombineTrajectories(testGrid, (1, 1), (3, 1), (5, 1), (7, 1), (1, 2))
            .Should()
            .Be(336);
        }
コード例 #3
0
        public void Simple_collision_test()
        {
            var result = TrajectoryCalculator.CalculateCollisions(new[] {
                "..##.......",
                "#...#...#..",
                ".#....#..#."
            }, 3, 1);

            Assert.Equal(1, result);
        }
コード例 #4
0
        private void Telescience2_Load(object sender, EventArgs e)
        {
            // Initialize stuff
            this.History  = new CoordinateHistory(this.GetCalculator);
            this.trajcalc = TrajectoryCalculator.createCalculator(0, 0, 0, 0, 0, 0, 0, TrajectoryCalculator.CalculationOptionsList[Properties.Settings.Default.selectedServer].CalcType);

            // Topmost window setting
            chkOnTop.Checked = Properties.Settings.Default.checkOnTop;
            this.TopMost     = chkOnTop.Checked;
        }
コード例 #5
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));
        }
コード例 #6
0
        public void CountTreesOnPath_1(string filename, int expected)
        {
            // ARRANGE
            var sut = new TrajectoryCalculator($"TobogganTrajectory/{filename}");

            // ACT
            var numberOfTrees = sut.TraverseMap(new List <(int verticalStep, int horizontalStep)> {
                (verticalStep: 1, horizontalStep: 3)
            }, x => x == '#');

            // ASSERT
            numberOfTrees.Should().Be(expected);
        }
コード例 #7
0
        public override void RunExercise2()
        {
            var numberOfTrees = new TrajectoryCalculator("Input/day3.txt")
                                .TraverseMap(new List <(int verticalStep, int horizontalStep)>
            {
                (verticalStep: 1, horizontalStep: 1),
                (verticalStep: 1, horizontalStep: 3),
                (verticalStep: 1, horizontalStep: 5),
                (verticalStep: 1, horizontalStep: 7),
                (verticalStep: 2, horizontalStep: 1)
            }, x => x == '#');

            LogMessage($"number of trees: Valid amount: {numberOfTrees}");
        }
コード例 #8
0
        public void Convert_string_to_array_test()
        {
            var result = TrajectoryCalculator.ConvertStringArrayToJaggedCharArray(new[] {
                "..##.......",
                "#...#...#..",
                ".#....#..#."
            });

            var expected = new char[][] {
                new [] { '.', '.', '#', '#', '.', '.', '.', '.', '.', '.', '.' },
                new [] { '#', '.', '.', '.', '#', '.', '.', '.', '#', '.', '.' },
                new [] { '.', '#', '.', '.', '.', '.', '#', '.', '.', '#', '.' }
            };

            Assert.Equal(expected, result);
        }
コード例 #9
0
        private void btnRecalculate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Recalculate all coordinates in\nthe list with the current offsets?", "Recalculate", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                TrajectoryCalculator trajcalc = GetCalculator();
                foreach (var Coordinates in coordinatesItemBindingSource.Cast <CoordinatesItem>())
                {
                    trajcalc.calcAll(Coordinates.X, Coordinates.Y);
                    Coordinates.Bearing   = trajcalc.resBearing;
                    Coordinates.Elevation = trajcalc.resElevation;
                    Coordinates.Power     = trajcalc.resPower;
                }

                dgvHistory.DataSource = null;
                dgvHistory.DataSource = coordinatesItemBindingSource;
            }
        }
コード例 #10
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}");
                }
            }
        }
コード例 #11
0
        public void CustomTable()
        {
            TableLoader  template = TableLoader.FromResource("g1_nowind");
            const double velocityAccuracyInPercent = 0.005, dropAccuracyInMOA = 0.2, windageAccuracyInMOA = 0.2;

            var table = DragTable.Get(template.Ammunition.BallisticCoefficient.Table);

            template.Ammunition.BallisticCoefficient = new BallisticCoefficient(template.Ammunition.BallisticCoefficient.Value, DragTableId.GC);


            var cal = new TrajectoryCalculator();

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

            var trajectory = cal.Calculate(template.Ammunition, template.Rifle, template.Atmosphere, shot, null, 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}");

                var dropAccuracyInInch = Measurement <AngularUnit> .Convert(dropAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100;

                var windageAccuracyInInch = Measurement <AngularUnit> .Convert(windageAccuracyInMOA, 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}");
                point.Windage.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Windage.In(DistanceUnit.Inch), windageAccuracyInInch, $"@{point.Distance:N0}");
            }
        }
コード例 #12
0
        public void CustomTableNotSpecifiedException()
        {
            TableLoader template = TableLoader.FromResource("g1_nowind");

            template.Ammunition.BallisticCoefficient = new BallisticCoefficient(template.Ammunition.BallisticCoefficient.Value, DragTableId.GC);

            var cal = new TrajectoryCalculator();

            ((Action)(() => cal.SightAngle(template.Ammunition, template.Rifle, template.Atmosphere)))
            .Should().Throw <ArgumentNullException>();

            ShotParameters shot = new ShotParameters()
            {
                Step            = new Measurement <DistanceUnit>(50, DistanceUnit.Yard),
                MaximumDistance = new Measurement <DistanceUnit>(1000, DistanceUnit.Yard),
                SightAngle      = new Measurement <AngularUnit>(10, AngularUnit.MOA),
                ShotAngle       = template.ShotParameters?.ShotAngle,
                CantAngle       = template.ShotParameters?.CantAngle,
            };

            ((Action)(() => cal.Calculate(template.Ammunition, template.Rifle, template.Atmosphere, shot, null)))
            .Should().Throw <ArgumentNullException>();
        }
コード例 #13
0
        public void TrajectoryTest(string name, double velocityAccuracyInPercent, double dropAccuracyInMOA, double windageAccuracyInMOA)
        {
            TableLoader template = TableLoader.FromResource(name);

            var cal = new TrajectoryCalculator();

            ShotParameters shot = new ShotParameters()
            {
                Step            = new Measurement <DistanceUnit>(50, DistanceUnit.Yard),
                MaximumDistance = new Measurement <DistanceUnit>(1000, DistanceUnit.Yard),
                SightAngle      = cal.SightAngle(template.Ammunition, template.Rifle, template.Atmosphere),
                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);

            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}");

                var dropAccuracyInInch = Measurement <AngularUnit> .Convert(dropAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100;

                var windageAccuracyInInch = Measurement <AngularUnit> .Convert(windageAccuracyInMOA, 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}");
                point.Windage.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Windage.In(DistanceUnit.Inch), windageAccuracyInInch, $"@{point.Distance:N0}");
            }
        }
コード例 #14
0
        static void Main(string[] args)
        {
            string[] input = File.ReadAllLines("./data.txt");

            var totalCollisions = TrajectoryCalculator.CalculateCollisionsForMultipleRoutes(input,
                                                                                            new[] {
コード例 #15
0
        internal static TrajectoryPoint[] M193(bool hasWind, Measurement <DistanceUnit> step)
        {
            //define M193 projectile out of 20 inch barrel
            var ammo = new Ammunition(
                weight: new Measurement <WeightUnit>(55, WeightUnit.Grain),
                ballisticCoefficient: new BallisticCoefficient(0.202, DragTableId.G1),
                muzzleVelocity: new Measurement <VelocityUnit>(3240, VelocityUnit.FeetPerSecond),
                bulletDiameter: new Measurement <DistanceUnit>(0.224, DistanceUnit.Inch),
                bulletLength: new Measurement <DistanceUnit>(0.76, 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>(100, 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>(1000, DistanceUnit.Yard),
                Step            = step,
                //calculate sight angle for the specified zero distance
                SightAngle = calc.SightAngle(ammo, rifle, atmosphere)
            };

            //define winds

            Wind[] wind = hasWind ? new Wind[2]
            {
                new Wind()
                {
                    Direction    = new Measurement <AngularUnit>(45, AngularUnit.Degree),
                    Velocity     = new Measurement <VelocityUnit>(10, VelocityUnit.MilesPerHour),
                    MaximumRange = new Measurement <DistanceUnit>(500, DistanceUnit.Yard),
                },
                new Wind()
                {
                    Direction = new Measurement <AngularUnit>(15, AngularUnit.Degree),
                    Velocity  = new Measurement <VelocityUnit>(5, VelocityUnit.MilesPerHour),
                }
            } : null;

            //calculate trajectory
            return(calc.Calculate(ammo, rifle, atmosphere, shot, wind));
        }
コード例 #16
0
        public void Longer_collision_tests(int right, int down, int expected)
        {
            var result = TrajectoryCalculator.CalculateCollisions(this.TestData, right, down);

            Assert.Equal(expected, result);
        }
コード例 #17
0
 public void Multiplication_test()
 {
     // experience has taught me that this is necessary
     var result = TrajectoryCalculator.CalculateCollisionsForMultipleRoutes(this.TestData,
                                                                            new[] {
コード例 #18
0
        public void WhenCalculateTrajectory_TreeCount(int accross, int down, int expected)
        {
            var calculator = new TrajectoryCalculator();

            calculator.CountTrees(testGrid, (accross, down)).Should().Be(expected);
        }
コード例 #19
0
ファイル: Processor.cs プロジェクト: NMO13/SolidTurn
 internal void Reset()
 {
     m_TrajCalculator = new TrajectoryCalculator(doc);
     m_TSVCalculator = new TSVCalculator(doc);
     m_ActiveSentence = null;
     m_SentencePointer = 0;
     m_GoBufferProcessing = false;
 }
コード例 #20
0
 internal void Reset()
 {
     m_TrajCalculator = new TrajectoryCalculator(doc);
 }
コード例 #21
0
        public void BDC_LongRange()
        {
            var canvas     = CreateMockCanvas();
            var reticle    = CreateReticle();
            var trajectory = TableLoader.FromResource("g1_nowind");

            //we need detailed trajectory to calculate BDC
            var calc = new TrajectoryCalculator();

            trajectory.ShotParameters.SightAngle      = calc.SightAngle(trajectory.Ammunition, trajectory.Rifle, trajectory.Atmosphere);
            trajectory.ShotParameters.Step            = DistanceUnit.Yard.New(10);
            trajectory.ShotParameters.MaximumDistance = DistanceUnit.Yard.New(500);
            var trajectory1 = calc.Calculate(trajectory.Ammunition, trajectory.Rifle, trajectory.Atmosphere, trajectory.ShotParameters, new[] { trajectory.Wind });

            reticle.BulletDropCompensator.Add(new ReticleBulletDropCompensatorPoint()
            {
                Position   = new ReticlePosition(AngularUnit.Mil.New(0), AngularUnit.Mil.New(-0.5)),
                TextHeight = AngularUnit.Mil.New(0.5),
                TextOffset = AngularUnit.Mil.New(0),
            });

            reticle.BulletDropCompensator.Add(new ReticleBulletDropCompensatorPoint()
            {
                Position   = new ReticlePosition(AngularUnit.Mil.New(0), AngularUnit.Mil.New(-1)),
                TextHeight = AngularUnit.Mil.New(0.5),
                TextOffset = AngularUnit.Mil.New(1),
            });

            reticle.BulletDropCompensator.Add(new ReticleBulletDropCompensatorPoint()
            {
                Position   = new ReticlePosition(AngularUnit.Mil.New(0), AngularUnit.Mil.New(-2)),
                TextHeight = AngularUnit.Mil.New(0.5),
                TextOffset = AngularUnit.Mil.New(-1),
            });

            canvas.Setup(canvas => canvas.Text(
                             It.Is <float>(f => Approximately(f, 5000)),                   //x == center
                             It.Is <float>(f => Approximately(f, 5750)),                   //x - 0.5mil(dot) + 0.5mil(text height) / 2
                             It.Is <float>(f => Approximately(f, 500)),
                             It.Is <string>(s => Approximately(float.Parse(s), 195, 10f)), //~195 yards on the trajectory of test
                             It.Is <string>(s => s == "black"))).Verifiable();

            canvas.Setup(canvas => canvas.Text(
                             It.Is <float>(f => Approximately(f, 6000)),                   //x == center + 1 mil
                             It.Is <float>(f => Approximately(f, 6250)),                   //x - 1mil(dot) + 0.5mil(text height) / 2
                             It.Is <float>(f => Approximately(f, 500)),
                             It.Is <string>(s => Approximately(float.Parse(s), 257, 10f)), //~257 yards on the trajectory of test
                             It.Is <string>(s => s == "black"))).Verifiable();

            canvas.Setup(canvas => canvas.Text(
                             It.Is <float>(f => Approximately(f, 4000)),                   //x == center - 1 mil
                             It.Is <float>(f => Approximately(f, 7250)),                   //x - 2mil(dot) + 0.5mil(text height) / 2
                             It.Is <float>(f => Approximately(f, 500)),
                             It.Is <string>(s => Approximately(float.Parse(s), 356, 10f)), //~356 yards on the trajectory of test
                             It.Is <string>(s => s == "black"))).Verifiable();

            ReticleDrawController controller = new ReticleDrawController(reticle, canvas.Object);

            controller.DrawBulletDropCompensator(trajectory1, trajectory.Rifle.Zero.Distance, false, DistanceUnit.Yard, "black");

            canvas.Verify();
        }