Esempio n. 1
0
        public RelationFlag(Relation relation)
        {
            this.detail          = new BitVector32();
            this.kind            = new BitVector32();
            kind[superiorMask]   = (int)(relation.Superior);
            kind[inferiorMask]   = (int)relation.Inferior;
            kind[aspectTypeMask] = (int)relation.Aspect.Kind;
            kind[directionMask]  = (relation.Aspect.Degrees > 180) ? 1 : 0;


            detail[superiorDirection] = relation.SuperiorPosition.LongitudeVelocity >= 0 ? 0 : 1;
            detail[inferiorDirection] = relation.InferiorPosition.LongitudeVelocity >= 0 ? 0 : 1;
            detail[sameDirection]     = (detail[superiorDirection] == detail[inferiorDirection]) ? 1 : 0;

            Angle current = new Rectascension(relation.InferiorPosition.Longitude - relation.SuperiorPosition.Longitude).Reference;
            Angle next    = new Angle(relation.SuperiorPosition.Longitude + relation.SuperiorPosition.LongitudeVelocity
                                      - relation.InferiorPosition.Longitude - relation.InferiorPosition.LongitudeVelocity).Reference;

            detail[angleExpanding] = (next.Degrees > current.Degrees) ? 1 : 0;

            detail[superiorNorthOrSouth] = relation.SuperiorPosition.Latitude >= 0 ? 0 : 1;
            detail[superiorInclination]  = relation.SuperiorPosition.LatitudeVelocity >= 0 ? 1 : 0;
            detail[inferiorNorthOrSouth] = relation.InferiorPosition.Latitude >= 0 ? 0 : 1;
            detail[inferiorInclination]  = relation.InferiorPosition.LatitudeVelocity >= 0 ? 1 : 0;
        }
Esempio n. 2
0
        public Relation(DateTimeOffset moment, Position one, Position another)
        {
            Moment = moment;
            if (one.Owner > another.Owner)
            {
                SuperiorPosition = one;
                InferiorPosition = another;
            }
            else
            {
                SuperiorPosition = another;
                InferiorPosition = one;
            }
            Aspect = Aspects.AspectBetween(SuperiorPosition.Longitude, InferiorPosition.Longitude);

            ReferenceAngle = new Rectascension(InferiorPosition.Longitude - SuperiorPosition.Longitude).Reference;

            if (Aspect != null)
            {
                Orb  = Aspect.OrbOf(InferiorPosition.Longitude - SuperiorPosition.Longitude);
                Flag = new RelationFlag(this);
            }
        }
Esempio n. 3
0
        public DateTimeOffset ExactlyTimeOf(PlanetId id, DateTimeOffset refDate, Rectascension destination)
        {
            double   jul_ut = Utilities.ToJulianDay(refDate);
            double   averageSpeed = Planet.AverageSpeedOf(id);
            Position posAverage, posDynamic = PositionDelegate(jul_ut, id);

            double shiftDynamic, shiftAverage;
            double dest = destination.Degrees;

            double distanceDynamic = Angle.BeelineOf(posDynamic.Longitude, dest);

            if (distanceDynamic < 0)
            {
                distanceDynamic += 360;
            }

            double lastDistance = 360, lastShift, distanceAverage = distanceDynamic;

            shiftDynamic = distanceDynamic / (posDynamic.LongitudeVelocity < 0 ? averageSpeed : posDynamic.LongitudeVelocity);
            shiftAverage = distanceAverage / averageSpeed;

            for (int i = 0; i < 10; i++)
            {
                posDynamic = PositionDelegate(jul_ut + shiftDynamic, id);
                posAverage = PositionDelegate(jul_ut + shiftAverage, id);

                distanceDynamic = Angle.BeelineOf(posDynamic.Longitude, dest);
                distanceAverage = Angle.BeelineOf(posAverage.Longitude, dest);


                if (Math.Abs(distanceAverage) > Math.Abs(distanceDynamic))
                {
                    if (Math.Abs(distanceDynamic) < Negligible)
                    {
                        return(Utilities.UtcFromJulianDay(jul_ut));
                    }

                    jul_ut         += shiftDynamic;
                    lastShift       = shiftDynamic;
                    distanceAverage = distanceDynamic;
                    posAverage      = posDynamic;
                    lastDistance    = distanceDynamic;
                }
                else
                {
                    if (Math.Abs(distanceAverage) < Negligible)
                    {
                        return(Utilities.UtcFromJulianDay(jul_ut));
                    }

                    jul_ut         += shiftAverage;
                    lastShift       = shiftAverage;
                    distanceDynamic = distanceAverage;
                    posDynamic      = posAverage;
                    lastDistance    = distanceAverage;
                }

                shiftDynamic = distanceDynamic / posDynamic.LongitudeVelocity;
                shiftAverage = distanceAverage / averageSpeed;
            }

            throw new Exception("Failed destination get the exact time!");
        }
Esempio n. 4
0
        //static Ephemeris()
        //{
        //    try
        //    {
        //        luminous = new List<PlanetId>();

        //        for (PlanetId id = PlanetId.SE_SUN; id < PlanetId.SE_MEAN_NODE; id++)
        //        {
        //            luminous.Add(id);
        //        }
        //        luminous.Add(PlanetId.SE_NORTHNODE);
        //    }
        //    catch
        //    {
        //        Console.WriteLine("Something wrong!");
        //    }
        //}

        //public static DateTimeOffset ExactlyTimeOf(PlanetId id, DateTimeOffset refDate, Rectascension destination)
        //{
        //    double jul_ut = Utilities.ToJulianDay(refDate);
        //    double averageSpeed = Planet.AverageSpeedOf(id);
        //    Position posAverage, posDynamic = PositionDelegate(jul_ut, id);

        //    double shiftDynamic, shiftAverage;
        //    double dest = destination.Degrees;

        //    double distanceDynamic = Angle.BeelineOf(posDynamic.Longitude, dest);

        //    if (distanceDynamic < 0) distanceDynamic += 360;

        //    double lastDistance = 360, lastShift, distanceAverage = distanceDynamic;

        //    shiftDynamic = distanceDynamic / (posDynamic.LongitudeVelocity < 0 ? averageSpeed : posDynamic.LongitudeVelocity);
        //    shiftAverage = distanceAverage / averageSpeed;

        //    for (int i = 0; i < 10; i++)
        //    {
        //        posDynamic = PositionDelegate(jul_ut + shiftDynamic, id);
        //        posAverage = PositionDelegate(jul_ut + shiftAverage, id);

        //        distanceDynamic = Angle.BeelineOf(posDynamic.Longitude, dest);
        //        distanceAverage = Angle.BeelineOf(posAverage.Longitude, dest);


        //        if (Math.Abs(distanceAverage) > Math.Abs(distanceDynamic))
        //        {
        //            if (Math.Abs(distanceDynamic) < Negligible)
        //                return Utilities.UtcFromJulianDay(jul_ut);

        //            jul_ut += shiftDynamic;
        //            lastShift = shiftDynamic;
        //            distanceAverage = distanceDynamic;
        //            posAverage = posDynamic;
        //            lastDistance = distanceDynamic;
        //        }
        //        else
        //        {
        //            if (Math.Abs(distanceAverage) < Negligible)
        //                return Utilities.UtcFromJulianDay(jul_ut);

        //            jul_ut += shiftAverage;
        //            lastShift = shiftAverage;
        //            distanceDynamic = distanceAverage;
        //            posDynamic = posAverage;
        //            lastDistance = distanceAverage;

        //        }

        //        shiftDynamic = distanceDynamic / posDynamic.LongitudeVelocity;
        //        shiftAverage = distanceAverage / averageSpeed;

        //    }

        //    throw new Exception("Failed destination get the exact time!");
        //}

        //public static Angle AngleOfTime(DateTimeOffset time)
        //{
        //    DateTimeOffset equinox = VernalEquinoxTimeOf(time.Year);

        //    Double daysPassed = (time - equinox).TotalDays;

        //    if (daysPassed < 0)
        //        daysPassed += AverageYearLength;

        //    return new Angle( (daysPassed / AverageYearLength) * 360 );
        //}

        public static DateTimeOffset DateOfPlanetPosition(PlanetId star, DateTimeOffset since, Rectascension destination)
        {
            DateTimeOffset date;
            Position       posPrev, posNext;
            Double         difPrev, difNext;

            posPrev = CurrentEphemeris[since, star];
            difPrev = Angle.DistanceBetween(posPrev.Longitude, destination.Degrees);

            if (difPrev > 60)
            {
                throw new ArgumentOutOfRangeException("The date of starting search is not set properly.");
            }
            else if (difPrev < Negligible)
            {
                return(since);
            }

            for (int i = 1; i < 200; i++)
            {
                date    = since.AddDays(i);
                posNext = CurrentEphemeris[date, star];

                difNext = Angle.DistanceBetween(posNext.Longitude, destination.Degrees);

                if (difPrev <= difNext)
                {
                    return(date.AddDays(-1));
                }
                else if (difPrev < Angle.DistanceBetween(posNext.Longitude, posPrev.Longitude))
                {
                    return(date.AddDays(-1));
                }

                posPrev = posNext;
                difPrev = difNext;
            }

            return(DateTimeOffset.MinValue);

            //Double cusp = destination.Within.Cusp;
            //Sign destSign = destination.Within;
            //Position pos1, pos2;

            //DateTimeOffset date1, date2, enter, exit;

            //enter = entryDateAround(star, destSign, since);
            //exit = entryDateAround(star, destSign + 1, enter);

            //for (date1 = enter.AddDays(-1); date1 < exit; date1 += TimeSpan.FromDays(1) )
            //{
            //    date2 = date1.AddDays(1);
            //    pos1 = Geocentric[date1, star];
            //    pos2 = Geocentric[date2, star];

            //    Double b2 = Angle.BeelineOf(pos2.Longitude, destination.Degrees);
            //    Double b1 = Angle.BeelineOf(pos1.Longitude, destination.Degrees);

            //    if (b2 > 0 || b1 < 0)
            //        continue;

            //    return date2;
            //}

            throw new Exception();
        }
Esempio n. 5
0
 public string ToString(string format, IFormatProvider formatProvider)
 {
     return(String.Format("{0}: {1}({2:F3})", Planet.SymbolOf(Owner), Rectascension.AngleFormatOf(Longitude, format), LongitudeVelocity));
 }