Esempio n. 1
0
        public static PlanetPosition NorthSouthNode(double jul_ut, PlanetId id, SeFlg flag)
        {
            if (id != PlanetId.SE_NORTHNODE && id != PlanetId.SE_SOUTHNODE)
            {
                throw new Exception("Wrong parameter of " + id.ToString());
            }

            double[] xnasc    = new double[6];
            double[] xndsc    = new double[6];
            double[] xperi    = new double[6];
            double[] xaphe    = new double[6];
            String   errorMsg = "";

            if (swe_nod_aps_ut(jul_ut, PlanetId.SE_MOON, flag, 0, xnasc, xndsc, xperi, xaphe, errorMsg) == SeFlg.ERR)
            {
                DateTime utc = SweWrapper.UtcFromJulianDay(jul_ut);
                Console.WriteLine(String.Format("Error for {0}@{1} with Flag of {2}: {3}", id, utc, SeFlg.DEFAULT, errorMsg));
                return(null);
            }
            else
            {
                PlanetPosition nodePos = new PlanetPosition(id, (id == PlanetId.SE_NORTHNODE) ? xnasc : xndsc);
                return(nodePos);
            }
        }
Esempio n. 2
0
        public static PlanetPosition PositionOf(double jul_ut, PlanetId id, SeFlg flag)
        {
            double[] result   = new double[6];
            String   errorMsg = "";

            SeFlg retFlag = SeFlg.ERR;

            if (id < PlanetId.SE_NORTHNODE)
            {
                retFlag = swe_calc_ut(jul_ut, id, flag, result, errorMsg);
                if (retFlag == SeFlg.ERR)
                {
                    DateTime utc = SweWrapper.UtcFromJulianDay(jul_ut);
                    Console.WriteLine(String.Format("Error for {0}@{1} with Flag of {2}: {3}", id, utc, SeFlg.DEFAULT, errorMsg));
                    return(null);
                }
                else
                {
                    if (retFlag != flag)
                    {
                        Console.WriteLine(((SeFlg)retFlag).ToString());
                    }
                    return(new PlanetPosition(id, result));
                }
            }
            else
            {
                return(NorthSouthNode(jul_ut, id, flag));
            }
        }
Esempio n. 3
0
        public static List <Angle> GetObliquityNutation(Double jul_ut)
        {
            double[] result   = new double[6];
            String   errorMsg = "";

            SeFlg retFlag = swe_calc_ut(jul_ut, PlanetId.SE_ECL_NUT, SeFlg.DEFAULT, result, errorMsg);

            if (retFlag == SeFlg.ERR)
            {
                DateTime utc = SweWrapper.UtcFromJulianDay(jul_ut);
                return(null);
            }
            else
            {
                //Console.WriteLine(((SeFlg)retFlag).ToString());
                List <Angle> angles            = new List <Angle>();
                Angle        trueObliquity     = new Angle(result[0]);
                Angle        meanObliquity     = new Angle(result[1]);
                Angle        nutationLongitude = new Angle(result[2]);
                Angle        nutationObliquity = new Angle(result[3]);
                angles.Add(trueObliquity);
                angles.Add(meanObliquity);
                angles.Add(nutationLongitude);
                angles.Add(nutationObliquity);
                return(angles);
            }
        }
Esempio n. 4
0
        //public DateTime GetEventTime()
        //{
        //    Double expected = DegreesExpected;

        //    double jul = referencePoint;
        //    PlanetPosition interiorPos, exterirorPos;
        //    double angle, orb, speed, step = 100.0, inPos, exPos;

        //    for (int tryCount = 0; tryCount < maxTry; tryCount ++ )
        //    {
        //        interiorPos = SweWrapper.PositionOf(jul, Interior, SeFlg.SEFLG_SPEED);
        //        exterirorPos = SweWrapper.PositionOf(jul, Exterior, SeFlg.SEFLG_SPEED);

        //        inPos = interiorPos.Rectascension.Degrees;
        //        exPos = exterirorPos.Rectascension.Degrees;

        //        angle =( inPos - exPos + 360) % 360.0;

        //        orb = ( (angle > 180.0) ? 360.0-expected : expected) - angle;
        //        speed = interiorPos.LongVelo.Degrees - exterirorPos.LongVelo.Degrees;

        //        if (!cachedAspects.ContainsKey(jul))
        //            cachedAspects.Add(jul, angle);

        //        if (Math.Abs(orb) < Negligible)
        //            return SweWrapper.UtcFromJulianDay(jul);

        //        step = orb / speed;
        //        jul += step;

        //        //step = Math.Min(step / 2.0, Math.Abs(orb / speed));

        //        //if (orb * speed * (inPos-exPos) > 0)
        //        //    jul += step;
        //        //else
        //        //    jul -= step;
        //    }
        //    return getClosestFromCache();
        //}

        public Phenomenon PhenomenonNearby()
        {
            Double expected = similarAspectDegrees(cachedAspects[referencePoint]);

            double         jul = referencePoint;
            PlanetPosition interiorPos, exterirorPos;
            double         angle, orb, speed, step = 100.0, inPos, exPos;

            for (int tryCount = 0; tryCount < maxTry; tryCount++)
            {
                interiorPos  = SweWrapper.PositionOf(jul, Interior, SeFlg.SEFLG_SPEED);
                exterirorPos = SweWrapper.PositionOf(jul, Exterior, SeFlg.SEFLG_SPEED);

                inPos = interiorPos.Rectascension.Degrees;
                exPos = exterirorPos.Rectascension.Degrees;

                angle = (inPos - exPos + 360) % 360.0;

                orb   = ((angle > 180.0) ? 360.0 - expected : expected) - angle;
                speed = interiorPos.LongVelo.Degrees - exterirorPos.LongVelo.Degrees;

                if (!cachedAspects.ContainsKey(jul))
                {
                    cachedAspects.Add(jul, angle);
                }

                if (Math.Abs(orb) < Negligible)
                {
                    return(new Phenomenon(SweWrapper.UtcFromJulianDay(jul),
                                          new RelationKind(Interior, Exterior, Aspect.AspectTypeOf(expected)), inPos, exPos));
                    //return SweWrapper.UtcFromJulianDay(jul);
                }

                step = orb / speed;
                jul += step;

                //step = Math.Min(step / 2.0, Math.Abs(orb / speed));

                //if (orb * speed * (inPos-exPos) > 0)
                //    jul += step;
                //else
                //    jul -= step;
            }
            return(null);
        }
Esempio n. 5
0
        private DateTime getClosestFromCache(Double expected)
        {
            double closestDate = 0;
            double minOrb      = 5.0;
            double orb;

            foreach (KeyValuePair <double, double> kvp in cachedAspects)
            {
                orb = Math.Abs(kvp.Value);
                orb = (orb >= expected) ? orb - expected : expected - orb;
                if (minOrb > orb)
                {
                    closestDate = kvp.Key;
                    minOrb      = orb;
                }
            }

            return(SweWrapper.UtcFromJulianDay(closestDate));
        }
Esempio n. 6
0
        public static void CalcPhenomenon(DateTime utcMoment, PlanetId ipl, SeFlg flag)
        {
            double jul_ut = ToJulianDay(utcMoment);

            double[] result   = new double[20];
            String   errorMsg = "";

            SeFlg retFlag = SeFlg.ERR;

            retFlag = swe_pheno_ut(jul_ut, ipl, flag, result, errorMsg);
            if (retFlag == SeFlg.ERR)
            {
                DateTime utc = SweWrapper.UtcFromJulianDay(jul_ut);
                Console.WriteLine(String.Format("Error for {0}@{1} with Flag of {2}: {3}", ipl, utc, SeFlg.DEFAULT, errorMsg));
            }
            else
            {
                ///  * attr[0] = phase theAngle (earth-planet-sun)
                ///  * attr[1] = phase (illumined fraction of disc)
                ///  * attr[2] = elongation of planet
                ///  * attr[3] = apparent diameter of disc
                ///  * attr[4] = apparent magnitude
                ///  * attr[5] = geocentric horizontal parallax (Moon)
                DateTime utc = SweWrapper.UtcFromJulianDay(jul_ut);

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0} at {1}", ipl, utc);
                sb.AppendFormat("PhaseAngle = {0}, Phase={1}, Elongation={2}, Diameter={3}, Magnitude={4}, Parallax={5}",
                                result[0], result[1], result[2], result[3], result[4], result[5]);

                for (int i = 6; i < 20; i++)
                {
                    sb.AppendFormat("result[{0}] = {1}\t", i, result[i]);
                    if ((i - 6) % 5 == 4)
                    {
                        sb.AppendLine();
                    }
                }

                Console.Write(sb.ToString());
            }
        }