Ejemplo n.º 1
0
        private static DateTimeOffset entryDateAround(PlanetId star, Sign destSign, DateTimeOffset around)
        {
            Double         speed         = Planet.AverageSpeedOf(star);
            int            dayAdjustment = 0;
            DateTimeOffset date          = around.UtcDateTime.Date;
            Position       pos           = CurrentEphemeris[date, star];

            int dif = destSign.Order - Sign.SignOf(pos.Longitude).Order;

            dayAdjustment = dif > 0 ? (int)((destSign.Order - Sign.SignOf(pos.Longitude).Order - 1) * 30 / speed)
                : (int)((11 + destSign.Order - Sign.SignOf(pos.Longitude).Order) * 30 / speed);

            do
            {
                date = date.AddDays(dayAdjustment);
                pos  = CurrentEphemeris[date, star];
                dayAdjustment--;
            } while (Sign.SignOf(pos.Longitude) != destSign.Previous);

            if (Sign.SignOf(pos.Longitude) != destSign.Previous)
            {
                throw new Exception();
            }

            do
            {
                date = date.AddDays(1);
                pos  = CurrentEphemeris[date, star];
                if (Sign.SignOf(pos.Longitude) == destSign)
                {
                    return(date);
                }
            } while (true);

            throw new Exception();
        }
Ejemplo n.º 2
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!");
        }