Ejemplo n.º 1
0
        private void ThithiEndTime(double[] cusps, AstroPlanet curSun, double orgSunLong, double orgMoonLong, Mod mod360)
        {
            double      thithiEnd     = Math.Truncate(mod360.sub(orgMoonLong, orgSunLong) / AstroConsts.ThithiLength) * AstroConsts.ThithiLength + AstroConsts.ThithiLength;
            AstroThithi tempThithi    = new AstroThithi(new AstroThithi(EnumThithi.Amavasya).ofDeg(curSun.Longitude, cusps[0]));
            AstroThithi currentThithi = new AstroThithi(new AstroThithi(EnumThithi.Amavasya).ofDeg(orgSunLong, orgMoonLong));

            if (currentThithi.Current != tempThithi.Current)
            {
                double difSpeed      = cusps[3] - curSun.SpeedInLongitude;
                double thithiTimeDif = ((mod360.sub(cusps[0], curSun.Longitude) - thithiEnd) / ((difSpeed == 0) ? 1 : difSpeed)) * 1440 * -1;
                if (ThithiEndDateTime == null)
                {
                    ThithiEndDateTime = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone).AddMinutes(thithiTimeDif);
                }
            }
        }
Ejemplo n.º 2
0
        private void KarnaEndTime(double[] cusps, AstroPlanet curSun, double orgSunLong, double orgMoonLong, Mod mod360)
        {
            double     karnaEnd     = Math.Truncate(mod360.sub(cusps[0], orgSunLong) / AstroConsts.KaranaLength) * AstroConsts.KaranaLength;
            AstroKarna tempKarna    = new AstroKarna(new AstroKarna(EnumKarana.Balava).ofDeg(curSun.Longitude, cusps[0]));
            AstroKarna currentKarna = new AstroKarna(new AstroKarna(EnumKarana.Balava).ofDeg(orgSunLong, orgMoonLong));

            if (currentKarna.Current != tempKarna.Current)
            {
                double difSpeed   = cusps[3] - curSun.SpeedInLongitude;
                double karTimeDif = ((mod360.sub(cusps[0], curSun.Longitude) - karnaEnd) / ((difSpeed == 0) ? 1 : difSpeed)) * 1440 * -1;
                if (KarnaEndDateTime == null)
                {
                    KarnaEndDateTime = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone).AddMinutes(karTimeDif);
                }
            }
        }
Ejemplo n.º 3
0
        private void YogaEndTime(double[] cusps, AstroPlanet curSun, double orgSunLong, double orgMoonLong, Mod mod360)
        {
            double    yogaEnd     = Math.Truncate(mod360.add(orgMoonLong, orgSunLong) / AstroConsts.YogaLength) * AstroConsts.YogaLength + AstroConsts.YogaLength;
            AstroYoga tempYoga    = new AstroYoga(new AstroYoga(EnumYoga.Shula).ofDeg(curSun.Longitude, cusps[0]));
            AstroYoga currentYoga = new AstroYoga(new AstroYoga(EnumYoga.Shula).ofDeg(orgSunLong, orgMoonLong));

            if (currentYoga.Current != tempYoga.Current)
            {
                double totalSpeed  = curSun.SpeedInLongitude + cusps[3];
                double yogaTimeDif = ((mod360.add(cusps[0], curSun.Longitude) - yogaEnd) / ((totalSpeed == 0) ? 1 : totalSpeed)) * 1440 * -1;
                if (YogaEndDateTime == null)
                {
                    YogaEndDateTime = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone).AddMinutes(yogaTimeDif);
                }
            }
        }
Ejemplo n.º 4
0
        private AstroPlanet Initialization(List <AstroPlanet> planets, double[] cusps, int planet, ref AstroPlanet ketu
                                           , ref double orgSunLong, ref double orgMoonLong)
        {
            Mod         mod360  = new Mod(360);
            AstroPlanet pReturn = new AstroPlanet(planet, cusps, LocationData);

            pReturn.Name = swissEph.swe_get_planet_name(planet);
            planets.Add(pReturn);
            if (pReturn.Current == EnumPlanet.Sun)
            {
                orgSunLong = pReturn.Longitude;
            }
            else if (pReturn.Current == EnumPlanet.Moon)
            {
                orgMoonLong = pReturn.Longitude;
            }
            // Add Ketu
            if (planet == SwissEph.SE_TRUE_NODE)
            {
                pReturn.Name = "Rahu";
                double[] kethuCusps = new double[6];
                cusps.CopyTo(kethuCusps, 0);
                kethuCusps[0] = mod360.add(kethuCusps[0], 180.00) % 360;
                ketu          = new AstroPlanet(12, kethuCusps, LocationData);
                ketu.Name     = "Kethu";
                planets.Add(ketu);
            }

            if (pReturn.RasiStart == 0.0)
            {
                pReturn.RasiStart = Math.Truncate(cusps[0] / AstroConsts.RasiLength) * AstroConsts.RasiLength;
            }
            if (pReturn.RasiEnd == 0.0)
            {
                pReturn.RasiEnd = pReturn.RasiStart + AstroConsts.RasiLength;
            }
            return(pReturn);
        }
Ejemplo n.º 5
0
        private bool PanchangaCalculation(double[] cusps, AstroPlanet pReturn, AstroPlanet curSun, double orgSunLong, double orgMoonLong)
        {
            Mod mod360 = new Mod(360);

            if (ThithiEndDateTime == null)
            {
                ThithiEndTime(cusps, curSun, orgSunLong, orgMoonLong, mod360);
            }
            if (YogaEndDateTime == null)
            {
                YogaEndTime(cusps, curSun, orgSunLong, orgMoonLong, mod360);
            }
            if (KarnaEndDateTime == null)
            {
                KarnaEndTime(cusps, curSun, orgSunLong, orgMoonLong, mod360);
            }
            if (NakathEndDateTime == null)
            {
                NakathEndTime(cusps, orgMoonLong);
            }

            return(NakathEndDateTime != null && KarnaEndDateTime != null && YogaEndDateTime != null && ThithiEndDateTime != null);
        }
Ejemplo n.º 6
0
 private bool LoopSkipLogic(int planet, AstroPlanet pReturn, bool IsPachangaCalculated, DateTime birthDateTime)
 {
     if (planet == SwissEph.SE_EARTH ||
         planet == SwissEph.SE_MEAN_NODE || planet == SwissEph.SE_MEAN_APOG ||
         planet == SwissEph.SE_OSCU_APOG || planet == SwissEph.SE_CHIRON)
     {
         return(true);
     }
     if (pReturn != null)
     {
         if (pReturn.Current == EnumPlanet.Moon || pReturn.Current == EnumPlanet.Sun)
         {
             if (pReturn.NextTransitDateTime > birthDateTime && IsPachangaCalculated)
             {
                 return(true);
             }
         }
         else if (pReturn.NextTransitDateTime > birthDateTime)
         {
             return(true);// transit is already captured for this planet, so no need to run this loop
         }
     }
     return(false);
 }
Ejemplo n.º 7
0
        public List <AstroPlanet> CalculatePlanetPositionWithDetailsForAsync()
        {
            List <AstroPlanet> planets = new List <AstroPlanet>();

            NakathEndDateTime = null;
            double[] cusps = new double[6];
            string   serr  = "";
            long     iflgret;
            int      planet;

            swissEph.swe_set_ephe_path(null);
            DateTime dt    = new DateTime(Year, Month, Day, Hour, Minute, Second);
            TimeData tData = new TimeData(dt.ToUniversalTime());

            /*
             * a loop over all planets
             */
            for (planet = SwissEph.SE_SUN; planet <= SwissEph.SE_CHIRON; planet++)
            {
                tjd_ut = tData.JulianDateTime;
                cusps  = new double[6];
                double x2RasiStart = 0.0;
                double x2RasiEnd   = 0.0;
                double x2NakathEnd = 0.0;
                if (planet == SwissEph.SE_EARTH ||
                    planet == SwissEph.SE_MEAN_NODE || planet == SwissEph.SE_MEAN_APOG ||
                    planet == SwissEph.SE_OSCU_APOG || planet == SwissEph.SE_CHIRON)
                {
                    continue;
                }

                /*
                 * do the coordinate calculation for this planet p
                 */
                swissEph.swe_set_sid_mode(SwissEphNet.SwissEph.SE_SIDM_LAHIRI, 0, 0);
                bool        shouldAdd         = true;
                bool        transitIsCaptured = false;
                AstroPlanet pReturn           = null;
                // Looping to find the next transit time/ reversing time of the planet body
                while (true)
                {
                    DateTime nowDate = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone);
                    if (nowDate.Subtract(dt).TotalDays > 365)
                    {
                        break;
                    }
                    iflgret = swissEph.swe_calc_ut(tjd_ut, planet, AstroConsts.iflag, cusps, ref serr);
                    // Longitude
                    // Latitude
                    // Distance in AU
                    // Speed in longitude(deg / day)
                    // Speed in latitude(deg / day)
                    // Speed in distance(AU / day)
                    if (shouldAdd)
                    {
                        shouldAdd = false;
                        pReturn   = new AstroPlanet(planet, cusps, LocationData);

                        /*
                         * if there is a problem, a negative value is returned and an
                         * error message is in serr.
                         */
                        if (iflgret < 0)
                        {
                            pReturn.CalculationError = serr;
                        }

                        /*
                         * get the name of the planet p
                         */
                        pReturn.Name = swissEph.swe_get_planet_name(planet);
                        planets.Add(pReturn);
                        // Add Ketu
                        if (planet == SwissEph.SE_TRUE_NODE)
                        {
                            pReturn.Name = "Rahu";
                            cusps[0]     = (cusps[0] + 180.00) % 360;
                            AstroPlanet ketu = new AstroPlanet(12, cusps, LocationData);
                            ketu.Name = "Kethu";
                            planets.Add(ketu);
                        }
                        x2RasiStart = Math.Truncate(cusps[0] / AstroConsts.RasiLength) * AstroConsts.RasiLength;
                        x2RasiEnd   = x2RasiStart + AstroConsts.RasiLength;
                        // Adjust the loop ending logic to include Nakath end degree
                        // This way we can find the NakathEndTime too
                        if (x2NakathEnd == 0.0 && pReturn.Current == EnumPlanet.Moon)
                        {
                            x2NakathEnd = Math.Truncate(cusps[0] / AstroConsts.NakLength) * AstroConsts.NakLength + AstroConsts.NakLength;
                        }
                    }
                    else if (x2RasiStart < cusps[0] && cusps[0] < x2RasiEnd)
                    {
                        // Planet Reversing related Calculation
                        if (pReturn.IsReversing && cusps[3] >= 0 && !pReturn.IsNode() && pReturn.ReversingEndAt == null)
                        {
                            pReturn.ReversingEndAt = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone);
                            pReturn.IsNivrutha     = true;
                        }
                        else if (!pReturn.IsReversing && cusps[3] <= 0 && !pReturn.IsNode() && pReturn.ReversingStartingAt == null)
                        {
                            pReturn.ReversingStartingAt = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone);
                            pReturn.IsNivrutha          = false;
                        }

                        // When Nakath ends before the rasi ends
                        if (pReturn.Current == EnumPlanet.Moon && NakathEndDateTime == null && x2NakathEnd < cusps[0])
                        {
                            // Adjustment for actual Nakath End Time
                            double nakTimeDif = ((cusps[0] - x2NakathEnd) / ((cusps[3] == 0) ? 1 : cusps[3])) * 1440 * -1;
                            NakathEndDateTime = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone).AddMinutes(nakTimeDif);
                        }

                        // Optimization for NextTransitTime Calculation
                        double degreeToGo = (!transitIsCaptured) ?
                                            Math.Truncate(cusps[0] / AstroConsts.RasiLength) * AstroConsts.RasiLength + AstroConsts.RasiLength - cusps[0]
                            : x2RasiEnd - cusps[0];
                        int    daysToGo  = (int)(degreeToGo / ((cusps[3] == 0) ? 1 : cusps[3]));
                        double hoursToGo = degreeToGo * 24 / ((cusps[3] == 0) ? 1 : cusps[3]);
                        if ((0.001 > cusps[3]) && (-0.001 < cusps[3]))
                        {
                            tjd_ut += 1.0 / 1440.0;
                        }
                        else if ((daysToGo > 2) || (daysToGo < -2))
                        {
                            tjd_ut += 1;
                        }
                        else if ((hoursToGo > 2) || (hoursToGo < -2))
                        {
                            tjd_ut += 60.0 / 1440.0;
                        }
                        else
                        {
                            tjd_ut += 1.0 / 1440.0;
                        }
                    }
                    else if (pReturn != null && !transitIsCaptured)
                    {
                        // TODO: One time sun speed was 0 and made the adjustment as I didn't have internet
                        // Need to check it again to find out whether the 1 is a viable alternative here
                        double rasiTimeDif = ((cusps[0] - x2RasiEnd) / ((cusps[3] == 0) ? 1 : cusps[3])) * 1440 * -1;
                        pReturn.NextTransitDateTime = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone).AddMinutes(rasiTimeDif);
                        transitIsCaptured           = true;
                        if (pReturn.Current == EnumPlanet.Moon && x2RasiEnd < x2NakathEnd)
                        {
                            x2RasiEnd = x2NakathEnd + 0.001; // Adustment to get it hit the internal logic
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(planets);
        }
Ejemplo n.º 8
0
        public List <AstroPlanet> CalculatePlanetPositionWithDetailsOptmized()
        {
            List <AstroPlanet> planets = new List <AstroPlanet>();

            NakathEndDateTime = null;
            double[] cusps         = new double[6];
            double   moonOrbPeriod = 27.321661;
            string   serr          = "";
            long     iflgret;
            int      planet;

            swissEph.swe_set_ephe_path(null);

            DateTime dt    = new DateTime(Year, Month, Day, Hour, Minute, Second);
            TimeData tData = new TimeData(AstroPlace.GetUniversalTime(dt, LocationData.Longitude));

            tjd_ut = tData.JulianDateTime;

            swissEph.swe_set_sid_mode(SwissEphNet.SwissEph.SE_SIDM_LAHIRI, 0, 0);

            cusps = new double[6];
            AstroPlanet ketu = null;

            bool   IsPachangaCalculated = false;
            double orgSunLong           = 0.0;
            double orgMoonLong          = 0.0;

            while (true)
            {
                if (planets.Count > 11 && planets.All(a => a.NextTransitDateTime > dt))
                {
                    return(planets);
                }
                AstroPlanet pReturn = null;
                AstroPlanet curSun  = null;
                for (planet = SwissEph.SE_SUN; planet <= SwissEph.SE_CHIRON; planet++)
                {
                    pReturn = planets.FirstOrDefault(x => x.CurrentInt == planet);
                    if (LoopSkipLogic(planet, pReturn, IsPachangaCalculated, dt))
                    {
                        continue;
                    }

                    iflgret = swissEph.swe_calc_ut(tjd_ut, planet, AstroConsts.iflag, cusps, ref serr);
                    if (iflgret < 0)
                    {
                        pReturn.CalculationError = serr;
                    }
                    // Longitude
                    // Latitude
                    // Distance in AU
                    // Speed in longitude(deg / day)
                    // Speed in latitude(deg / day)
                    // Speed in distance(AU / day)
                    if (pReturn == null)
                    {
                        pReturn = Initialization(planets, cusps, planet, ref ketu, ref orgSunLong, ref orgMoonLong);
                    }

                    if (pReturn.RasiStart < cusps[0] && cusps[0] < pReturn.RasiEnd)
                    {
                        // Planet Reversing related Calculation
                        if (pReturn.IsReversing && cusps[3] >= 0 && !pReturn.IsNode() && pReturn.ReversingEndAt == null)
                        {
                            pReturn.ReversingEndAt = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone);
                            pReturn.IsNivrutha     = true;
                        }
                        else if (!pReturn.IsReversing && cusps[3] <= 0 && !pReturn.IsNode() && pReturn.ReversingStartingAt == null)
                        {
                            pReturn.ReversingStartingAt = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone);
                            pReturn.IsNivrutha          = false;
                        }
                    }
                    else if ((pReturn != null) && !(pReturn.NextTransitDateTime > dt))
                    {
                        Mod mod360 = new Mod(360);
                        // TODO: One time sun speed was 0 and made the adjustment as I didn't have internet
                        // Need to check it again to find out whether the 1 is a viable alternative here

                        double rasiTimeDif = (((Math.Abs(mod360.sub(pReturn.RasiEnd, cusps[0])) < Math.Abs(mod360.sub(cusps[0], pReturn.RasiStart)))
                            ? mod360.sub(pReturn.RasiStart, cusps[0]) : mod360.sub(cusps[0], pReturn.RasiEnd))
                                              / ((cusps[3] == 0) ? 1 : cusps[3])) * 1440 * -1;
                        pReturn.NextTransitDateTime = TimeData.JulianToDateTime(tjd_ut, LocationData.TimeZone).AddMinutes(rasiTimeDif);
                        if ((pReturn.Current == EnumPlanet.Rahu) && (ketu != null))
                        {
                            ketu.NextTransitDateTime = pReturn.NextTransitDateTime;
                        }
                    }

                    if (pReturn.Current == EnumPlanet.Sun)
                    {
                        curSun = new AstroPlanet(pReturn.Current, pReturn.PlanetLocations, pReturn.Place);
                    }
                    // When Nakath ends before the rasi ends
                    else if (!IsPachangaCalculated && (pReturn.Current == EnumPlanet.Moon))
                    {
                        IsPachangaCalculated = PanchangaCalculation(cusps, pReturn, curSun, orgSunLong, orgMoonLong);
                    }
                }

                double daysToGo = 0.5;

                if (!IsPachangaCalculated)
                {
                    daysToGo = 60.0 / 1440.0;
                }
                else if (planets.Count(x => !(x.Current == EnumPlanet.Uranus || x.Current == EnumPlanet.Neptune || x.Current == EnumPlanet.Pluto) && (x.NextTransitDateTime < dt)) > 0)
                {
                    daysToGo = 0.5;
                }
                else
                {
                    daysToGo = 3.0;
                }

                tjd_ut += daysToGo;
            }
        }
Ejemplo n.º 9
0
        public List <AstroPlanet> CalculatePlanetPosition()
        {
            List <AstroPlanet> planets = new List <AstroPlanet>();

            NakathEndDateTime = null;
            double[] cusps = new double[6];
            string   serr  = "";
            long     iflgret;
            int      planet;

            swissEph.swe_set_ephe_path(null);

            DateTime dt    = new DateTime(Year, Month, Day, Hour, Minute, Second);
            TimeData tData = new TimeData(AstroPlace.GetUniversalTime(dt, LocationData.Longitude));

            tjd_ut = tData.JulianDateTime;

            /*
             * a loop over all planets
             */
            for (planet = SwissEph.SE_SUN; planet <= SwissEph.SE_CHIRON; planet++)
            {
                tjd_ut = tData.JulianDateTime;
                cusps  = new double[6];
                if (planet == SwissEph.SE_EARTH ||
                    planet == SwissEph.SE_MEAN_NODE || planet == SwissEph.SE_MEAN_APOG ||
                    planet == SwissEph.SE_OSCU_APOG || planet == SwissEph.SE_CHIRON)
                {
                    continue;
                }

                /*
                 * do the coordinate calculation for this planet p
                 */
                swissEph.swe_set_sid_mode(SwissEphNet.SwissEph.SE_SIDM_LAHIRI, 0, 0);
                AstroPlanet pReturn = null;
                // Looping to find the next transit time/ reversing time of the planet body

                iflgret = swissEph.swe_calc_ut(tjd_ut, planet, AstroConsts.iflag, cusps, ref serr);
                // Longitude
                // Latitude
                // Distance in AU
                // Speed in longitude(deg / day)
                // Speed in latitude(deg / day)
                // Speed in distance(AU / day)

                pReturn = new AstroPlanet(planet, cusps, LocationData);

                /*
                 * if there is a problem, a negative value is returned and an
                 * error message is in serr.
                 */
                if (iflgret < 0)
                {
                    pReturn.CalculationError = serr;
                }

                /*
                 * get the name of the planet p
                 */
                pReturn.Name = swissEph.swe_get_planet_name(planet);
                planets.Add(pReturn);
                // Add Ketu
                if (planet == SwissEph.SE_TRUE_NODE)
                {
                    pReturn.Name = "Rahu";
                    cusps[0]     = (cusps[0] + 180.00) % 360;
                    AstroPlanet ketu = new AstroPlanet(12, cusps, LocationData);
                    ketu.Name = "Kethu";
                    planets.Add(ketu);
                }
            }
            return(planets);
        }