예제 #1
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);
        }
예제 #2
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);
        }
        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));
        }
예제 #5
0
        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.");
        }