コード例 #1
0
        /// <summary>
        /// Returns ascendant integer value.
        /// For instance 1 is ascendant between 0 and 30 degrees (Aries),
        /// 2 is ascendant between 30 and 60 degrees (Taurus).
        /// For more details see https://en.wikipedia.org/wiki/Astrological_sign
        /// </summary>
        /// <param name="birthDateTime">UTC time at moment of birth</param>
        /// <param name="longitude">West are negative values, East are positive values</param>
        /// <param name="latitude">North are positive values, South are negative values</param>
        /// <param name="isVedic"></param>
        /// <returns></returns>
        public static int GetAscendant(DateTime birthDateTime, double longitude, double latitude, bool isVedic = true)
        {
            if (CoordinatesInvalid())
            {
                throw new ArgumentOutOfRangeException("Invalid longitude");
            }

            var asc = AscendantCalculations.GetAscendant(longitude, latitude, birthDateTime, isVedic);

            if (isVedic)
            {
                var shift = CommonCalculations.GetVedicShift(birthDateTime);
                asc -= shift;
            }
#if DEBUG
            Console.WriteLine(asc);
#endif
            return((int)asc / 30 + 1);

            bool CoordinatesInvalid()
            {
                return(longitude > 180 || longitude < -180 || latitude > 90 || latitude < -90);
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns dictionary translating int Houses to lists of tuples (int Planet, decimal Degree)
        /// Degrees values are ecliptical longitudes (longitudes % 30).
        /// Complete longitude value may be retrieved from correspodning House number.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="longitude"></param>
        /// <param name="latitude"></param>
        /// <param name="isVedic"></param>
        /// <param name="HousesPlanets">12 item list. Each item corresponds to one House. Each item contains array of numbers of planets</param>
        /// <param name="PlanetDegrees">List of planets with longitudes</param>
        /// <returns></returns>
        public void CalculatePositions(DateTime date, double longitude, double latitude, bool isVedic,
                                       out List <int[]> HousesPlanets, out List <Pair <int, decimal> > PlanetDegrees)
        {
            // Initialize output lists
            List <int[]> housesPlanets;
            List <Pair <int, decimal> > planetDegrees;

            InitializeLists();

            // Calculate vedic shift
            var vedicShift = isVedic ? CommonCalculations.GetVedicShift(date) : 0m;

            // Add ascendant to output list
            AddAscendant();

            // Add planets to outputlist
            AddPlanets();

            // Assign results to output references
            HousesPlanets = housesPlanets;
            PlanetDegrees = planetDegrees;

            // Local functions
            void InitializeLists()
            {
                housesPlanets = new List <int[]>();
                for (var i = 0; i < 12; i++)
                {
                    housesPlanets.Add(new int[] { });
                }
                planetDegrees = new List <Pair <int, decimal> >(PlanetPositions.Count);
            }

            void AddAscendant()
            {
                var asc = AscendantCalculations.GetAscendant(longitude, latitude, date, isVedic);

                if (isVedic)
                {
                    asc -= vedicShift;
                }
                From0_To360(ref asc);
                var house        = (int)(asc / 30);
                var currentArray = housesPlanets[house];
                var newArray     = new int[currentArray.Length + 1];

                currentArray.CopyTo(newArray, 0);
                newArray[currentArray.Length] = planetToNumbers["Ascendant"];
                housesPlanets[house]          = newArray;

                planetDegrees.Add(new Pair <int, decimal>(0, asc % 30));
            }

            void AddPlanets()
            {
                foreach (var planet in PlanetPositions)
                {
                    var planetNumber = planetToNumbers[planet.Name];
                    var eclLon       = planet.EclipticCoordinates(date).X;

                    From0_To360(ref eclLon);
                    if (isVedic)
                    {
                        eclLon -= vedicShift;
                    }
                    From0_To360(ref eclLon);
#if DEBUG
                    Console.WriteLine($"{planet.Name} degrees: {eclLon}\n\n\n\n");
#endif
                    var house = (int)(eclLon / 30);

                    var currentArray = housesPlanets[house];
                    var newArray     = new int[currentArray.Length + 1];
                    currentArray.CopyTo(newArray, 0);
                    newArray[currentArray.Length] = planetToNumbers[planet.Name];
                    housesPlanets[house]          = newArray;

                    planetDegrees.Add(new Pair <int, decimal>(planetNumber, eclLon % 30));
                }
            }

            // degrees should be in [0,360)
            void From0_To360(ref decimal deg)
            {
                deg %= 360;
                deg += 360;
                deg %= 360;
            }
        }