예제 #1
0
 /// <summary>
 /// Simulation constractor
 /// </summary>
 /// <param name="bullet">get bullet values</param>
 /// <param name="wind">get wind values</param>
 /// <param name="target">get target values</param>
 public Simulation(Bullet bullet, Wind wind, Target target)
 {
     this.bullet = bullet;
     this.wind   = wind;
     this.target = target;
 }
예제 #2
0
        /// <summary>
        /// Calculates bullet's velocity or location in a given direction and time.
        /// </summary>
        /// <param name="calc">Defines whether velocity or location needs to be calculated.</param>
        /// <param name="direction">the direction</param>
        /// <param name="wind">Wind can influence the bullet on the X axis.</param>
        /// <param name="t">Time t - measured in seconds.</param>
        /// <returns>bullet's velocity or location in a given direction and time</returns>
        public double CalcByDirection(Calculate calc, Direction direction, Wind wind,
                                      double t)
        {
            double k = this.ressistance; //ressistance
            double m = this.mass;        //mass
            double b = k / m;            //ressistance over mass
            double g = 0;                //Gravity
            double v = 0;                //Initial speed

            //Define initial speed abd gravity based on the given direction.
            switch (direction)
            {
            case Direction.X:
                v = this.velocityVector.XVelocity + wind.Velocity;
                break;

            case Direction.Y:
                v = this.velocityVector.YVelocity * -1;
                g = 9.8;
                break;

            case Direction.Z:
                v = this.velocityVector.ZVelocity;
                break;
            }

            double output = 0;

            //Chooses the needed formula according to the given parameters.
            switch (calc)
            {
            case Calculate.LOCATION:
                if (k != 0)     //if the ressistance not zero
                {
                    output = (-g + b * g * t + b * v + (g - b * v) * Math.Pow(Math.E, -b * t)) /
                             Math.Pow(b, 2);
                }
                else     // the ressistance is zero
                {
                    output = (g * Math.Pow(t, 2) + 2 * t * v) / 2;
                }
                break;

            case Calculate.VELOCITY:
                if (k != 0)     //if the ressistance not zero
                {
                    output = ((g / b) + (Math.Pow(Math.E, -b * t) * (v - (g / b))));
                }
                else     // the ressistance is zero
                {
                    output = g * t + v;
                }
                break;
            }

            if (direction == Direction.Y)
            {
                output *= -1;
            }

            return(output);
        }