Ejemplo n.º 1
0
 public double Forward(double ut, Longitude lonToFind)
 {
     while (true)
     {
         bool      bForwardStart = true, bForwardEnd = true;
         Longitude lStart = GetLongitude(ut, ref bForwardStart);
         Longitude lEnd   = GetLongitude(ut + 1.0, ref bForwardEnd);
         if (bForwardStart == true && bForwardEnd == true)
         {
             if (Transit.CircLonLessThan(lStart, lonToFind) &&
                 Transit.CircLonLessThan(lonToFind, lEnd))
             {
                 //Console.WriteLine("2: (N) +1.0. {0} Curr:{1} Start:{2} End:{3}", b, lonToFind.value, lStart.value, lEnd.value);
                 return(this.BinarySearchNormal(ut, ut + 1.0, lonToFind));
             }
             else
             {
                 //Console.WriteLine("1: (N) +1.0. {0} Find:{1} Start:{2} End:{3}", b, lonToFind.value, lStart.value, lEnd.value);
                 ut += 10.0;
             }
         }
         else if (bForwardStart == false && bForwardEnd == false)
         {
             if (Transit.CircLonLessThan(lEnd, lonToFind) &&
                 Transit.CircLonLessThan(lonToFind, lStart))
             {
                 //Console.WriteLine("2: (R) +1.0. {0} Curr:{1} Start:{2} End:{3}", b, lonToFind.value, lStart.value, lEnd.value);
                 return(this.BinarySearchRetro(ut, ut + 1.0, lonToFind));
             }
             else
             {
                 //Console.WriteLine("1: (R) +1.0. {0} Find:{1} Start:{2} End:{3}", b, lonToFind.value, lStart.value, lEnd.value);
                 ut += 10.0;
             }
         }
         else
         {
             //Console.WriteLine ("Retrograde Cusp date at {0}. Skipping for now.", ut);
             ut += 10.0;
         }
     }
 }
Ejemplo n.º 2
0
        public double FindClosestTransit(double ut, Longitude lonToFind)
        {
            BodyPosition bp = Basics.CalculateSingleBodyPosition(ut, sweph.BodyNameToSweph(b), b, BodyType.Name.Other, this.h);

            while (Transit.CircLonLessThan(bp.longitude, lonToFind))
            {
                //Console.WriteLine("- {0} {1}", bp.longitude.value, lonToFind.value);
                ut++;
                bp = Basics.CalculateSingleBodyPosition(ut, sweph.BodyNameToSweph(b), b, BodyType.Name.Other, this.h);
            }

            while (Transit.CircLonLessThan(lonToFind, bp.longitude))
            {
                //Console.WriteLine("+ {0} {1}", bp.longitude.value, lonToFind.value);
                ut--;
                bp = Basics.CalculateSingleBodyPosition(ut, sweph.BodyNameToSweph(b), b, BodyType.Name.Other, this.h);
            }

            return(ut);
        }
Ejemplo n.º 3
0
        public double gotoNextRetroSolarCusp(double ut)
        {
            return(ut);

#if DND
            Longitude    cusp_start = new Longitude(0);
            Longitude    cusp_end   = new Longitude(0);
            BodyPosition bp_sun     = Basics.CalculateSingleBodyPosition(ut, sweph.BodyNameToSweph(Body.Name.Sun), Body.Name.Sun, BodyType.Name.Other);
            BodyPosition bp_b       = Basics.CalculateSingleBodyPosition(ut, sweph.BodyNameToSweph(b), b, BodyType.Name.Other);
            Longitude    diff       = bp_b.longitude.sub(bp_sun.longitude);
            if (Transit.CircLonLessThan(cusp_start, diff) &&
                Transit.CircLonLessThan(diff, cusp_end))
            {
                return(ut);
            }

            Longitude diffIncrease = diff.sub(cusp_start);
            double    ret          = ut + (diffIncrease.value * 360.0 / 365.2425);
            return(ret);
#endif
        }
Ejemplo n.º 4
0
        public double TransitSearchDirect(Body.Name SearchBody, Moment StartDate,
                                          bool Forward, Longitude TransitPoint, Longitude FoundLon, ref bool bForward)
        {
            bool bDiscard = true;

            sweph.obtainLock(h);
            Transit   t        = new Transit(h, SearchBody);
            double    ut_base  = StartDate.toUniversalTime() - h.info.TimeZone.toDouble() / 24.0;
            Longitude lon_curr = t.GenericLongitude(ut_base, ref bDiscard);

            sweph.releaseLock(h);

            double diff = 0;

            diff = TransitPoint.sub(lon_curr).value;

            if (false == Forward)
            {
                diff -= 360.0;
            }

            double ut_diff_approx = diff / 360.0 * this.DirectSpeed(SearchBody);

            sweph.obtainLock(h);
            double found_ut = 0;

            if (SearchBody == Body.Name.Lagna)
            {
                found_ut = t.LinearSearchBinary(ut_base + ut_diff_approx - 3.0 / 24.0, ut_base + ut_diff_approx + 3.0 / 24.0, TransitPoint, new ReturnLon(t.GenericLongitude));
            }
            else
            {
                found_ut = t.LinearSearch(ut_base + ut_diff_approx, TransitPoint, new ReturnLon(t.GenericLongitude));
            }
            FoundLon.value = t.GenericLongitude(found_ut, ref bForward).value;
            bForward       = true;
            sweph.releaseLock(h);
            return(found_ut);
        }
Ejemplo n.º 5
0
        public double BinarySearchRetro(double ut_start, double ut_end, Longitude lon_to_find)
        {
            if (Math.Abs(ut_end - ut_start) < (1.0 / (24.0 * 60.0 * 60.0 * 60.0)))
            {
                //Console.WriteLine ("BinarySearchRetro: Found {0} at {1}", lon_to_find, ut_start);
                return(ut_start);
            }

            double    ut_middle = (ut_start + ut_end) / 2.0;
            bool      bDiscard  = true;
            Longitude lon       = GetLongitude(ut_middle, ref bDiscard);

            //Console.WriteLine ("BinarySearchRetro {0} Find:{1} {2} curr:{3}", b, lon_to_find.value, ut_middle, lon.value);
            if (Transit.CircLonLessThan(lon, lon_to_find))
            {
                return(BinarySearchRetro(ut_start, ut_middle, lon_to_find));
            }
            else
            {
                return(BinarySearchRetro(ut_middle, ut_end, lon_to_find));
            }
        }
Ejemplo n.º 6
0
 public bool CircularLonLessThan(Longitude a, Longitude b)
 {
     return(Transit.CircLonLessThan(a, b));
 }
Ejemplo n.º 7
0
        private void ComputeEntry(double ut, double[] geopos)
        {
            int    year = 0, month = 0, day = 0;
            double sunset = 0, hour = 0;

            sweph.obtainLock(h);
            h.populateSunrisetCacheHelper(ut - 0.5, ref sunrise, ref sunset, ref ut_sr);
            sweph.releaseLock(h);

            sweph.swe_revjul(ut_sr, ref year, ref month, ref day, ref hour);
            Moment    moment_sr = new Moment(year, month, day, hour);
            Moment    moment_ut = new Moment(ut, h);
            HoraInfo  infoCurr  = new HoraInfo(moment_ut, h.info.lat, h.info.lon, h.info.tz);
            Horoscope hCurr     = new Horoscope(infoCurr, h.options);

            ListViewItem li = null;

            PanchangaLocalMoments local = new PanchangaLocalMoments();

            local.sunrise    = hCurr.sunrise;
            local.sunset     = sunset;
            local.sunrise_ut = ut_sr;
            sweph.swe_revjul(ut, ref year, ref month, ref day, ref hour);
            local.wday = (Basics.Weekday)sweph.swe_day_of_week(ut);



            local.kalas_ut = hCurr.getKalaCuspsUt();
            if (this.opts.CalcSpecialKalas)
            {
                Body.Name bStart = Basics.weekdayRuler(hCurr.wday);
                if (hCurr.options.KalaType == HoroscopeOptions.EHoraType.Lmt)
                {
                    bStart = Basics.weekdayRuler(hCurr.lmt_wday);
                }

                local.rahu_kala_index   = this.rahu_kalas[(int)bStart];
                local.gulika_kala_index = this.gulika_kalas[(int)bStart];
                local.yama_kala_index   = this.yama_kalas[(int)bStart];
            }

            if (opts.CalcLagnaCusps)
            {
                li = new ListViewItem();
                sweph.obtainLock(h);
                BodyPosition     bp_lagna_sr = Basics.CalculateSingleBodyPosition(ut_sr, sweph.BodyNameToSweph(Body.Name.Lagna), Body.Name.Lagna, BodyType.Name.Lagna, h);
                DivisionPosition dp_lagna_sr = bp_lagna_sr.toDivisionPosition(new Division(Basics.DivisionType.Rasi));
                local.lagna_zh = dp_lagna_sr.zodiac_house.value;

                Longitude bp_lagna_base = new Longitude(bp_lagna_sr.longitude.toZodiacHouseBase());
                double    ut_transit    = ut_sr;
                for (int i = 1; i <= 12; i++)
                {
                    Retrogression r = new Retrogression(h, Body.Name.Lagna);
                    ut_transit = r.GetLagnaTransitForward(ut_transit, bp_lagna_base.add(i * 30.0));

                    PanchangaMomentInfo pmi = new PanchangaMomentInfo(
                        ut_transit, (int)bp_lagna_sr.longitude.toZodiacHouse().add(i + 1).value);
                    local.lagnas_ut.Add(pmi);
                }

                sweph.releaseLock(h);
            }

            if (opts.CalcTithiCusps)
            {
                Transit t = new Transit(h);
                sweph.obtainLock(h);
                Tithi tithi_start = t.LongitudeOfTithi(ut_sr).toTithi();
                Tithi tithi_end   = t.LongitudeOfTithi(ut_sr + 1.0).toTithi();

                Tithi tithi_curr = tithi_start.add(1);
                local.tithi_index_start = globals.tithis_ut.Count - 1;
                local.tithi_index_end   = globals.tithis_ut.Count - 1;

                while (tithi_start.value != tithi_end.value &&
                       tithi_curr.value != tithi_end.value)
                {
                    tithi_curr = tithi_curr.add(2);
                    double dLonToFind = ((double)(int)tithi_curr.value - 1) * (360.0 / 30.0);
                    double ut_found   = t.LinearSearchBinary(ut_sr, ut_sr + 1.0, new Longitude(dLonToFind),
                                                             new ReturnLon(t.LongitudeOfTithiDir));

                    globals.tithis_ut.Add(new PanchangaMomentInfo(ut_found, (int)tithi_curr.value));
                    local.tithi_index_end++;
                }
                sweph.releaseLock(h);
            }


            if (opts.CalcKaranaCusps)
            {
                Transit t = new Transit(h);
                sweph.obtainLock(h);
                Karana karana_start = t.LongitudeOfTithi(ut_sr).toKarana();
                Karana karana_end   = t.LongitudeOfTithi(ut_sr + 1.0).toKarana();

                Karana karana_curr = karana_start.add(1);
                local.karana_index_start = globals.karanas_ut.Count - 1;
                local.karana_index_end   = globals.karanas_ut.Count - 1;

                while (karana_start.value != karana_end.value &&
                       karana_curr.value != karana_end.value)
                {
                    karana_curr = karana_curr.add(2);
                    double dLonToFind = ((double)(int)karana_curr.value - 1) * (360.0 / 60.0);
                    double ut_found   = t.LinearSearchBinary(ut_sr, ut_sr + 1.0, new Longitude(dLonToFind),
                                                             new ReturnLon(t.LongitudeOfTithiDir));

                    globals.karanas_ut.Add(new PanchangaMomentInfo(ut_found, (int)karana_curr.value));
                    local.karana_index_end++;
                }
                sweph.releaseLock(h);
            }

            if (opts.CalcSMYogaCusps)
            {
                Transit t = new Transit(h);
                sweph.obtainLock(h);
                SunMoonYoga sm_start = t.LongitudeOfSunMoonYoga(ut_sr).toSunMoonYoga();
                SunMoonYoga sm_end   = t.LongitudeOfSunMoonYoga(ut_sr + 1.0).toSunMoonYoga();

                SunMoonYoga sm_curr = sm_start.add(1);
                local.smyoga_index_start = globals.smyogas_ut.Count - 1;
                local.smyoga_index_end   = globals.smyogas_ut.Count - 1;

                while (sm_start.value != sm_end.value &&
                       sm_curr.value != sm_end.value)
                {
                    sm_curr = sm_curr.add(2);
                    double dLonToFind = ((double)(int)sm_curr.value - 1) * (360.0 / 27);
                    double ut_found   = t.LinearSearchBinary(ut_sr, ut_sr + 1.0, new Longitude(dLonToFind),
                                                             new ReturnLon(t.LongitudeOfSunMoonYogaDir));

                    globals.smyogas_ut.Add(new PanchangaMomentInfo(ut_found, (int)sm_curr.value));
                    local.smyoga_index_end++;
                }

                sweph.releaseLock(h);
            }


            if (opts.CalcNakCusps)
            {
                bool    bDiscard = true;
                Transit t        = new Transit(h, Body.Name.Moon);
                sweph.obtainLock(h);
                Nakshatra nak_start = t.GenericLongitude(ut_sr, ref bDiscard).toNakshatra();
                Nakshatra nak_end   = t.GenericLongitude(ut_sr + 1.0, ref bDiscard).toNakshatra();

                local.nakshatra_index_start = globals.nakshatras_ut.Count - 1;
                local.nakshatra_index_end   = globals.nakshatras_ut.Count - 1;

                Nakshatra nak_curr = nak_start.add(1);

                while (nak_start.value != nak_end.value &&
                       nak_curr.value != nak_end.value)
                {
                    nak_curr = nak_curr.add(2);
                    double dLonToFind = ((double)((int)nak_curr.value - 1)) * (360.0 / 27.0);
                    double ut_found   = t.LinearSearchBinary(ut_sr, ut_sr + 1.0, new Longitude(dLonToFind),
                                                             new ReturnLon(t.GenericLongitude));

                    globals.nakshatras_ut.Add(new PanchangaMomentInfo(ut_found, (int)nak_curr.value));
                    Console.WriteLine("Found nakshatra {0}", nak_curr.value);
                    local.nakshatra_index_end++;
                }
                sweph.releaseLock(h);
            }

            if (opts.CalcHoraCusps)
            {
                local.horas_ut = hCurr.getHoraCuspsUt();
                hCurr.calculateHora(ut_sr + 1.0 / 24.0, ref local.hora_base);
            }

            if (opts.CalcKalaCusps)
            {
                hCurr.calculateKala(ref local.kala_base);
            }


            this.locals.Add(local);
            this.DisplayEntry(local);
        }