Exemple #1
0
        public ApoapsisPeriapsisPrediction predictOrbit()
        {
            VesselController.setReferenceFrameType(VesselController.ReferenceFrameType.ClosestBodyCenter);
            VesselController.updateBodyPosition();
            var   currentPosition = VesselController.getPosition();
            var   currentVelocity = VesselController.getVelocity();
            float stepsize        = 1.0f;

            float  time       = 0.0f;
            double min        = 99999999990.0;
            double max        = 0.0;
            double last       = VesselController.getAltitudeAtPoint(currentPosition);
            int    direction  = 0;
            int    changes    = 0;
            double timeToApo  = 0.0;
            double timeToPeri = 0.0;

            while (true)
            {
                var gravity       = VesselController.getGravityAtPoint(currentPosition);
                var gravityLength = gravity.Length();
                //Console.WriteLine(gravity.Length());
                currentVelocity += gravity * stepsize;
                currentPosition += currentVelocity * stepsize;
                double newAltitude = VesselController.getAltitudeAtPoint(currentPosition);
                time += stepsize;
                if (newAltitude < min)
                {
                    min        = newAltitude;
                    timeToPeri = time;
                }
                if (newAltitude > max)
                {
                    max       = newAltitude;
                    timeToApo = time;
                }
                if (direction == 0)
                {
                    direction = newAltitude < last ? -1 : 1;
                    changes++;
                }
                else if (direction == 1 && gravityLength < last)
                {
                    changes++;
                    direction = -1;
                }
                else if (direction == -1 && gravityLength >= last)
                {
                    changes++;
                    direction = 1;
                }
                last = last * 0.999 + 0.001 * gravityLength;
                if (changes > 3)
                {
                    break;
                }
                if (newAltitude < 0)
                {
                    break;
                }
            }
            VesselController.setReferenceFrameType(VesselController.ReferenceFrameType.ClosestBodySurface);
            VesselController.updateBodyPosition();
            return(new ApoapsisPeriapsisPrediction()
            {
                Apoapsis = max,
                Periapsis = min,
                TimeToApoapsis = timeToApo,
                TimeToPeriapsis = timeToPeri
            });
        }