Example #1
0
        /// <summary>
        /// Calculates solar position for a given location and point in time
        /// </summary>
        /// <param name="date">time and date calculate for</param>
        /// <param name="latitude">latitude in degrees</param>
        /// <param name="longitude">longitude in degrees</param>
        /// <returns></returns>
        public static SunPosition GetPosition(DateTime date, double latitude, double longitude)
        {
            double lw  = Constants.Rad * -longitude;
            double phi = Constants.Rad * latitude;
            double d   = Calendar.ToDays(date);

            SunCoordinates c = Sun.Coordinates(d);
            double         H = Position.SiderealTime(d, lw) - c.RightAscension;

            return(new SunPosition
            {
                Azimuth = Position.Azimuth(H, phi, c.Declination),
                Altitude = Position.Altitude(H, phi, c.Declination)
            });
        }
Example #2
0
        /// <summary>
        /// Calculates lunar position for a given location and point in time
        ///
        /// based on http://aa.quae.nl/en/reken/hemelpositie.html formulas
        /// </summary>
        /// <param name="date">time and date calculate for</param>
        /// <param name="latitude">latitude in degrees</param>
        /// <param name="longitude">longitude in degrees</param>
        /// <returns></returns>
        public static MoonPosition GetMoonPosition(DateTime date, double latitude, double longitude)
        {
            var lw  = Constants.Rad * -longitude;
            var phi = Constants.Rad * latitude;
            var d   = Calendar.ToDays(date);

            var c = Moon.Coordinates(d);
            var H = Position.SiderealTime(d, lw) - c.RightAscension;
            var h = Position.Altitude(H, phi, c.Declination);
            // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
            var pa = Math.Atan2(Math.Sin(H), Math.Tan(phi) * Math.Cos(c.Declination) - Math.Sin(c.Declination) * Math.Cos(H));

            h += Moon.AstroRefraction(h); // altitude correction for refraction

            return(new MoonPosition
            {
                Azimuth = Position.Azimuth(H, phi, c.Declination),
                Altitude = h,
                Distance = c.Distance,
                ParallacticAngle = pa
            });
        }