예제 #1
0
        public DateEvents(DateTimeOffset date)
        {
            try
            {
                if (date.TimeOfDay == TimeSpan.Zero && date.Offset == TimeSpan.Zero)
                {
                    Date = date;
                }
                else
                {
                    Date = new DateTimeOffset(date.UtcDateTime.Date, TimeSpan.Zero);
                }

                MatchRules during = new MatchRules(Date, SearchMode.WithinTheDay);
                Relations = Ephemeris.RelationsWithin(during);

                Positions = new Dictionary <PlanetId, PlanetEvents>();

                for (PlanetId id = PlanetId.SE_SUN; id <= PlanetId.SE_PLUTO; id++)
                {
                    Positions.Add(id, new PlanetEvents(TheEphemeris, Date, id));
                }
                Positions.Add(PlanetId.SE_NORTHNODE, new PlanetEvents(TheEphemeris, Date, PlanetId.SE_NORTHNODE));
                Positions.Add(PlanetId.SE_CHIRON, new PlanetEvents(TheEphemeris, Date, PlanetId.SE_CHIRON));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        private bool merge(Ephemeris other)
        {
            if (!other.Name.StartsWith(this.Name))
            {
                throw new Exception();
            }

            if (Buffer.Count == 0)
            {
                Buffer = other.Buffer;
            }
            else if (Buffer.ContainsKey(other.Buffer.First().Key))
            {
                throw new Exception("No need of merge at all ! ?");
            }
            else
            {
                foreach (KeyValuePair <DateTimeOffset, List <Position> > kvp in other.Buffer)
                {
                    Buffer.Add(kvp.Key, kvp.Value);
                }
            }

            return(true);
        }
예제 #3
0
        private Ephemeris(string name, PositionLookupDelegate positionDel, DateTimeOffset date)
            : this(name, positionDel)
        {
            Ephemeris decade = decadeEphemerisOf(date);

            this.merge(decade);
        }
예제 #4
0
        public Position this[DateTimeOffset date, PlanetId id]
        {
            get
            {
                if (date.TimeOfDay != TimeSpan.Zero)
                {
                    double jul_ut = Utilities.ToJulianDay(date);
                    return(PositionDelegate(jul_ut, id));
                }

                if (!Buffer.ContainsKey(date))
                {
                    Ephemeris decade = decadeEphemerisOf(date);
                    this.merge(decade);
                }

                Position result = PositionOf(Buffer[date], id);

                if (result == null)
                {
                    double jul_ut = Utilities.ToJulianDay(date);
                    result = PositionDelegate(jul_ut, id);
                    Buffer[date].Add(result);
                }

                return(result);
            }
        }
예제 #5
0
        private Ephemeris decadeEphemerisOf(DateTimeOffset date)
        {
            int    startYear = 10 * (date.Year / 10);
            string fileName  = String.Format("{0}{1}.eph", Name, startYear);

            FileInfo[] files      = EphemerisDirectory.GetFiles(fileName, SearchOption.AllDirectories);
            Ephemeris  decadeEphe = null;

            if (files.Length != 0)
            {
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(EphemerisDirectory + fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                decadeEphe = (Ephemeris)formatter.Deserialize(stream);
                stream.Close();
            }

            if (decadeEphe == null)
            {
                decadeEphe = new Ephemeris(Name + startYear.ToString(), PositionDelegate);
                DateTimeOffset start = new DateTimeOffset(startYear, 1, 1, 0, 0, 0, TimeSpan.Zero);
                DateTimeOffset end   = new DateTimeOffset(startYear + 10, 1, 1, 0, 0, 0, TimeSpan.Zero);
                decadeEphe.calculate(start, end);

                decadeEphe.save();
            }

            return(decadeEphe);
        }
예제 #6
0
        public List <Position> this[DateTimeOffset date]
        {
            get
            {
                if (date.TimeOfDay != TimeSpan.Zero || date.Offset != TimeSpan.Zero)
                {
                    return(lookFor(Utilities.ToJulianDay(date)));
                }

                if (!Buffer.ContainsKey(date))
                {
                    Ephemeris decade = decadeEphemerisOf(date);
                    this.merge(decade);
                }

                return(Buffer[date]);
            }
        }
예제 #7
0
        public void Load(DateTimeOffset start, DateTimeOffset end)
        {
            int startYear = 10 * (start.Year / 10);
            int endYear   = 10 * (end.Year / 10);

            for (; startYear <= endYear; startYear += 10)
            {
                DateTimeOffset date = new DateTimeOffset(startYear, 1, 1, 0, 0, 0, TimeSpan.Zero);

                if (!Buffer.ContainsKey(date))
                {
                    Ephemeris decade = decadeEphemerisOf(date);
                    this.merge(decade);
                    date = decade.Until.AddDays(1);
                }
                ;
            }
        }
예제 #8
0
        public static Double DegreeToEquinox(DateTimeOffset time)
        {
            DateTimeOffset thisVernal = Ephemeris.VernalEquinoxTimeOf(time.Year);
            Double         yearLength, elapsed;

            if (time >= thisVernal)
            {
                DateTimeOffset end = Ephemeris.VernalEquinoxTimeOf(time.Year + 1);
                yearLength = (end - thisVernal).TotalDays;
                elapsed    = (time - thisVernal).TotalDays;
            }
            else
            {
                DateTimeOffset last = Ephemeris.VernalEquinoxTimeOf(time.Year - 1);
                yearLength = (thisVernal - last).TotalDays;
                elapsed    = (time - last).TotalDays;
            }
            return((elapsed * 360 / yearLength).Normalize());
        }
예제 #9
0
        public PlanetEvents(Ephemeris ephem, DateTimeOffset date, PlanetId id)
        {
            List <Position>       watchedPositions = new List <Position>();
            List <double>         longSpeeds       = new List <double>();
            List <double>         latSpeeds        = new List <double>();
            List <double>         latitudes        = new List <double>();
            List <double>         distSpeeds       = new List <double>();
            List <DateTimeOffset> retroDates       = null;

            try
            {
                TheEphemeris = ephem;
                Date         = date;

                for (int i = -WatchingDays; i <= WatchingDays; i++)
                {
                    Position pos = TheEphemeris[date.AddDays(i), id];
                    watchedPositions.Add(pos);
                    latitudes.Add(pos.Latitude);
                    longSpeeds.Add(pos.LongitudeVelocity);
                    latSpeeds.Add(pos.LatitudeVelocity);
                    distSpeeds.Add(pos.DistanceVelocity);
                }

                Current            = watchedPositions[WatchingDays];
                RelationWithOthers = Ephemeris.RelationsWithin(new MatchRules(date, SearchMode.WithinTheDay), id);

                //List<double> reversedVelocities = Ephemeris.TurningsOf(longSpeeds);

                //if (reversedVelocities.Count != 0)
                //{

                //}


                double minLongVel = (from spd in longSpeeds
                                     orderby Math.Abs(spd)
                                     select spd).FirstOrDefault();

                int            stationIndex = longSpeeds.IndexOf(minLongVel);
                DateTimeOffset around       = Date.AddDays(stationIndex - WatchingDays);
                retroDates = Ephemeris.RetrogradeDateAround(id, around);

                if (retroDates != null)
                {
                    DateTimeOffset nearest = (from keyDay in retroDates
                                              orderby Math.Abs((date - keyDay).TotalDays)
                                              select keyDay).FirstOrDefault();

                    if (!retroDates.Contains(nearest))
                    {
                        LongitudeStatus         = RectascensionMode.None;
                        DaysToRectascensionMode = 100;
                    }
                    else
                    {
                        DaysToRectascensionMode = (int)((date - nearest).TotalDays);

                        if (DaysToRectascensionMode > EffectiveDays || DaysToRectascensionMode < -EffectiveDays)
                        {
                            LongitudeStatus = RectascensionMode.None;
                        }
                        else
                        {
                            switch (retroDates.IndexOf(nearest))
                            {
                            case 0:
                                LongitudeStatus = RectascensionMode.Resisted;
                                break;

                            case 1:
                                LongitudeStatus = RectascensionMode.Retrograde;
                                break;

                            case 2:
                                LongitudeStatus = RectascensionMode.Direct;
                                break;

                            case 3:
                                LongitudeStatus = RectascensionMode.Transcend;
                                break;

                            default:
                                LongitudeStatus = RectascensionMode.None;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    getRectascensionMode(longSpeeds);
                }

                getDeclinationMode(latSpeeds, latitudes);
                getDistanceMode(distSpeeds);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
            }
        }
예제 #10
0
 private Ephemeris(string name, DateTimeOffset date) : this(name)
 {
     Ephemeris decade = decadeEphemerisOf(date);
     this.merge(decade);
 }
예제 #11
0
        public OrbitsCollection(DateTimeOffset since, DateTimeOffset until, Ephemeris ephemeris)
        {
            Start = since;
            End   = until;

            //Longitudes = new Dictionary<PlanetId, List<Double>>();
            //Latitudes = new Dictionary<PlanetId, List<double>>();
            //Distances = new Dictionary<PlanetId, List<double>>();
            //LongitudeVelocities = new Dictionary<PlanetId, List<double>>();
            //LatitudeVelocities = new Dictionary<PlanetId, List<double>>();
            //DistanceVelocities = new Dictionary<PlanetId, List<double>>();

            //for (PlanetId id = PlanetId.SE_SUN; id <= PlanetId.SE_PLUTO; id ++ )
            //{
            //    Longitudes.Add(id, new List<double>());
            //    Latitudes.Add(id, new List<double>());
            //    Distances.Add(id, new List<double>());
            //    LongitudeVelocities.Add(id, new List<double>());
            //    LatitudeVelocities.Add(id, new List<double>());
            //    DistanceVelocities.Add(id, new List<double>());
            //}

            ephemeris.Load(since, until);

            AllOrbits = new Dictionary <PlanetId, Dictionary <OrbitInfoType, List <double> > >();

            for (PlanetId id = PlanetId.SE_SUN; id <= PlanetId.SE_CHIRON; id++)
            {
                if (id > PlanetId.SE_PLUTO && id != PlanetId.SE_CHIRON)
                {
                    continue;
                }

                Dictionary <OrbitInfoType, List <Double> > newOrbit = new Dictionary <OrbitInfoType, List <Double> >();
                newOrbit.Add(OrbitInfoType.Longitude, new List <double>());
                newOrbit.Add(OrbitInfoType.Latitude, new List <double>());
                newOrbit.Add(OrbitInfoType.Distance, new List <double>());
                newOrbit.Add(OrbitInfoType.LongitudeVelocities, new List <double>());
                newOrbit.Add(OrbitInfoType.LatitudeVelocities, new List <double>());
                newOrbit.Add(OrbitInfoType.DistanceVelocities, new List <double>());

                AllOrbits.Add(id, newOrbit);
            }

            TimeSpan interval = TimeSpan.FromDays(NormalIntervalDays);

            DayByDay     = new List <Double>();
            MonthByMonth = new List <Double>();

            for (DateTimeOffset date = Start; date <= End; date += TimeSpan.FromDays(SparsedInterval))
            {
                MonthByMonth.Add(date.UtcDateTime.ToOADate());
            }

            for (DateTimeOffset date = since; date <= until; date += interval)
            {
                List <Position> positions = ephemeris[date];
                DayByDay.Add(date.UtcDateTime.ToOADate());
                Position pos;

                for (int i = (int)PlanetId.SE_SUN; i <= (int)PlanetId.SE_PLUTO; i++)
                {
                    pos = positions[i];
                    PlanetId id = pos.Owner;

                    AllOrbits[id][OrbitInfoType.Longitude].Add(pos.Longitude);
                    AllOrbits[id][OrbitInfoType.Latitude].Add(pos.Latitude);
                    AllOrbits[id][OrbitInfoType.Distance].Add(pos.Distance);
                    AllOrbits[id][OrbitInfoType.LongitudeVelocities].Add(pos.LongitudeVelocity);
                    AllOrbits[id][OrbitInfoType.LatitudeVelocities].Add(pos.LatitudeVelocity);
                    AllOrbits[id][OrbitInfoType.DistanceVelocities].Add(pos.DistanceVelocity);
                }

                pos = positions.Last();
                if (pos.Owner == PlanetId.SE_CHIRON)
                {
                    Dictionary <OrbitInfoType, List <Double> > values = AllOrbits[PlanetId.SE_CHIRON];
                    values[OrbitInfoType.Longitude].Add(pos.Longitude);
                    values[OrbitInfoType.Latitude].Add(pos.Latitude);
                    values[OrbitInfoType.Distance].Add(pos.Distance);
                    values[OrbitInfoType.LongitudeVelocities].Add(pos.LongitudeVelocity);
                    values[OrbitInfoType.LatitudeVelocities].Add(pos.LatitudeVelocity);
                    values[OrbitInfoType.DistanceVelocities].Add(pos.DistanceVelocity);
                }
            }

            //ascendingOrbits = new Dictionary<PlanetId, List<double>>();
            //descendingOrbits = new Dictionary<PlanetId, List<double>>();
            //perigeeOrbits = new Dictionary<PlanetId, List<double>>();
            //apogeeOrbits = new Dictionary<PlanetId, List<double>>();

            //ascendingHeights = new Dictionary<PlanetId, List<double>>();
            //descendingHeights = new Dictionary<PlanetId, List<double>>();
            //perigeeHeights = new Dictionary<PlanetId, List<double>>();
            //apogeeHeights = new Dictionary<PlanetId, List<double>>();

            //ascendingVelocities = new Dictionary<PlanetId, List<double>>();
            //descendingVelocities = new Dictionary<PlanetId, List<double>>();
            //perigeeVelocities = new Dictionary<PlanetId, List<double>>();
            //apogeeVelocities = new Dictionary<PlanetId, List<double>>();
        }