Пример #1
0
        /// <summary>
        /// Creates a table that shows bullet's location and velocity as a function of time from
        /// t = 0 bullt's hit time.
        /// </summary>
        private void fillDataGrid()
        {
            double hitTime = this.simulation.getHitTime();

            DataTable table = new DataTable();

            //Add table colums.
            table.Columns.Add("t", typeof(double));
            table.Columns.Add("X", typeof(double));
            table.Columns.Add("Y", typeof(double));
            table.Columns.Add("Z", typeof(double));
            table.Columns.Add("Vt", typeof(double));

            //Fill table rows with the requiered data from t = 0 till bullt's hit time
            //and round all the numbers.
            for (double i = 0; i <= 1; i += 0.1)
            {
                double     t    = hitTime * i;
                Cordinates cord = this.simulation.getBulletCordinates(t);
                table.Rows.Add(Math.Round(t, 3), Math.Round(cord.X, 3), Math.Round(cord.Y, 3),
                               Math.Round(cord.Z, 3), Math.Round(this.simulation.getBulletVelocity(t), 3));
            }

            this.dataGridView.DataSource = table;
            this.dataGridView.AutoResizeColumns();
        }
Пример #2
0
        /// <summary>
        /// Paint a crosshair on targetPicture that shows the bullet's hit location relatively to
        /// the targe't center.
        /// Shows also information about distance from bullet's hit location to target's center,
        /// wind speed and direction.
        /// </summary>
        private void paintCrossHairAndShowResults()
        {
            //Get bullet hit cordinates.
            Cordinates hitCord            = this.simulation.getBulletCordinates(this.simulation.getHitTime());
            double     distanceFromCenter = Math.Sqrt(Math.Pow(hitCord.X, 2) + Math.Pow(hitCord.Y, 2));

            //Return if bullet missed target.
            if (distanceFromCenter > this.simulation._target.Radius)
            {
                showLabelResults(distanceFromCenter, true);
                //Redraw image.
                this.targetPicture.Refresh();
                return;
            }
            //Get ratio between picture size and target's radius.
            double xRatio = this.targetPicture.Width / (this.simulation._target.Radius * 2);
            double yRatio = this.targetPicture.Height / (this.simulation._target.Radius * 2);
            //Get hit location on the picture.
            Point hitPoint = new Point();

            hitPoint.X = (int)((this.targetPicture.Width / 2) + (hitCord.X * xRatio));
            hitPoint.Y = (int)((this.targetPicture.Height / 2) - (hitCord.Y * yRatio));

            using (Graphics crossHair = this.targetPicture.CreateGraphics())
            {
                //Redraw image.
                this.targetPicture.Refresh();
                //Paint crosshair:
                Pen p = new Pen(System.Drawing.Color.Red, 2);
                crossHair.DrawLine(p, hitPoint.X - 15, hitPoint.Y, hitPoint.X + 15, hitPoint.Y);
                crossHair.DrawLine(p, hitPoint.X, hitPoint.Y - 15, hitPoint.X, hitPoint.Y + 15);
            }

            //Show results.
            showLabelResults(distanceFromCenter, true);
        }