public static double Asin(double value)
        {
            var radians = DegreeHelper.DegreesToRadians(value);
            var result  = System.Math.Asin(radians);

            return(result);
        }
        public static RiseTransitSetModel GetRiseTransitSet(
            this CelestialObjectPositionModel celestialObjectPosition,
            CelestialObjectPositionModel earthPosition,
            double longitudeDegrees,
            double latitudeDegrees)
        {
            var transitTimeSpan = celestialObjectPosition.GetTransitTimeSpan(earthPosition, longitudeDegrees);

            var transit = new DateTimeOffset(
                celestialObjectPosition.ReferenceDate.DateTime.Year,
                celestialObjectPosition.ReferenceDate.DateTime.Month,
                celestialObjectPosition.ReferenceDate.DateTime.Day,
                transitTimeSpan.Hours,
                transitTimeSpan.Minutes,
                transitTimeSpan.Seconds,
                transitTimeSpan.Milliseconds,
                TimeSpan.Zero);

            var hourHorizonDegrees  = celestialObjectPosition.GetHourHorizon(latitudeDegrees, 0);
            var hourHorizonTimeSpan = DegreeHelper.DegreeToTimeSpan(hourHorizonDegrees);
            var rise = transit - hourHorizonTimeSpan;
            var set  = transit + hourHorizonTimeSpan;

            return(new RiseTransitSetModel(rise, transit, set));
        }
Exemple #3
0
        /// <summary>
        /// Compute the eccentric anomaly 'E'
        /// </summary>
        /// <param name="eccentricity"></param>
        /// <param name="meanAnomaly"></param>
        /// <param name="tolerance">number of decimal positions</param>
        /// <param name="maximumIterations"></param>
        /// <returns></returns>
        internal static double GetEccentricAnomaly2(double eccentricity, DegreeModel meanAnomaly, double tolerance, double maximumIterations)
        {
            var delta = Math.Pow(10, -tolerance);

            var ma = meanAnomaly.Degrees;

            ma = ma / 360.0;

            ma = 2 * Math.PI * (ma - Math.Floor(ma));

            var eccentricAnomaly = eccentricity < 0.8 ? ma : Math.PI;

            var calculateF = eccentricAnomaly - (eccentricity * Math.Sin(ma)) - ma;

            double i = 0;

            while (Math.Abs(calculateF) > delta && i < maximumIterations)
            {
                eccentricAnomaly = eccentricAnomaly - (calculateF / (1.0 - (eccentricity * Math.Cos(eccentricAnomaly))));
                calculateF       = eccentricAnomaly - (eccentricity * Math.Sin(eccentricAnomaly)) - ma;
                i++;
            }

            eccentricAnomaly = DegreeHelper.RadiansToDegrees(eccentricAnomaly);

            var result = Math.Round(eccentricAnomaly * Math.Pow(10, tolerance)) / Math.Pow(10, tolerance);

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Compute the eccentric anomaly 'E'
        /// </summary>
        /// <param name="eccentricity"></param>
        /// <param name="meanAnomaly"></param>
        /// <returns></returns>
        internal static double GetEccentricAnomaly(double eccentricity, DegreeModel meanAnomaly)
        {
            var iteration = 0;
            var maxIterationsiteration = 1000000;
            var tolerance = Math.Pow(10, -10);

            var eccentricAnomalyDegrees = new DegreeModel(DegreeHelper.RadiansToDegrees(eccentricity));

            var result = meanAnomaly.Degrees + (eccentricAnomalyDegrees.Degrees * MathDegrees.Sin(meanAnomaly.Degrees));

            while (iteration < maxIterationsiteration)
            {
                var deltaMeanAnomaly      = meanAnomaly.Degrees - (result - (eccentricAnomalyDegrees.Degrees * MathDegrees.Sin(result)));
                var deltaEccentricAnomaly = deltaMeanAnomaly / (1 - (eccentricity * MathDegrees.Cos(result)));
                result = result + deltaEccentricAnomaly;

                if (Math.Abs(deltaEccentricAnomaly) < tolerance)
                {
                    return(result);
                }

                iteration++;
            }

            return(result);
        }
 private void ColourDeviceViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == HUE_PROPERTY)
     {
         this.angle = DegreeHelper.ConvertToDegree(this.Hue);
         this.OnPropertyChanged(ANGLE_PROPERTY);
     }
 }
        public static double Atan2(double value, double secondaryValue)
        {
            var radians          = DegreeHelper.DegreesToRadians(value);
            var secondaryRadians = DegreeHelper.DegreesToRadians(secondaryValue);
            var result           = System.Math.Atan2(radians, secondaryRadians);

            return(result);
        }
 /// <summary>
 /// Θ = MEarth + ΠEarth + 15° (t+tz) (mod360°)
 /// </summary>
 /// <param name="meanAnomaly"></param>
 /// <param name="minuteConstant">degree ratation per minute</param>
 /// <param name="keplerianOrbitValue"></param>
 /// <param name="utcMinutes"></param>
 /// <returns></returns>
 private static double GetSiderealTime(
     double meanAnomaly,
     double minuteConstant,
     KeplerianOrbitValueModel keplerianOrbitValue,
     int utcMinutes)
 {
     return(DegreeHelper.Modulo360Absolute(meanAnomaly + keplerianOrbitValue.Pi + (minuteConstant * utcMinutes)));
 }
        public void DegreeToTimeTest(double value, int expectedHours, int expectedMinutes, int expectedSeconds)
        {
            var actualTimeSpan = DegreeHelper.DegreeToTimeSpan(value);

            Assert.Equal(expectedHours, actualTimeSpan.Hours);
            Assert.Equal(expectedMinutes, actualTimeSpan.Minutes);
            Assert.Equal(expectedSeconds, actualTimeSpan.Seconds);
        }
 public static double GetTransitDegrees(
     double celestialObjectRightAscension,
     double earthMeanAnomaly,
     double longitudeDegrees)
 {
     return(DegreeHelper.Modulo360Absolute(celestialObjectRightAscension +
                                           longitudeDegrees -
                                           earthMeanAnomaly -
                                           EarthKeplerianOrbitValue.Pi));
 }
        public static TimeSpan GetTransitTimeSpan(
            this CelestialObjectPositionModel celestialObjectPosition,
            CelestialObjectPositionModel earthPosition,
            double longitudeDegrees)
        {
            var degrees = celestialObjectPosition.GetTransitDegrees(
                earthPosition,
                longitudeDegrees);

            return(DegreeHelper.DegreeToTimeSpan(degrees));
        }
        public void DegreeTimeSpanConversionTest(double value)
        {
            var actualTimeSpan   = DegreeHelper.DegreeToTimeSpan(value);
            var expectedTimeSpan = new TimeSpan((int)Math.Floor(value / 15), (int)Math.Floor(value % 15) * 4, (int)Math.Floor((value % 0.25) * 240));

            Assert.Equal(expectedTimeSpan.Hours, actualTimeSpan.Hours);
            Assert.Equal(expectedTimeSpan.Minutes, actualTimeSpan.Minutes);
            Assert.Equal(expectedTimeSpan.Seconds, actualTimeSpan.Seconds);

            var actualDegrees = DegreeHelper.TimeSpanToDegree(actualTimeSpan);

            Assert.Equal(value, actualDegrees);
        }
        private static double GetHourHorizon(
            this CelestialObjectPositionModel celestialObjectPosition,
            double latitudeDegrees,
            double h0)
        {
            if (h0.EqualsWithinTolerance(0, 6))
            {
                return(DegreeHelper.RadiansToDegrees(
                           Math.Acos(
                               -MathDegrees.Tan(latitudeDegrees) *
                               MathDegrees.Tan(celestialObjectPosition.Declination))));
            }

            return(DegreeHelper.RadiansToDegrees(Math.Acos(
                                                     (MathDegrees.Sin(h0) - (MathDegrees.Sin(latitudeDegrees) * MathDegrees.Sin(celestialObjectPosition.Declination))) /
                                                     (MathDegrees.Cos(latitudeDegrees) * MathDegrees.Cos(celestialObjectPosition.Declination)))));
        }
        internal static SkyPositionModel GetSkyPosition(
            double declination,
            double latitude,
            DateTimeOffset dateTimeOffset,
            double siderealTime)
        {
            var azimuth =
                DegreeHelper.RadiansToDegrees(
                    Math.Atan2(
                        MathDegrees.Sin(siderealTime),
                        (MathDegrees.Cos(siderealTime) * MathDegrees.Sin(latitude)) - (MathDegrees.Tan(declination) * MathDegrees.Cos(latitude))));

            var height =
                DegreeHelper.RadiansToDegrees(
                    Math.Asin(
                        (MathDegrees.Sin(latitude) * MathDegrees.Sin(declination)) +
                        (MathDegrees.Cos(latitude) * MathDegrees.Cos(declination) * MathDegrees.Cos(siderealTime))));

            return(new SkyPositionModel(dateTimeOffset, height, azimuth));
        }
        public void TimeToDegreeTest(int hours, int minutes, int seconds, double expected)
        {
            var actualTimeSpan = DegreeHelper.TimeSpanToDegree(new TimeSpan(hours, minutes, seconds));

            Assert.Equal(expected, actualTimeSpan);
        }
        public void Modulo360AroundZeroTest(double value, double expected)
        {
            var actual = DegreeHelper.Modulo360AroundZero(value);

            Assert.True(expected.EqualsWithinTolerance(actual, 6), $"expected {expected} and actual {actual} are not equal.");
        }
        public void RadiansToDegreesTest(double value, double expected)
        {
            var actual = DegreeHelper.RadiansToDegrees(value);

            Assert.True(expected.EqualsWithinTolerance(actual, 6), $"expected {expected} and actual {actual} are not equal.");
        }
 public static DegreeModel Modulo360Absolute(this DegreeModel model)
 {
     return(new DegreeModel(DegreeHelper.Modulo360Absolute(model.Degrees)));
 }
 public static DegreeModel Modulo360AroundZero(this DegreeModel model)
 {
     return(new DegreeModel(DegreeHelper.Modulo360AroundZero(model.Degrees)));
 }
Exemple #19
0
 /// <summary>
 /// Get the argument of Perihelion 'ω' = 'ϖ' - 'Ω'
 /// </summary>
 /// <returns></returns>
 public DegreeModel GetArgumentOfPerihelion()
 {
     return(new DegreeModel(DegreeHelper.Modulo360Absolute(PerihelionLongitude.Degrees - AscendingNodeLongitude.Degrees)));
 }
Exemple #20
0
 /// <summary>
 /// Get the argument of Perihelion 'M' = 'L' - 'ϖ' or 'L' - 'ω'' - 'Ω'
 /// </summary>
 /// <returns></returns>
 public DegreeModel GetMeanAnomaly360()
 {
     return(new DegreeModel(DegreeHelper.Modulo360Absolute(MeanLongitude.Degrees - PerihelionLongitude.Degrees)));
 }
Exemple #21
0
 /// <summary>
 /// Get the argument of Perihelion 'M' = 'L' - 'ϖ' or 'L' - 'ω'' - 'Ω'
 /// </summary>
 /// <returns></returns>
 public DegreeModel GetMeanAnomalyAroundZero()
 {
     return(new DegreeModel(DegreeHelper.Modulo360AroundZero(MeanLongitude.Degrees - PerihelionLongitude.Degrees)));
 }