Пример #1
0
 public void Reset(
     double min1, double step1, uint n1,
     double min2, double step2, uint n2,
     Func <double, double, double> action = null)
 {
     x_min_  = min1;
     x_max_  = min1 + step1 * (n1 - 1);
     x_step_ = step1;
     n_      = n1;
     values_ = new LinearTable[n1];
     if (action == null)
     {
         for (uint i = 0; i < n1; i++)
         {
             values_[i] = new LinearTable(min2, step2, n2);
         }
     }
     else
     {
         for (uint i = 0; i < n1; i++)
         {
             double x = x_min_ + i * x_step_;
             values_[i] = new LinearTable(
                 min2, step2, n2,
                 (double x2) => action(x, x2));
         }
     }
 }
Пример #2
0
        public void Reset(
            VesselData vessel_data,
            double altitude_step,
            double velocity_step, double velocity_max,
            double aoa,
            bool init_simple = true)
        {
            double aoa_cos = Math.Cos(aoa);
            double aoa_sin = Math.Sin(aoa);

            double altitude_max;

            if (body_.HasAtmosphere)
            {
                altitude_max = body_.AtmosphereDepth;
            }
            else
            {
                altitude_max  = 1d;
                altitude_step = 1d;
            }

            uint altitude_n = (uint)Math.Ceiling(altitude_max / altitude_step);
            uint velocity_n = (uint)Math.Ceiling(velocity_max / velocity_step);

            var    flight = vessel_.Flight(body_.ReferenceFrame);
            double radius = body_.EquatorialRadius;

            /*var stream_pos = conn_.AddStream(() => vessel_.Position(body_.ReferenceFrame));
             * var stream_backward = conn_.AddStream(() => sc_.TransformDirection(
             *  new Tuple<double, double, double>(0, -1, 0),
             *  vessel_.ReferenceFrame, body_.ReferenceFrame));
             * var stream_right = conn_.AddStream(() => sc_.TransformDirection(
             *  new Tuple<double, double, double>(1, 0, 0),
             *  vessel_.ReferenceFrame, body_.ReferenceFrame));*/

            atm_ = new LinearTable(
                0d, altitude_step, altitude_n,
                (double altitude) =>
            {
                double atm = body_.PressureAt(altitude) / Constants.Common.STANDARD_ATMOSPHERIC_PRESSURE;
                return(atm);
            },
                init_simple);

            available_thrust_ = new LinearTable(
                0d, altitude_step, altitude_n,
                (double altitude) =>
            {
                double atm = atm_[altitude];
                double thr = vessel_.AvailableThrustAt(atm);
                return(thr);
            },
                init_simple);

            density_ = new LinearTable(
                0d, altitude_step, altitude_n,
                (double altitude) =>
            {
                double density = body_.DensityAt(altitude);
                return(density);
            },
                init_simple);

            sim_drift_ = new BiLinearTable(
                0d, altitude_step, altitude_n,
                0d, velocity_step, velocity_n,
                (double altitude, double velocity) =>
            {
                /*Vector3d pos_now = new Vector3d(stream_pos.Get());
                 * Vector3d backward = new Vector3d(stream_backward.Get());*/
                Vector3d pos          = vessel_data.Vessel.Position.Norm() * (radius + altitude);
                Vector3d vel_backward = -velocity * vessel_data.Vessel.Forward;
                var sim = flight.SimulateAerodynamicForceAt(body_, pos.ToTuple(), vel_backward.ToTuple());
                return(new Vector3d(sim).Length());
            });

            sim_lift_ = new BiLinearTable(
                0d, altitude_step, altitude_n,
                0d, velocity_step, velocity_n,
                (double altitude, double velocity) =>
            {
                /*Vector3d pos_now = new Vector3d(stream_pos.Get());
                *  Vector3d backward = new Vector3d(stream_backward.Get());
                *  Vector3d right = new Vector3d(stream_right.Get());*/
                Vector3d pos          = vessel_data.Vessel.Position.Norm() * (radius + altitude);
                Vector3d vel_backward = -velocity * vessel_data.Vessel.Forward;
                Vector3d vel_tilt     = velocity * (vessel_data.Vessel.Right * aoa_sin - vessel_data.Vessel.Forward * aoa_cos);
                var sim = flight.SimulateAerodynamicForceAt(body_, pos.ToTuple(), vel_tilt.ToTuple());
                return(-(new Vector3d(sim) * vessel_data.Vessel.Right));
            });
        }