Exemplo n.º 1
0
        /*********************************************************************/
        /*                                                                   */
        /*  m1 - previous moon position                                      */
        /*  m2 - next moon position                                          */
        /*  s1 - previous sun position                                       */
        /*  s2 - next sun position                                           */
        /*                                                                   */
        /*  Test for conjunction of the sun and moon                         */
        /*  m1,s1 is in one time moment                                      */
        /*  m2,s2 is in second time moment                                   */
        /*                                                                   */
        /*  this function tests whether conjunction occurs between           */
        /*  these two moments                                                */
        /*                                                                   */
        /*********************************************************************/

        public static bool IsConjunction(double m1, double s1, double s2, double m2)
        {
            if (m2 < m1)
            {
                m2 += 360.0;
            }
            if (s2 < s1)
            {
                s2 += 360.0;
            }
            if ((m1 <= s1) && (s1 < s2) && (s2 <= m2))
            {
                return(true);
            }

            m1 = GCMath.putIn180(m1);
            m2 = GCMath.putIn180(m2);
            s1 = GCMath.putIn180(s1);
            s2 = GCMath.putIn180(s2);

            if ((m1 <= s1) && (s1 < s2) && (s2 <= m2))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public string ShortTimeString()
        {
            int h, m;

            GCMath.DaytimeToHourMin(shour, out h, out m);
            return(string.Format("{0:00}:{1:00}", h, m));
        }
Exemplo n.º 3
0
        public double GetPlanetHouse(double longitudeTropical, double julianDate, GCEarthData earth)
        {
            double longitudeSidereal = longitudeTropical - GCAyanamsha.GetAyanamsa(julianDate);
            double firstHouseStart   = earth.GetAscendantDegrees(julianDate) - 15.0;

            return(GCMath.putIn360(longitudeSidereal - firstHouseStart) / 30.0);
        }
Exemplo n.º 4
0
        public GCEquatorialCoords getTopocentricEquatorial(GCEarthData obs, double jdate)
        {
            double             u, h, delta_alpha;
            double             rho_sin, rho_cos;
            const double       b_a = 0.99664719;
            GCEquatorialCoords tec = new GCEquatorialCoords();

            double altitude = 0;

            // geocentric position of observer on the earth surface
            // 10.1 - 10.3
            u       = GCMath.arcTanDeg(b_a * b_a * GCMath.tanDeg(obs.latitudeDeg));
            rho_sin = b_a * GCMath.sinDeg(u) + altitude / 6378140.0 * GCMath.sinDeg(obs.latitudeDeg);
            rho_cos = GCMath.cosDeg(u) + altitude / 6378140.0 * GCMath.cosDeg(obs.latitudeDeg);

            // equatorial horizontal paralax
            // 39.1
            double parallax = GCMath.arcSinDeg(GCMath.sinDeg(8.794 / 3600) / (radius / GCMath.AU));

            // geocentric hour angle of the body
            h = GCEarthData.SiderealTimeGreenwich(jdate) + obs.longitudeDeg - rightAscension;


            // 39.2
            delta_alpha = GCMath.arcTanDeg(
                (-rho_cos * GCMath.sinDeg(parallax) * GCMath.sinDeg(h)) /
                (GCMath.cosDeg(this.declination) - rho_cos * GCMath.sinDeg(parallax) * GCMath.cosDeg(h)));
            tec.rightAscension = rightAscension + delta_alpha;
            tec.declination    = declination + GCMath.arcTanDeg(
                ((GCMath.sinDeg(declination) - rho_sin * GCMath.sinDeg(parallax)) * GCMath.cosDeg(delta_alpha)) /
                (GCMath.cosDeg(declination) - rho_cos * GCMath.sinDeg(parallax) * GCMath.cosDeg(h)));

            return(tec);
        }
Exemplo n.º 5
0
        public string LongTimeString()
        {
            int h, m, s;

            GCMath.DaytimeToHourMin(shour, out h, out m, out s);
            return(string.Format("{0:00}:{1:00}:{2:00}", h, m, s));
        }
Exemplo n.º 6
0
        ////////////////////////////////////////////////////////////////
        //
        //  Conversion time from DEGREE fromat to H:M:S:MS format
        //
        //  time - output
        //  time_deg - input time in range 0 deg to 360 deg
        //             where 0 deg = 0:00 AM and 360 deg = 12:00 PM
        //
        public void SetDegTime(double time_deg)
        {
            double time_hr = 0.0;

            time_deg = GCMath.putIn360(time_deg);

            // hour
            time_hr = time_deg / 360 * 24;
            hour    = Convert.ToInt32(Math.Floor(time_hr));

            // minute
            time_hr -= hour;
            time_hr *= 60;
            min      = Convert.ToInt32(Math.Floor(time_hr));

            // second
            time_hr -= min;
            time_hr *= 60;
            sec      = Convert.ToInt32(Math.Floor(time_hr));

            // miliseconds
            time_hr -= sec;
            time_hr *= 1000;
            mili     = Convert.ToInt32(Math.Floor(time_hr));
        }
Exemplo n.º 7
0
        public static int GetNextYogaStart(GCEarthData ed, GregorianDateTime startDate, out GregorianDateTime nextDate)
        {
            double            phi = 40.0 / 3.0;
            double            l1, l2, longitudeSun;
            double            jday = startDate.GetJulianComplete();
            double            xj;
            double            longitudeMoon;
            GregorianDateTime d = new GregorianDateTime();

            d.Set(startDate);
            GregorianDateTime xd        = new GregorianDateTime();
            double            scan_step = 0.5;
            int    prev_tit             = 0;
            int    new_tit   = -1;
            double ayanamsha = GCAyanamsha.GetAyanamsa(jday);

            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
            longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
            l1            = GCMath.putIn360(longitudeMoon + longitudeSun - 2 * ayanamsha);
            prev_tit      = Convert.ToInt32(Math.Floor(l1 / phi));

            int counter = 0;

            while (counter < 20)
            {
                xj = jday;
                xd.Set(d);

                jday    += scan_step;
                d.shour += scan_step;
                if (d.shour > 1.0)
                {
                    d.shour -= 1.0;
                    d.NextDay();
                }

                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
                longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
                l2            = GCMath.putIn360(longitudeMoon + longitudeSun - 2 * ayanamsha);
                new_tit       = Convert.ToInt32(Math.Floor(l2 / phi));

                if (prev_tit != new_tit)
                {
                    jday = xj;
                    d.Set(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }
            nextDate = d;

            return(new_tit);
        }
Exemplo n.º 8
0
 public void SetCoordinates(double longitude, double latitude)
 {
     Longitude = longitude;
     Latitude  = latitude;
     if (TimeZone != null)
     {
         TimeZone.OffsetMinutes = GCMath.IntFloor((longitude - 7.5) / 15) * 60;
     }
 }
Exemplo n.º 9
0
        /*********************************************************************/
        /*                                                                   */
        /*   finds previous time when starts next tithi                      */
        /*                                                                   */
        /*   timezone is not changed                                         */
        /*                                                                   */
        /*   return value: index of tithi 0..29                              */
        /*                 or -1 if failed                                   */
        /*********************************************************************/

        public static int GetPrevTithiStart(GCEarthData ed, GregorianDateTime startDate, out GregorianDateTime nextDate)
        {
            double            phi = 12.0;
            double            l1, l2, longitudeSun, longitudeMoon;
            double            jday = startDate.GetJulianComplete();
            double            xj;
            GregorianDateTime d = new GregorianDateTime();

            d.Set(startDate);
            GregorianDateTime xd        = new GregorianDateTime();
            double            scan_step = 0.5;
            int prev_tit = 0;
            int new_tit  = -1;

            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
            longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
            l1            = GCMath.putIn360(longitudeMoon - longitudeSun - 180.0);
            prev_tit      = GCMath.IntFloor(l1 / phi);

            int counter = 0;

            while (counter < 20)
            {
                xj = jday;
                xd.Set(d);

                jday    -= scan_step;
                d.shour -= scan_step;
                if (d.shour < 0.0)
                {
                    d.shour += 1.0;
                    d.PreviousDay();
                }

                longitudeSun  = GCCoreAstronomy.GetSunLongitude(d, ed);
                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
                l2            = GCMath.putIn360(longitudeMoon - longitudeSun - 180.0);
                new_tit       = GCMath.IntFloor(l2 / phi);

                if (prev_tit != new_tit)
                {
                    jday = xj;
                    d.Set(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }
            nextDate = d;
            //	nextDate.shour += startDate.tzone / 24.0;
            //	nextDate.NormalizeValues();
            return(new_tit);
        }
Exemplo n.º 10
0
        public static int GetNextMoonRasi(GCEarthData ed, GregorianDateTime startDate, out GregorianDateTime nextDate)
        {
            double            phi = 30.0;
            double            l1, l2, longitudeMoon;
            double            jday = startDate.GetJulianComplete();
            GregorianDateTime d    = new GregorianDateTime();

            d.Set(startDate);
            double ayanamsa  = GCAyanamsha.GetAyanamsa(jday);
            double scan_step = 0.5;
            int    prev_naks = 0;
            int    new_naks  = -1;

            double            xj;
            GregorianDateTime xd = new GregorianDateTime();

            longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
            l1            = GCMath.putIn360(longitudeMoon - ayanamsa);
            prev_naks     = GCMath.IntFloor(l1 / phi);

            int counter = 0;

            while (counter < 20)
            {
                xj = jday;
                xd.Set(d);

                jday    += scan_step;
                d.shour += scan_step;
                if (d.shour > 1.0)
                {
                    d.shour -= 1.0;
                    d.NextDay();
                }

                longitudeMoon = GCCoreAstronomy.GetMoonLongitude(d, ed);
                l2            = GCMath.putIn360(longitudeMoon - ayanamsa);
                new_naks      = GCMath.IntFloor(l2 / phi);
                if (prev_naks != new_naks)
                {
                    jday = xj;
                    d.Set(xd);
                    scan_step *= 0.5;
                    counter++;
                    continue;
                }
                else
                {
                    l1 = l2;
                }
            }
            nextDate = new GregorianDateTime();
            nextDate.Set(d);
            return(new_naks);
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="julianDateUTC">Time in UT1 or for general use UTC. This should reflect also hours, minutes and seconds. When finding local sidereal time,
        /// this argument should contains time that is observed on Greenwich meridian. Use function GetJulianDetailed or GetGreenwichDateTime</param>
        /// <param name="longitudeDegrees"></param>
        /// <returns></returns>
        public static double SiderealTimeLocal(double julianDateUTC, double longitudeDegrees, double timezoneDegrees)
        {
            double julianDate2000, julianMillenium;
            double delta_phi = 0.0, epsilon = 0.0;

            julianDate2000  = julianDateUTC - 2451545.0;
            julianMillenium = julianDate2000 / 36525.0;
            GCEarthData.CalculateNutations(julianDateUTC, out delta_phi, out epsilon);
            return(GCMath.putIn360(280.46061837 + 360.98564736629 * julianDate2000 +
                                   julianMillenium * julianMillenium * (0.000387933 - julianMillenium / 38710000) +
                                   delta_phi * GCMath.cosDeg(epsilon) + longitudeDegrees - timezoneDegrees));
        }
Exemplo n.º 12
0
        public static double SiderealTimeGreenwich(double date)
        {
            double jd, t;
            double delta_phi = 0.0, epsilon = 0.0;

            jd = date;
            t  = (jd - 2451545.0) / 36525.0;
            GCEarthData.CalculateNutations(date, out delta_phi, out epsilon);
            return(GCMath.putIn360(280.46061837 + 360.98564736629 * (jd - 2451545.0) +
                                   t * t * (0.000387933 - t / 38710000) +
                                   delta_phi * GCMath.cosDeg(epsilon)));
        }
Exemplo n.º 13
0
        public static string GetTextLongitude(double d)
        {
            int  a0, a1;
            char c0;

            c0 = d < 0.0 ? 'W' : 'E';
            d  = Math.Abs(d);
            a0 = GCMath.IntFloor(d);
            a1 = GCMath.IntFloor((d - a0) * 60 + 0.5);

            return(string.Format("{0}{1}{2:00}", a0, c0, a1));
        }
Exemplo n.º 14
0
        public static GCHourTime CalcSunrise(GregorianDateTime vct, GCEarthData earth)
        {
            double    tempSunrise = 180.0;
            GCSunData sun         = new GCSunData();

            for (int i = 0; i < 3; i++)
            {
                sun.SunPosition(vct, earth, tempSunrise - 180.0);

                double x;
                // definition of event
                double eventdef = 0.01454;

                /*	switch(ed.obs)
                 *  {
                 *  case 1:	// civil twilight
                 *      eventdef = 0.10453;
                 *      break;
                 *  case 2:	// nautical twilight
                 *      eventdef = 0.20791;
                 *      break;
                 *  case 3:	// astronomical twilight
                 *      eventdef = 0.30902;
                 *      break;
                 *  default:// center of the sun on the horizont
                 *      eventdef = 0.01454;
                 *      break;
                 *  }*/

                eventdef = (eventdef / GCMath.cosDeg(earth.latitudeDeg)) / GCMath.cosDeg(sun.declinationDeg);

                x = GCMath.tanDeg(earth.latitudeDeg) * GCMath.tanDeg(sun.declinationDeg) + eventdef;

                if ((x >= -1.0) && (x <= 1.0))
                {
                    // time of sunrise
                    tempSunrise = 90.0 - earth.longitudeDeg - GCMath.arcSinDeg(x) + sun.equationOfTime;
                }
                else
                {
                    // initial values for the case
                    // that no rise no set for that day
                    tempSunrise = -360.0;
                    break;
                }
            }

            GCHourTime result = new GCHourTime();

            result.longitude = sun.longitudeDeg;
            result.SetDegTime(tempSunrise + earth.OffsetUtcHours * 15.0);
            return(result);
        }
Exemplo n.º 15
0
        //==================================================================================
        //
        //==================================================================================



        public void calc_horizontal(double date, double longitude, double latitude)
        {
            double h;

            h = GCMath.putIn360(GCEarthData.SiderealTimeGreenwich(date) - this.rightAscension + longitude);

            this.azimuth = GCMath.rad2deg(Math.Atan2(GCMath.sinDeg(h),
                                                     GCMath.cosDeg(h) * GCMath.sinDeg(latitude) -
                                                     GCMath.tanDeg(this.declination) * GCMath.cosDeg(latitude)));

            this.elevation = GCMath.rad2deg(Math.Asin(GCMath.sinDeg(latitude) * GCMath.sinDeg(this.declination) +
                                                      GCMath.cosDeg(latitude) * GCMath.cosDeg(this.declination) * GCMath.cosDeg(h)));
        }
Exemplo n.º 16
0
        public static double MoonDistance(double jdate)
        {
            double temp, t, d, m, ms, f, e, ls, sr;// : extended;

            t = (jdate - 2451545.0) / 36525.0;

            //(* mean elongation of the moon
            d = 297.8502042 + (445267.1115168 + (-0.0016300 + (1.0 / 545868 - 1.0 / 113065000 * t) * t) * t) * t;

            //(* mean anomaly of the sun
            m = 357.5291092 + (35999.0502909 + (-0.0001536 + 1.0 / 24490000 * t) * t) * t;

            //(* mean anomaly of the moon
            ms = 134.9634114 + (477198.8676313 + (0.0089970 + (1.0 / 69699 - 1.0 / 1471200 * t) * t) * t) * t;

            //(* argument of the longitude of the moon
            f = 93.2720993 + (483202.0175273 + (-0.0034029 + (-1.0 / 3526000 + 1.0 / 863310000 * t) * t) * t) * t;

            //(* correction term due to excentricity of the earth orbit
            e = 1.0 + (-0.002516 - 0.0000074 * t) * t;

            //(* mean longitude of the moon
            ls = 218.3164591 + (481267.88134236 + (-0.0013268 + (1.0 / 538841 - 1.0 / 65194000 * t) * t) * t) * t;

            sr = 0;

            int i;

            for (i = 0; i < 60; i++)
            {
                temp = sigma_r[i] * GCMath.cosDeg(arg_lr[i, 0] * d
                                                  + arg_lr[i, 1] * m
                                                  + arg_lr[i, 2] * ms
                                                  + arg_lr[i, 3] * f);
                if (Math.Abs(arg_lr[i, 1]) == 1)
                {
                    temp = temp * e;
                }
                if (Math.Abs(arg_lr[i, 1]) == 2)
                {
                    temp = temp * e * e;
                }
                sr = sr + temp;
            }


            return(385000.56 + sr / 1000);
        }
Exemplo n.º 17
0
        public static GCHorizontalCoords equatorialToHorizontalCoords(GCEquatorialCoords eqc, GCEarthData obs, double date)
        {
            double             localHourAngle;
            GCHorizontalCoords hc;

            localHourAngle = GCMath.putIn360(GCEarthData.SiderealTimeGreenwich(date) - eqc.rightAscension + obs.longitudeDeg);

            hc.azimut = GCMath.rad2deg(Math.Atan2(GCMath.sinDeg(localHourAngle),
                                                  GCMath.cosDeg(localHourAngle) * GCMath.sinDeg(obs.latitudeDeg) -
                                                  GCMath.tanDeg(eqc.declination) * GCMath.cosDeg(obs.latitudeDeg)));

            hc.elevation = GCMath.rad2deg(Math.Asin(GCMath.sinDeg(obs.latitudeDeg) * GCMath.sinDeg(eqc.declination) +
                                                    GCMath.cosDeg(obs.latitudeDeg) * GCMath.cosDeg(eqc.declination) * GCMath.cosDeg(localHourAngle)));

            return(hc);
        }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="julianDateUTC">This contains time UTC, that means time observed on Greenwich meridian. DateTime in other
        /// timezones should be converted into timezone UTC+0h before using in this method.</param>
        /// <returns></returns>
        public double GetAscendantDegrees(double julianDateUTC)
        {
            double A         = GCEarthData.SiderealTimeLocal(julianDateUTC, longitudeDeg, OffsetUtcHours * 15.0);
            double E         = 23.4392911;
            double ascendant = GCMath.arcTan2Deg(-GCMath.cosDeg(A), GCMath.sinDeg(A) * GCMath.cosDeg(E) + GCMath.tanDeg(latitudeDeg) * GCMath.sinDeg(E));

            if (ascendant < 180)
            {
                ascendant += 180;
            }
            else
            {
                ascendant -= 180;
            }
            return(GCMath.putIn360(ascendant - GCAyanamsha.GetAyanamsa(julianDateUTC)));
        }
Exemplo n.º 19
0
        private void CalculatePlanetRasi(int bodyId, GCLocation loc, GregorianDateTime vcEnd, GregorianDateTime vcAdd, GCConfigRatedEvents rec)
        {
            int    nData;
            double JD, JDE;

            JD    = vcAdd.GetJulian() - 0.5 - loc.OffsetUtcHours / 24.0;
            JDE   = vcEnd.GetJulian() + 0.5 - loc.OffsetUtcHours / 24.0;
            nData = GCMath.IntFloor(GCMath.putIn360(GCVSOPAstronomy.GetPlanetLongitude(bodyId, JD) - GCAyanamsha.GetAyanamsa(JD)) / 30.0);

            // initial rasi at the start date 00:00
            AddRating(JD, loc, rec.rateGrahaRasi[bodyId, nData], rec.rateGrahaRasi[bodyId, Prev(nData, 12)]);

            while ((JD = FindNextRasiChange(JD, JDE, bodyId, out nData)) < JDE)
            {
                AddRating(JD, loc, rec.rateGrahaRasi[bodyId, nData], rec.rateGrahaRasi[bodyId, Prev(nData, 12)]);
                JD += 1.0;
            }
        }
Exemplo n.º 20
0
        /*********************************************************************/
        /*  Finds next time when rasi is changed                             */
        /*                                                                   */
        /*  startDate - starting date and time, timezone member must be valid */
        /*  zodiac [out] - found zodiac sign into which is changed           */
        /*                                                                   */
        /*********************************************************************/

        public static GregorianDateTime GetNextSankranti(GregorianDateTime startDate, GCEarthData earth, out int zodiac)
        {
            GregorianDateTime d = new GregorianDateTime();
            double            step = 1.0;
            int               count = 0;
            double            ld, prev;
            int               prev_rasi, new_rasi;
            GregorianDateTime prevday;

            d.Set(startDate);
            //d.ChangeTimeZone(0.0);
            //d.shour = 0.0;
            zodiac = 0;

            prev      = GCMath.putIn360(GCCoreAstronomy.GetSunLongitude(d, earth) - GCAyanamsha.GetAyanamsa(d.GetJulian()));
            prev_rasi = GCMath.IntFloor(prev / 30.0);

            while (count < 20)
            {
                prevday = new GregorianDateTime();
                prevday.Set(d);
                d.shour += step;
                if (d.shour > 1.0)
                {
                    d.shour -= 1.0;
                    d.NextDay();
                }

                ld       = GCMath.putIn360(GCCoreAstronomy.GetSunLongitude(d, earth) - GCAyanamsha.GetAyanamsa(d.GetJulian()));
                new_rasi = GCMath.IntFloor(ld / 30.0);

                if (prev_rasi != new_rasi)
                {
                    zodiac = new_rasi;
                    //v uplynulom dni je sankranti
                    step *= 0.5;
                    d.Set(prevday);
                    count++;
                    continue;
                }
            }

            return(d);
        }
Exemplo n.º 21
0
        private void CalculatePlanetHouse(int bodyId, GCLocation loc, GregorianDateTime vcEnd, GregorianDateTime vcAdd, GCConfigRatedEvents rec)
        {
            int         nData;
            double      JD, JDE;
            GCEarthData earth = loc.GetEarthData();

            JD  = vcAdd.GetJulian() - 0.5 - loc.OffsetUtcHours / 24.0;
            JDE = vcEnd.GetJulian() + 0.5 - loc.OffsetUtcHours / 24.0;

            // initial rasi at the start date 00:00
            nData = GCMath.IntFloor(GetPlanetHouse(GCVSOPAstronomy.GetPlanetLongitude(bodyId, JD), JD, earth));
            AddRating(JD, loc, rec.rateGrahaHouse[bodyId, nData], rec.rateGrahaHouse[bodyId, Prev(nData, 12)]);

            while ((JD = FindNextHouseChange(JD, JDE, bodyId, earth, out nData)) < JDE)
            {
                AddRating(JD, loc, rec.rateGrahaHouse[bodyId, nData], rec.rateGrahaHouse[bodyId, Prev(nData, 12)]);
                JD += 1.0 / 24.0;
            }
        }
Exemplo n.º 22
0
        public static string GetTimeZoneOffsetText(double d)
        {
            int a4, a5;
            int sig;

            if (d < 0.0)
            {
                sig = -1;
                d   = -d;
            }
            else
            {
                sig = 1;
            }
            a4 = GCMath.IntFloor(d);
            a5 = Convert.ToInt32((d - a4) * 60);

            return(string.Format("{0}{1}:{2:00}", (sig > 0 ? '+' : '-'), a4, a5));
        }
Exemplo n.º 23
0
        public double FindNextHouseChange(double startJD, double endJD, int bodyId, GCEarthData earth, out int nNextHouse)
        {
            double jd = startJD;
            double A, B, B1;
            int    C, D;
            double step = 1.0 / 24.0;

            A   = GetPlanetHouse(GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd), jd, earth);
            jd += step;
            B1  = A;
            B   = GetPlanetHouse(GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd), jd, earth);
            C   = GCMath.IntFloor(A);
            D   = GCMath.IntFloor(B);

            while (jd < endJD && Math.Abs(B1 - B) >= 1 / 86400.0)
            {
                if (C == D)
                {
                    // goto next date
                    A = B;
                    C = D;
                }
                else if (C < D)
                {
                    jd    = jd - step;
                    step *= (D - A) / (B - A);
                }
                else // C > D
                {
                    jd    = jd - step;
                    step *= (A - C) / (A - B);
                }

                jd += step;
                B1  = B;
                B   = GetPlanetHouse(GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd), jd, earth);
                D   = GCMath.IntFloor(B);
            }

            nNextHouse = GCMath.IntFloor(GetPlanetHouse(GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd + 0.5 / 24.0), jd + 0.5 / 24.0, earth));
            return(jd);
        }
Exemplo n.º 24
0
        public double FindNextRasiChange(double startJD, double endJD, int bodyId, out int nNextRasi)
        {
            double jd = startJD;
            double A, B, B1;
            int    C, D;
            double step = 1.0;

            A   = (GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd) - GCAyanamsha.GetAyanamsa(jd)) / 30.0;
            jd += step;
            B1  = A;
            B   = (GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd) - GCAyanamsha.GetAyanamsa(jd)) / 30.0;
            C   = GCMath.IntFloor(A);
            D   = GCMath.IntFloor(B);

            while (jd < endJD && Math.Abs(B1 - B) >= 1 / 86400.0)
            {
                if (C == D)
                {
                    // goto next date
                    A = B;
                    C = D;
                }
                else if (C < D)
                {
                    jd    = jd - step;
                    step *= (D - A) / (B - A);
                }
                else // C > D
                {
                    jd    = jd - step;
                    step *= (C - B) / (A - B);
                }

                jd += step;
                B1  = B;
                B   = (GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd) - GCAyanamsha.GetAyanamsa(jd)) / 30.0;
                D   = GCMath.IntFloor(B);
            }

            nNextRasi = GCMath.IntFloor((GCVSOPAstronomy.GetPlanetLongitude(bodyId, jd + 0.1) - GCAyanamsha.GetAyanamsa(jd)) / 30.0);
            return(jd);
        }
Exemplo n.º 25
0
        public static GCEquatorialCoords eclipticalToEquatorialCoords(ref GCEclipticalCoords ecc, double date)
        {
            //var
            GCEquatorialCoords eqc;

            double epsilon;
            double nutationLongitude;

            GCEarthData.CalculateNutations(date, out nutationLongitude, out epsilon);


            // formula from Chapter 21
            ecc.longitude = GCMath.putIn360(ecc.longitude + nutationLongitude);

            // formulas from Chapter 12
            eqc.rightAscension = GCMath.arcTan2Deg(GCMath.sinDeg(ecc.longitude) * GCMath.cosDeg(epsilon) - GCMath.tanDeg(ecc.latitude) * GCMath.sinDeg(epsilon),
                                                   GCMath.cosDeg(ecc.longitude));

            eqc.declination = GCMath.arcSinDeg(GCMath.sinDeg(ecc.latitude) * GCMath.cosDeg(epsilon) + GCMath.cosDeg(ecc.latitude) * GCMath.sinDeg(epsilon) * GCMath.sinDeg(ecc.longitude));

            return(eqc);
        }
Exemplo n.º 26
0
        public static GCHourTime CalcSunset(GregorianDateTime vct, GCEarthData earth)
        {
            double    tempSunset = 180.0;
            GCSunData sun        = new GCSunData();

            for (int i = 0; i < 3; i++)
            {
                sun.SunPosition(vct, earth, tempSunset - 180.0);

                double x;
                // definition of event
                double eventdef = GCSunData.RiseAngleLevel;

                eventdef = (eventdef / GCMath.cosDeg(earth.latitudeDeg)) / GCMath.cosDeg(sun.declinationDeg);

                x = GCMath.tanDeg(earth.latitudeDeg) * GCMath.tanDeg(sun.declinationDeg) + eventdef;


                if ((x >= -1.0) && (x <= 1.0))
                {
                    // time of sunset
                    tempSunset = 270.0 - earth.longitudeDeg + GCMath.arcSinDeg(x) + sun.equationOfTime;
                }
                else
                {
                    // initial values for the case
                    // that no rise no set for that day
                    tempSunset = -360.0;
                    break;
                }
            }

            GCHourTime result = new GCHourTime();

            result.longitude = sun.longitudeDeg;
            result.SetDegTime(tempSunset + earth.OffsetUtcHours * 15.0);
            return(result);
        }
Exemplo n.º 27
0
        public void CorrectEqatorialWithParallax(double jdate, double latitude, double longitude, double height)
        {
            double       u, hourAngleBody, delta_alpha;
            double       rho_sin, rho_cos;
            const double b_a = 0.99664719;

            // calculate geocentric longitude and latitude of observer
            u       = GCMath.arcTanDeg(b_a * b_a * GCMath.tanDeg(latitude));
            rho_sin = b_a * GCMath.sinDeg(u) + height / 6378140.0 * GCMath.sinDeg(latitude);
            rho_cos = GCMath.cosDeg(u) + height / 6378140.0 * GCMath.cosDeg(latitude);

            // calculate paralax
            this.parallax = GCMath.arcSinDeg(GCMath.sinDeg(8.794 / 3600) / (MoonDistance(jdate) / GCMath.AU));

            // calculate correction of equatorial coordinates
            hourAngleBody = GCEarthData.SiderealTimeGreenwich(jdate) + longitude - this.rightAscension;
            delta_alpha   = GCMath.arcTan2Deg(-rho_cos * GCMath.sinDeg(this.parallax) * GCMath.sinDeg(hourAngleBody),
                                              GCMath.cosDeg(this.declination) - rho_cos * GCMath.sinDeg(this.parallax) * GCMath.cosDeg(hourAngleBody));
            this.rightAscension += delta_alpha;
            this.declination    += GCMath.arcTan2Deg(
                (GCMath.sinDeg(this.declination) - rho_sin * GCMath.sinDeg(this.parallax)) * GCMath.cosDeg(delta_alpha),
                GCMath.cosDeg(this.declination) - rho_cos * GCMath.sinDeg(this.parallax) * GCMath.cosDeg(hourAngleBody));
        }
Exemplo n.º 28
0
        public static GCEclipticalCoords CalculateEcliptical(double jdate)
        {
            double t, d, m, ms, f, e, ls;
            double sr, sl, sb, temp; // : extended;
            double a1, a2, a3;       // : extended;
            int    i;                //: integer;


            t = (jdate - 2451545.0) / 36525.0;

            //(* mean elongation of the moon
            d = 297.8502042 + (445267.1115168 + (-0.0016300 + (1.0 / 545868 - 1.0 / 113065000 * t) * t) * t) * t;

            //(* mean anomaly of the sun
            m = 357.5291092 + (35999.0502909 + (-0.0001536 + 1.0 / 24490000 * t) * t) * t;

            //(* mean anomaly of the moon
            ms = 134.9634114 + (477198.8676313 + (0.0089970 + (1.0 / 69699 - 1.0 / 1471200 * t) * t) * t) * t;

            //(* argument of the longitude of the moon
            f = 93.2720993 + (483202.0175273 + (-0.0034029 + (-1.0 / 3526000 + 1.0 / 863310000 * t) * t) * t) * t;

            //(* correction term due to excentricity of the earth orbit
            e = 1.0 + (-0.002516 - 0.0000074 * t) * t;

            //(* mean longitude of the moon
            ls = 218.3164591 + (481267.88134236 + (-0.0013268 + (1.0 / 538841 - 1.0 / 65194000 * t) * t) * t) * t;

            //(* arguments of correction terms
            a1 = 119.75 + 131.849 * t;
            a2 = 53.09 + 479264.290 * t;
            a3 = 313.45 + 481266.484 * t;

            sr = 0;
            for (i = 0; i < 60; i++)
            {
                temp = sigma_r[i] * GCMath.cosDeg(arg_lr[i, 0] * d
                                                  + arg_lr[i, 1] * m
                                                  + arg_lr[i, 2] * ms
                                                  + arg_lr[i, 3] * f);
                if (Math.Abs(arg_lr[i, 1]) == 1)
                {
                    temp = temp * e;
                }
                if (Math.Abs(arg_lr[i, 1]) == 2)
                {
                    temp = temp * e * e;
                }
                sr = sr + temp;
            }

            sl = 0;
            for (i = 0; i < 60; i++)
            {
                temp = sigma_l[i] * GCMath.sinDeg(arg_lr[i, 0] * d
                                                  + arg_lr[i, 1] * m
                                                  + arg_lr[i, 2] * ms
                                                  + arg_lr[i, 3] * f);
                if (Math.Abs(arg_lr[i, 1]) == 1)
                {
                    temp = temp * e;
                }
                if (Math.Abs(arg_lr[i, 1]) == 2)
                {
                    temp = temp * e * e;
                }
                sl = sl + temp;
            }

            //(* correction terms
            sl = sl + 3958 * GCMath.sinDeg(a1)
                 + 1962 * GCMath.sinDeg(ls - f)
                 + 318 * GCMath.sinDeg(a2);
            sb = 0;
            for (i = 0; i < 60; i++)
            {
                temp = sigma_b[i] * GCMath.sinDeg(arg_b[i, 0] * d
                                                  + arg_b[i, 1] * m
                                                  + arg_b[i, 2] * ms
                                                  + arg_b[i, 3] * f);
                if (Math.Abs(arg_b[i, 1]) == 1)
                {
                    temp = temp * e;
                }
                if (Math.Abs(arg_b[i, 1]) == 2)
                {
                    temp = temp * e * e;
                }
                sb = sb + temp;
            }

            //(* correction terms
            sb = sb - 2235 * GCMath.sinDeg(ls)
                 + 382 * GCMath.sinDeg(a3)
                 + 175 * GCMath.sinDeg(a1 - f)
                 + 175 * GCMath.sinDeg(a1 + f)
                 + 127 * GCMath.sinDeg(ls - ms)
                 - 115 * GCMath.sinDeg(ls + ms);

            GCEclipticalCoords coords;

            coords.longitude = ls + sl / 1000000;
            coords.latitude  = sb / 1000000;
            coords.distance  = 385000.56 + sr / 1000;

            return(coords);
        }
Exemplo n.º 29
0
        /*********************************************************************/
        /*                                                                   */
        /* Calculation of Rasi from sun-logitude and ayanamsa                */
        /*                                                                   */
        /*********************************************************************/

        public static int GetRasi(double SunLongitude, double Ayanamsa)
        {
            return(GCMath.IntFloor(GCMath.putIn360(SunLongitude - Ayanamsa) / 30.0));
        }
Exemplo n.º 30
0
        /*
         * Function before is writen accoring this algorithms:
         *
         *
         *  1. Normal - fasting day has ekadasi at sunrise and dvadasi at next sunrise.
         *
         *  2. Viddha - fasting day has dvadasi at sunrise and trayodasi at next
         *  sunrise, and it is not a naksatra mahadvadasi
         *
         *  3. Unmilani - fasting day has ekadasi at both sunrises
         *
         *  4. Vyanjuli - fasting day has dvadasi at both sunrises, and it is not a
         *  naksatra mahadvadasi
         *
         *  5. Trisprsa - fasting day has ekadasi at sunrise and trayodasi at next
         *  sunrise.
         *
         *  6. Jayanti/Vijaya - fasting day has gaura dvadasi and specified naksatra at
         *  sunrise and same naksatra at next sunrise
         *
         *  7. Jaya/Papanasini - fasting day has gaura dvadasi and specified naksatra at
         *  sunrise and same naksatra at next sunrise
         *
         *  ==============================================
         *  Case 1 Normal (no change)
         *
         *  If dvadasi tithi ends before 1/3 of daylight
         *     then PARANA END = TIME OF END OF TITHI
         *  but if dvadasi TITHI ends after 1/3 of daylight
         *     then PARANA END = TIME OF 1/3 OF DAYLIGHT
         *
         *  if 1/4 of dvadasi tithi is before sunrise
         *     then PARANA BEGIN is sunrise time
         *  but if 1/4 of dvadasi tithi is after sunrise
         *     then PARANA BEGIN is time of 1/4 of dvadasi tithi
         *
         *  if PARANA BEGIN is before PARANA END
         *     then we will write "BREAK FAST FROM xx TO yy
         *  but if PARANA BEGIN is after PARANA END
         *     then we will write "BREAK FAST AFTER xx"
         *
         *  ==============================================
         *  Case 2 Viddha
         *
         *  If trayodasi tithi ends before 1/3 of daylight
         *     then PARANA END = TIME OF END OF TITHI
         *  but if trayodasi TITHI ends after 1/3 of daylight
         *     then PARANA END = TIME OF 1/3 OF DAYLIGHT
         *
         *  PARANA BEGIN is sunrise time
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 3 Unmilani
         *
         *  PARANA END = TIME OF 1/3 OF DAYLIGHT
         *
         *  PARANA BEGIN is end of Ekadasi tithi
         *
         *  if PARANA BEGIN is before PARANA END
         *     then we will write "BREAK FAST FROM xx TO yy
         *  but if PARANA BEGIN is after PARANA END
         *     then we will write "BREAK FAST AFTER xx"
         *
         *  ==============================================
         *  Case 4 Vyanjuli
         *
         *  PARANA BEGIN = Sunrise
         *
         *  PARANA END is end of Dvadasi tithi
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 5 Trisprsa
         *
         *  PARANA BEGIN = Sunrise
         *
         *  PARANA END = 1/3 of daylight hours
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 6 Jayanti/Vijaya
         *
         *  PARANA BEGIN = Sunrise
         *
         *  PARANA END1 = end of dvadasi tithi or sunrise, whichever is later
         *  PARANA END2 = end of naksatra
         *
         *  PARANA END is earlier of END1 and END2
         *
         *  we will write "BREAK FAST FROM xx TO yy
         *
         *  ==============================================
         *  Case 7 Jaya/Papanasini
         *
         *  PARANA BEGIN = end of naksatra
         *
         *  PARANA END = 1/3 of Daylight hours
         *
         *  if PARANA BEGIN is before PARANA END
         *     then we will write "BREAK FAST FROM xx TO yy
         *  but if PARANA BEGIN is after PARANA END
         *     then we will write "BREAK FAST AFTER xx"
         *
         *
         * */
        public int CalculateEParana(GCEarthData earth)
        {
            VAISNAVADAY t = this;

            if (t.Previous == null)
            {
                return(0);
            }

            t.nMahadvadasiID = MahadvadasiType.EV_NULL;
            t.ekadasi_parana = true;
            t.nFastID        = FastType.FAST_NULL;

            TCoreEvent naksEnd;
            TCoreEvent parBeg     = null;
            TCoreEvent parEnd     = null;
            TCoreEvent tithiStart = null;
            TCoreEvent tithiEnd   = null;
            TCoreEvent sunRise    = t.FindCoreEvent(CoreEventType.CCTYPE_S_RISE);
            TCoreEvent sunSet     = t.FindCoreEvent(CoreEventType.CCTYPE_S_SET);

            if (sunRise == null || sunSet == null)
            {
                GCLog.Write("Cannot find sunrise of sunset for day " + t.date.ToString());
                return(0);
            }

            TCoreEvent third_day = new TCoreEvent()
            {
                nData = sunRise.nData,
                nType = CoreEventType.CCTYPE_THIRD_OF_DAY,
                nDst  = sunRise.nDst,
                Time  = (sunSet.Time - sunRise.Time) / 3 + sunRise.Time
            };

            List <CoreEventFindRec> tempTimes = GetRecentCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_TITHI, 1);

            if (tempTimes.Count != 1)
            {
                GCLog.Write("Start or End of tithi was not found for date " + t.ToString());
                return(0);
            }
            else
            {
                tithiStart = tempTimes[0].coreEvent;
            }

            tempTimes = GetNextCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_TITHI, 1);
            if (tempTimes.Count != 1)
            {
                GCLog.Write("End of tithi was not found for date " + t.ToString());
                tempTimes = GetNextCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_TITHI, 1);
                return(0);
            }
            else
            {
                tithiEnd = new TCoreEvent(tempTimes[0].coreEvent)
                {
                    nType = CoreEventType.CCTYPE_TITHI_END
                };
                tithiEnd.ApplyDstType(UtcDayStart, DstDayType);
            }

            if (Previous == null)
            {
                return(0);
            }

            tempTimes = Previous.GetNextCoreTimes(CoreEventType.CCTYPE_S_RISE, CoreEventType.CCTYPE_NAKS, 1);
            if (tempTimes.Count != 1)
            {
                GCLog.Write("End of naksatra was not found for date " + t.ToString());
                return(0);
            }
            else
            {
                naksEnd = new TCoreEvent(tempTimes[0].coreEvent)
                {
                    nType = CoreEventType.CCTYPE_NAKS_END
                };
                naksEnd.ApplyDstType(UtcDayStart, DstDayType);
            }

            TCoreEvent tithi_quart = new TCoreEvent()
            {
                nType = CoreEventType.CCTYPE_TITHI_QUARTER,
                nData = tithiStart.nData,
                Time  = (tithiEnd.Time - tithiStart.Time) / 4 + tithiStart.Time,
                nDst  = tithiStart.nDst
            };

            tithi_quart.ApplyDstType(UtcDayStart, DstDayType);


            switch (t.Previous.nMahadvadasiID)
            {
            case MahadvadasiType.EV_UNMILANI:
                parEnd = GCMath.Min(tithiEnd, third_day);
                parBeg = sunRise;
                break;

            case MahadvadasiType.EV_VYANJULI:
                parBeg = sunRise;
                parEnd = GCMath.Min(tithiEnd, third_day);
                break;

            case MahadvadasiType.EV_TRISPRSA:
                parBeg = sunRise;
                parEnd = third_day;
                break;

            case MahadvadasiType.EV_JAYANTI:
            case MahadvadasiType.EV_VIJAYA:
                if (GCTithi.TITHI_DVADASI(t.astrodata.sunRise.Tithi))
                {
                    if (naksEnd.Time < tithiEnd.Time)
                    {
                        if (naksEnd.Time < third_day.Time)
                        {
                            parBeg = naksEnd;
                            parEnd = GCMath.Min(tithiEnd, third_day);
                        }
                        else
                        {
                            parBeg = naksEnd;
                            parEnd = tithiEnd;
                        }
                    }
                    else
                    {
                        parBeg = sunRise;
                        parEnd = GCMath.Min(tithiEnd, third_day);
                    }
                }
                else
                {
                    parBeg = sunRise;
                    parEnd = GCMath.Min(naksEnd, third_day);
                }

                break;

            case MahadvadasiType.EV_JAYA:
            case MahadvadasiType.EV_PAPA_NASINI:
                if (GCTithi.TITHI_DVADASI(t.astrodata.sunRise.Tithi))
                {
                    if (naksEnd.Time < tithiEnd.Time)
                    {
                        if (naksEnd.Time < third_day.Time)
                        {
                            parBeg = naksEnd;
                            parEnd = GCMath.Min(tithiEnd, third_day);
                        }
                        else
                        {
                            parBeg = naksEnd;
                            parEnd = tithiEnd;
                        }
                    }
                    else
                    {
                        parBeg = sunRise;
                        parEnd = GCMath.Min(tithiEnd, third_day);
                    }
                }
                else
                {
                    if (naksEnd.Time < third_day.Time)
                    {
                        parBeg = naksEnd;
                        parEnd = third_day;
                    }
                    else
                    {
                        parBeg = naksEnd;
                        parEnd = null;
                    }
                }

                break;

            default:
                // first initial
                parEnd = GCMath.Min(tithiEnd, third_day);
                parBeg = GCMath.Max(sunRise, tithi_quart);
                if (GCTithi.TITHI_DVADASI(t.Previous.astrodata.sunRise.Tithi))
                {
                    parBeg = sunRise;
                }

                break;
            }

            if (parBeg.Time >= parEnd.Time)
            {
                parEnd = null;
            }

            t.eparana_time1 = parBeg;
            t.eparana_time2 = parEnd;

            return(1);
        }