Example #1
0
        public double BinarySearchNormal(double ut_start, double ut_end, Longitude lon_to_find)
        {
            bool bDiscard = true;

            if (Math.Abs(ut_end - ut_start) < (1.0 / (24.0 * 60.0 * 60.0 * 60.0)))
            {
                //Console.WriteLine ("BinarySearchNormal: Found {0} at {1}", lon_to_find, ut_start);
                if (Transit.CircLonLessThan(GetLongitude(ut_start, ref bDiscard), lon_to_find))
                {
                    return(ut_end);
                }
                else
                {
                    return(ut_start);
                }
            }

            double ut_middle = (ut_start + ut_end) / 2.0;

            Longitude lon = GetLongitude(ut_middle, ref bDiscard);

            //Console.WriteLine ("BinarySearchNormal {0} Find:{1} {2} curr:{3}", b, lon_to_find.value, ut_middle, lon.value);
            if (Transit.CircLonLessThan(lon, lon_to_find))
            {
                return(BinarySearchNormal(ut_middle, ut_end, lon_to_find));
            }
            else
            {
                return(BinarySearchNormal(ut_start, ut_middle, lon_to_find));
            }
        }
Example #2
0
        public double LinearSearchBinary(double ut_start, double ut_end, Longitude lon_to_find, ReturnLon func)
        {
            bool bDiscard = true;

            if (Math.Abs(ut_end - ut_start) < (1.0 / (24.0 * 60.0 * 60.0 * 60.0)))
            {
                if (Transit.CircLonLessThan(func(ut_start, ref bDiscard), lon_to_find))
                {
                    return(ut_end);
                }
                return(ut_start);
            }

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

            if (this.CircularLonLessThan(lon, lon_to_find))
            {
                return(LinearSearchBinary(ut_middle, ut_end, lon_to_find, func));
            }
            else
            {
                return(LinearSearchBinary(ut_start, ut_middle, lon_to_find, func));
            }
        }
Example #3
0
        public double BinaryLonSearch(double ut_start, double ut_end, Longitude lon_to_find, bool normal)
        {
            if (Math.Abs(ut_end - ut_start) < (1.0 / (24.0 * 60.0 * 60.0 * 60.0 * 60.0)))
            {
                if (Transit.CircLonLessThan(GetLon(ut_start), lon_to_find))
                {
                    if (normal)
                    {
                        return(ut_end);
                    }
                    else
                    {
                        return(ut_start);
                    }
                }
                else
                {
                    if (normal)
                    {
                        return(ut_start);
                    }
                    else
                    {
                        return(ut_end);
                    }
                }
            }

            double ut_middle = (ut_start + ut_end) / 2.0;

            Longitude lon_start  = GetLon(ut_start);
            Longitude lon_middle = GetLon(ut_middle);
            Longitude lon_end    = GetLon(ut_end);

            if (normal)
            {
                if (lon_to_find.sub(lon_start).value <= lon_middle.sub(lon_start).value)
                {
                    return(BinaryLonSearch(ut_start, ut_middle, lon_to_find, normal));
                }
                else
                {
                    return(BinaryLonSearch(ut_middle, ut_end, lon_to_find, normal));
                }
            }
            else
            {
                if (lon_to_find.sub(lon_end).value <= lon_middle.sub(lon_end).value)
                {
                    return(BinaryLonSearch(ut_middle, ut_end, lon_to_find, normal));
                }
                else
                {
                    return(BinaryLonSearch(ut_start, ut_middle, lon_to_find, normal));
                }
            }
        }
Example #4
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;
         }
     }
 }
Example #5
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);
        }
Example #6
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
        }
Example #7
0
 public bool CircularLonLessThan(Longitude a, Longitude b)
 {
     return(Transit.CircLonLessThan(a, b));
 }