Пример #1
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));
            }
        }
Пример #2
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);
            }
        }
Пример #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);
            }
        }
Пример #4
0
        private void initiateCache()
        {
            this.cachedAspects = new SortedDictionary <double, double>(new JulianUtComparer());
            double inDegrees = SweWrapper.LongitudeDegreeOf(referencePoint, Interior);
            double exDegrees = SweWrapper.LongitudeDegreeOf(referencePoint, Exterior);
            double angle     = (inDegrees - exDegrees + 360.0) % 360;
            double expected  = similarAspectDegrees(angle);
            double orb       = ((angle > 180.0) ? 360.0 - expected : expected) - angle;

            this.cachedAspects.Add(referencePoint, angle);
        }
Пример #5
0
        public void Calculate()
        {
            double jul_ut = SweWrapper.ToJulianDay(this.moment);

            PlanetPosition pos = null;

            foreach (PlanetId id in Astrolabe.Concerned)
            {
                pos = SweWrapper.PositionOf(jul_ut, id, SeFlg.SEFLG_SPEED);

                if (this.starPositions.ContainsKey(id))
                {
                    this.starPositions[id] = pos;
                }
                else
                {
                    this.starPositions.Add(id, pos);
                }

                //this.starPositions.Add(id, pos);

                //pos2 = PositionOf(jul_et, id);
            }

            SweWrapper.swe_close();

            PlanetPosition posA, posB;

            patterns.Clear();

            for (int i = 0; i < starPositions.Count - 1; i++)
            {
                KeyValuePair <PlanetId, PlanetPosition> kvp = starPositions.ElementAt(i);
                posA = kvp.Value;
                for (int j = i + 1; j < starPositions.Count; j++)
                {
                    kvp  = starPositions.ElementAt(j);
                    posB = kvp.Value;

                    if (Relation.HasRelation(posA, posB))
                    {
                        Relation newRelation = new Relation(posA, posB);

                        patterns.Add(newRelation.Kind, newRelation);
                    }
                }
            }
        }
Пример #6
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);
        }
Пример #7
0
 public AspectHelper(RelationKind kind, DateTime time)
 {
     this.kind            = kind;
     this.referencePoint  = SweWrapper.ToJulianDay(time);
     this.cachedAspects   = new SortedDictionary <double, double>(new JulianUtComparer());
     this.concernedAngles = new List <double>();
     if (kind.Pattern != AspectType.None)
     {
         this.concernedAngles.Add(Aspect.DegreesOf(kind.Pattern));
     }
     else
     {
         foreach (double degrees in Aspect.Concerned.Keys)
         {
             this.concernedAngles.Add(degrees);
         }
     }
     initiateCache();
 }
Пример #8
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));
        }
Пример #9
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());
            }
        }
Пример #10
0
        public List <Phenomenon> GetNearbyPhenonema()
        {
            List <Phenomenon> phenomena = new List <Phenomenon>();
            PlanetPosition    posA, posB;

            for (int i = 0; i < starPositions.Count - 1; i++)
            {
                KeyValuePair <PlanetId, PlanetPosition> kvp = starPositions.ElementAt(i);
                posA = kvp.Value;
                for (int j = i + 1; j < starPositions.Count; j++)
                {
                    kvp  = starPositions.ElementAt(j);
                    posB = kvp.Value;

                    Relation newRelation = new Relation(posA, posB);

                    AspectHelper helper = new AspectHelper(newRelation.Kind, this.moment);

                    Phenomenon newPhenom = helper.PhenomenonNearby();

                    if (newPhenom != null)
                    {
                        phenomena.Add(newPhenom);
                    }
                    //if (Relation.HasRelation(posA, posB))
                    //{
                    //    Relation newRelation = new Relation(posA, posB);

                    //    AspectHelper helper = new AspectHelper(newRelation.Kind, this.moment);

                    //    Phenomenon newPhenom = helper.PhenomenonNearby();

                    //    if (newPhenom != null)
                    //        phenomena.Add(newPhenom);
                    //}
                }
            }

            SweWrapper.swe_close();

            return(phenomena);
        }