示例#1
0
            public orbit(string orbitName, string parentName)
            {
                name         = orbitName;
                child_orbits = new List <orbit> ();

                if (!string.IsNullOrEmpty(parentName))
                {
                    parent = new orbit(parentName, null);
                }
            }
示例#2
0
 // Use this for initialization
 void Start()
 {
     objects_size  = moving_objects.Length;
     player        = GameObject.FindGameObjectWithTag("Player").GetComponent <rotor>();
     objects_speed = new float[objects_size];
     for (int i = 0; i < objects_size; i++)
     {
         objects_speed[i] = moving_objects[i].GetComponent <move_obstacle>().speed;
     }
     orb = gameObject.GetComponent <orbit>();
 }
示例#3
0
        private static orbit GenerateOrbitList(List <OrbitRelation> relations)
        {
            var allOrbits = new List <orbit> ();

            foreach (var relation in relations)
            {
                if (allOrbits.Any(x => x.name == relation.Orbiter))
                {
                    throw new Exception("Orbiter already has a parent");
                }
                allOrbits.Add(new orbit(relation.Orbiter, relation.Target));
            }

            var rootOrbit = new orbit("COM", null);

            rootOrbit.assignallchildren(allOrbits);
            return(rootOrbit);
        }
示例#4
0
            public orbit FindChildren(string childName)
            {
                orbit result = null;

                foreach (var child in this.child_orbits)
                {
                    if (child.name == childName)
                    {
                        result = child;
                        break;
                    }
                    else if (child.child_orbits.Any())
                    {
                        result = child.FindChildren(childName);
                    }
                    if (result != null)
                    {
                        return(result);
                    }
                }
                return(result);
            }
示例#5
0
        /// <summary>
        /// Compute rectangular (x/y/z) heliocentric J2000 equatorial coordinates of position (AU) and
        /// velocity (KM/sec.).
        /// </summary>
        /// <param name="tjd">Terrestrial Julian date/time for which position and velocity is to be computed</param>
        /// <returns>Array of 6 values containing rectangular (x/y/z) heliocentric J2000 equatorial
        /// coordinates of position (AU) and velocity (KM/sec.) for the body.</returns>
        /// <remarks>The TJD parameter is the date/time as a Terrestrial Time Julian date. See below for
        /// more info. If you are using ACP, there are functions available to convert between UTC and
        /// Terrestrial time, and for estimating the current value of delta-T. See the Overview page for
        /// the Kepler.Ephemeris class for more information on time keeping systems.</remarks>
        public double[] GetPositionAndVelocity(double tjd)
        {
            double[] posvec = new double[6];
            int[]    ai     = new int[2];
            double[,] pos = new double[4, 4];
            orbit  op  = new orbit();
            int    i   = 0;
            double qjd = 0;

            double[] p = new double[3];

            if (!m_bTypeValid)
            {
                throw (new Exceptions.ValueNotSetException("Kepler:GetPositionAndVelocity Body type has not been set"));
            }
            //TL.LogMessage("GetPosAndVel", m_Number.ToString)
            if (m_Type == BodyType.MajorPlanet) //MAJOR PLANETS [unimpl. SUN, MOON]
            {
                if (m_Number == Body.Mercury)
                {
                    op = mercury;
                }
                else if (m_Number == Body.Venus)
                {
                    op = venus;
                }
                else if (m_Number == Body.Earth)
                {
                    op = earthplanet;
                }
                else if (m_Number == Body.Mars)
                {
                    op = mars;
                }
                else if (m_Number == Body.Jupiter)
                {
                    op = jupiter;
                }
                else if (m_Number == Body.Saturn)
                {
                    op = saturn;
                }
                else if (m_Number == Body.Uranus)
                {
                    op = uranus;
                }
                else if (m_Number == Body.Neptune)
                {
                    op = neptune;
                }
                else if (m_Number == Body.Pluto)
                {
                    op = pluto;
                }
                else
                {
                    throw (new Utilities.Exceptions.InvalidValueException("Kepler:GetPositionAndVelocity Invalid value for planet number: " + System.Convert.ToString(m_Number)));
                }
            } //MINOR PLANET
            else if (m_Type == BodyType.MinorPlanet)
            {
                ////TODO: Check elements
                op = m_e;
            } //COMET
            else if (m_Type == BodyType.Comet)
            {
                ////TODO: Check elements
                op = m_e;
            }
            for (i = 0; i <= 2; i++)
            {
                qjd = tjd + (i - 1) * DTVEL;
                //TL.LogMessage("GetPosVel", "Before KepCalc")
                KeplerCalc(qjd, op, p);
                //TL.LogMessage("GetPosVel", "After KepCalc")
                pos[i, 0] = p[0];
                pos[i, 1] = p[1];
                pos[i, 2] = p[2];
            }

            //pos(1,x) contains the pos vector
            //pos(0,x) and pos(2,x) are used to determine the velocity based on position change with time!
            for (i = 0; i <= 2; i++)
            {
                posvec[i]     = pos[1, i];
                posvec[3 + i] = System.Convert.ToInt32((pos[2, i] - pos[0, i]) / (2.0 * DTVEL));
            }

            return(posvec);
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="moverAbsolutePos"></param>
        /// <param name="speed"></param>
        /// <param name="targetOrbit"></param>
        /// <param name="atDateTime"></param>
        /// <param name="offsetPosition">position ralitive to the target object we wish to stop warp.</param>
        /// <returns></returns>
        public static (Vector3 position, DateTime etiDateTime) GetInterceptPosition_m(Vector3 moverAbsolutePos, double speed, OrbitDB targetOrbit, DateTime atDateTime, Vector3 offsetPosition = new Vector3())
        {
            var    pos = moverAbsolutePos;
            double tim = 0;

            var pl = new orbit()
            {
                position = moverAbsolutePos,
                T        = targetOrbit.OrbitalPeriod.TotalSeconds,
            };

            double a = targetOrbit.SemiMajorAxis * 2;

            Vector3 p;
            int     i;
            double  tt, t, dt, a0, a1, T;

            // find orbital position with min error (coarse)
            a1 = -1.0;
            dt = 0.01 * pl.T;


            for (t = 0; t < pl.T; t += dt)
            {
                p  = OrbitProcessor.GetAbsolutePosition_m(targetOrbit, atDateTime + TimeSpan.FromSeconds(t)); //pl.position(sim_t + t);                     // try time t
                p += offsetPosition;
                tt = Vector3.Magnitude(p - pos) / speed;                                                      //length(p - pos) / speed;
                a0 = tt - t; if (a0 < 0.0)
                {
                    continue;                                 // ignore overshoots
                }
                a0 /= pl.T;                                   // remove full periods from the difference
                a0 -= Math.Floor(a0);
                a0 *= pl.T;
                if ((a0 < a1) || (a1 < 0.0))
                {
                    a1  = a0;
                    tim = tt;
                }   // remember best option
            }
            // find orbital position with min error (fine)
            for (i = 0; i < 10; i++)                               // recursive increase of accuracy
            {
                for (a1 = -1.0, t = tim - dt, T = tim + dt, dt *= 0.1; t < T; t += dt)
                {
                    p  = OrbitProcessor.GetAbsolutePosition_m(targetOrbit, atDateTime + TimeSpan.FromSeconds(t)); //p = pl.position(sim_t + t);                     // try time t
                    p += offsetPosition;
                    tt = Vector3.Magnitude(p - pos) / speed;                                                      //tt = length(p - pos) / speed;
                    a0 = tt - t; if (a0 < 0.0)
                    {
                        continue;                                 // ignore overshoots
                    }
                    a0 /= pl.T;                                   // remove full periods from the difference
                    a0 -= Math.Floor(a0);
                    a0 *= pl.T;
                    if ((a0 < a1) || (a1 < 0.0))
                    {
                        a1  = a0;
                        tim = tt;
                    }   // remember best option
                }
            }
            // direction
            p  = OrbitProcessor.GetAbsolutePosition_m(targetOrbit, atDateTime + TimeSpan.FromSeconds(tim));//pl.position(sim_t + tim);
            p += offsetPosition;
            //dir = normalize(p - pos);
            return(p, atDateTime + TimeSpan.FromSeconds(tim));
        }