diff --git a/PALib.Tests/PABinary.cs b/PALib.Tests/PABinary.cs index d8ce6cf..7af1343 100644 --- a/PALib.Tests/PABinary.cs +++ b/PALib.Tests/PABinary.cs @@ -1,20 +1,19 @@ using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PABinary_Tests { - public class PABinary_Tests - { - private readonly PABinary _paBinary; + private readonly PABinary _paBinary; - public PABinary_Tests() - { - _paBinary = new PABinary(); - } + public PABinary_Tests() + { + _paBinary = new PABinary(); + } - [Fact] - public void BinaryStarOrbit() - { - Assert.Equal((318.5, 0.41), _paBinary.BinaryStarOrbit(1, 1, 1980, "eta-Cor")); - } + [Fact] + public void BinaryStarOrbit() + { + Assert.Equal((318.5, 0.41), _paBinary.BinaryStarOrbit(1, 1, 1980, "eta-Cor")); } -} \ No newline at end of file +} diff --git a/PALib.Tests/PAComet.cs b/PALib.Tests/PAComet.cs index 1c3ebc3..faa70e3 100644 --- a/PALib.Tests/PAComet.cs +++ b/PALib.Tests/PAComet.cs @@ -1,26 +1,25 @@ using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PAComet_Tests { - public class PAComet_Tests - { - private readonly PAComet _paComet; + private readonly PAComet _paComet; - public PAComet_Tests() - { - _paComet = new PAComet(); - } + public PAComet_Tests() + { + _paComet = new PAComet(); + } - [Fact] - public void PositionOfEllipticalComet() - { - Assert.Equal((6, 29, 10, 13, 8.13), _paComet.PositionOfEllipticalComet(0, 0, 0, false, 0, 1, 1, 1984, "Halley")); - } + [Fact] + public void PositionOfEllipticalComet() + { + Assert.Equal((6, 29, 10, 13, 8.13), _paComet.PositionOfEllipticalComet(0, 0, 0, false, 0, 1, 1, 1984, "Halley")); + } - [Fact] - public void PositionOfParabolicComet() - { - Assert.Equal((23, 17, 11.53, -33, 42, 26.42, 1.11), _paComet.PositionOfParabolicComet(0, 0, 0, false, 0, 25, 12, 1977, "Kohler")); - } + [Fact] + public void PositionOfParabolicComet() + { + Assert.Equal((23, 17, 11.53, -33, 42, 26.42, 1.11), _paComet.PositionOfParabolicComet(0, 0, 0, false, 0, 25, 12, 1977, "Kohler")); } -} \ No newline at end of file +} diff --git a/PALib.Tests/PACoordinates.cs b/PALib.Tests/PACoordinates.cs index 798995d..b4b4391 100644 --- a/PALib.Tests/PACoordinates.cs +++ b/PALib.Tests/PACoordinates.cs @@ -1,151 +1,150 @@ using System; using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PACoordinates_Tests { - public class PACoordinates_Tests - { - private readonly PACoordinates _paCoordinates; - - public PACoordinates_Tests() - { - _paCoordinates = new PACoordinates(); - } - - [Fact] - public void AngleToDecimalDegrees() - { - Assert.Equal(182.524167, Math.Round(_paCoordinates.AngleToDecimalDegrees(182, 31, 27), 6)); - } - - [Fact] - public void DecimalDegreesToAngle() - { - Assert.Equal((182, 31, 27), _paCoordinates.DecimalDegreesToAngle(182.524167)); - } - - [Fact] - public void RightAscensionToHourAngle() - { - Assert.Equal((9, 52, 23.66), _paCoordinates.RightAscensionToHourAngle(18, 32, 21, 14, 36, 51.67, false, -4, 22, 4, 1980, -64)); - } - - [Fact] - public void HourAngleToRightAscension() - { - Assert.Equal((18, 32, 21), _paCoordinates.HourAngleToRightAscension(9, 52, 23.66, 14, 36, 51.67, false, -4, 22, 4, 1980, -64)); - } - - [Fact] - public void EquatorialCoordinatesToHorizonCoordinates() - { - Assert.Equal((283, 16, 15.7, 19, 20, 3.64), _paCoordinates.EquatorialCoordinatesToHorizonCoordinates(5, 51, 44, 23, 13, 10, 52)); - } - - [Fact] - public void HorizonCoordinatesToEquatorialCoordinates() - { - Assert.Equal((5, 51, 44, 23, 13, 10), _paCoordinates.HorizonCoordinatesToEquatorialCoordinates(283, 16, 15.7, 19, 20, 3.64, 52)); - } - - [Fact] - public void MeanObliquityOfTheEcliptic() - { - Assert.Equal(23.43805531, Math.Round(_paCoordinates.MeanObliquityOfTheEcliptic(6, 7, 2009), 8)); - } - - [Fact] - public void EclipticCoordinateToEquatorialCoordinate() - { - Assert.Equal((9, 34, 53.4, 19, 32, 8.52), _paCoordinates.EclipticCoordinateToEquatorialCoordinate(139, 41, 10, 4, 52, 31, 6, 7, 2009)); - } - - [Fact] - public void EquatorialCoordinateToEclipticCoordinate() - { - Assert.Equal((139, 41, 9.97, 4, 52, 30.99), _paCoordinates.EquatorialCoordinateToEclipticCoordinate(9, 34, 53.4, 19, 32, 8.52, 6, 7, 2009)); - } - - [Fact] - public void EquatorialCoordinateToGalacticCoordinate() - { - Assert.Equal((232, 14, 52.38, 51, 7, 20.16), _paCoordinates.EquatorialCoordinateToGalacticCoordinate(10, 21, 0, 10, 3, 11)); - } - - [Fact] - public void GalacticCoordinateToEquatorialCoordinate() - { - Assert.Equal((10, 21, 0, 10, 3, 11), _paCoordinates.GalacticCoordinateToEquatorialCoordinate(232, 14, 52.38, 51, 7, 20.16)); - } - - [Fact] - public void AngleBetweenTwoObjects() - { - Assert.Equal((23, 40, 25.86), _paCoordinates.AngleBetweenTwoObjects(5, 13, 31.7, -8, 13, 30, 6, 44, 13.4, -16, 41, 11, PAAngleMeasure.Hours)); - } - - [Fact] - public void RisingAndSetting() - { - Assert.Equal(("OK", 14, 16, 4, 10, 64.36, 295.64), _paCoordinates.RisingAndSetting(23, 39, 20, 21, 42, 0, 24, 8, 2010, 64, 30, 0.5667)); - } - - [Fact] - public void CorrectForPrecession() - { - Assert.Equal((9, 12, 20.18, 14, 16, 9.12), _paCoordinates.CorrectForPrecession(9, 10, 43, 14, 23, 25, 0.923, 1, 1950, 1, 6, 1979)); - } - - [Fact] - public void NutationInEclipticLongitudeAndObliquity() - { - var result = _paCoordinates.NutationInEclipticLongitudeAndObliquity(1, 9, 1988); - - Assert.Equal((0.001525808, 0.0025671), (Math.Round(result.nutInLongDeg, 9), Math.Round(result.nutInOblDeg, 7))); - } - - [Fact] - public void CorrectForAberration() - { - Assert.Equal((352, 37, 30.45, -1, 32, 56.33), _paCoordinates.CorrectForAberration(0, 0, 0, 8, 9, 1988, 352, 37, 10.1, -1, 32, 56.4)); - } - - [Fact] - public void AtmosphericRefraction() - { - Assert.Equal((23, 13, 44.74, 40, 19, 45.76), _paCoordinates.AtmosphericRefraction(23, 14, 0, 40, 10, 0, PACoordinateType.True, 0.17, 51.2036110, 0, 0, 23, 3, 1987, 1, 1, 24, 1012, 21.7)); - } - - [Fact] - public void CorrectionsForGeocentricParallax() - { - var result = _paCoordinates.CorrectionsForGeocentricParallax(22, 35, 19, -7, 41, 13, PACoordinateType.True, 1.019167, -100, 50, 60, 0, -6, 26, 2, 1979, 10, 45, 0); - - Assert.Equal((22, 36, 43.22, -8, 32, 17.4), result); - } - - [Fact] - public void HeliographicCoordinates() - { - Assert.Equal((142.59, -19.94), _paCoordinates.HeliographicCoordinates(220, 10.5, 1, 5, 1988)); - } - - [Fact] - public void CarringtonRotationNumber() - { - Assert.Equal(1624, _paCoordinates.CarringtonRotationNumber(27, 1, 1975)); - } - - [Fact] - public void SelenographicCoordinates1() - { - Assert.Equal((-4.88, 4.04, 19.78), _paCoordinates.SelenographicCoordinates1(1, 5, 1988)); - } - - [Fact] - public void SelenographicCoordinates2() - { - Assert.Equal((6.81, 83.19, 1.19), _paCoordinates.SelenographicCoordinates2(1, 5, 1988)); - } - } -} \ No newline at end of file + private readonly PACoordinates _paCoordinates; + + public PACoordinates_Tests() + { + _paCoordinates = new PACoordinates(); + } + + [Fact] + public void AngleToDecimalDegrees() + { + Assert.Equal(182.524167, Math.Round(_paCoordinates.AngleToDecimalDegrees(182, 31, 27), 6)); + } + + [Fact] + public void DecimalDegreesToAngle() + { + Assert.Equal((182, 31, 27), _paCoordinates.DecimalDegreesToAngle(182.524167)); + } + + [Fact] + public void RightAscensionToHourAngle() + { + Assert.Equal((9, 52, 23.66), _paCoordinates.RightAscensionToHourAngle(18, 32, 21, 14, 36, 51.67, false, -4, 22, 4, 1980, -64)); + } + + [Fact] + public void HourAngleToRightAscension() + { + Assert.Equal((18, 32, 21), _paCoordinates.HourAngleToRightAscension(9, 52, 23.66, 14, 36, 51.67, false, -4, 22, 4, 1980, -64)); + } + + [Fact] + public void EquatorialCoordinatesToHorizonCoordinates() + { + Assert.Equal((283, 16, 15.7, 19, 20, 3.64), _paCoordinates.EquatorialCoordinatesToHorizonCoordinates(5, 51, 44, 23, 13, 10, 52)); + } + + [Fact] + public void HorizonCoordinatesToEquatorialCoordinates() + { + Assert.Equal((5, 51, 44, 23, 13, 10), _paCoordinates.HorizonCoordinatesToEquatorialCoordinates(283, 16, 15.7, 19, 20, 3.64, 52)); + } + + [Fact] + public void MeanObliquityOfTheEcliptic() + { + Assert.Equal(23.43805531, Math.Round(_paCoordinates.MeanObliquityOfTheEcliptic(6, 7, 2009), 8)); + } + + [Fact] + public void EclipticCoordinateToEquatorialCoordinate() + { + Assert.Equal((9, 34, 53.4, 19, 32, 8.52), _paCoordinates.EclipticCoordinateToEquatorialCoordinate(139, 41, 10, 4, 52, 31, 6, 7, 2009)); + } + + [Fact] + public void EquatorialCoordinateToEclipticCoordinate() + { + Assert.Equal((139, 41, 9.97, 4, 52, 30.99), _paCoordinates.EquatorialCoordinateToEclipticCoordinate(9, 34, 53.4, 19, 32, 8.52, 6, 7, 2009)); + } + + [Fact] + public void EquatorialCoordinateToGalacticCoordinate() + { + Assert.Equal((232, 14, 52.38, 51, 7, 20.16), _paCoordinates.EquatorialCoordinateToGalacticCoordinate(10, 21, 0, 10, 3, 11)); + } + + [Fact] + public void GalacticCoordinateToEquatorialCoordinate() + { + Assert.Equal((10, 21, 0, 10, 3, 11), _paCoordinates.GalacticCoordinateToEquatorialCoordinate(232, 14, 52.38, 51, 7, 20.16)); + } + + [Fact] + public void AngleBetweenTwoObjects() + { + Assert.Equal((23, 40, 25.86), _paCoordinates.AngleBetweenTwoObjects(5, 13, 31.7, -8, 13, 30, 6, 44, 13.4, -16, 41, 11, PAAngleMeasure.Hours)); + } + + [Fact] + public void RisingAndSetting() + { + Assert.Equal(("OK", 14, 16, 4, 10, 64.36, 295.64), _paCoordinates.RisingAndSetting(23, 39, 20, 21, 42, 0, 24, 8, 2010, 64, 30, 0.5667)); + } + + [Fact] + public void CorrectForPrecession() + { + Assert.Equal((9, 12, 20.18, 14, 16, 9.12), _paCoordinates.CorrectForPrecession(9, 10, 43, 14, 23, 25, 0.923, 1, 1950, 1, 6, 1979)); + } + + [Fact] + public void NutationInEclipticLongitudeAndObliquity() + { + var result = _paCoordinates.NutationInEclipticLongitudeAndObliquity(1, 9, 1988); + + Assert.Equal((0.001525808, 0.0025671), (Math.Round(result.nutInLongDeg, 9), Math.Round(result.nutInOblDeg, 7))); + } + + [Fact] + public void CorrectForAberration() + { + Assert.Equal((352, 37, 30.45, -1, 32, 56.33), _paCoordinates.CorrectForAberration(0, 0, 0, 8, 9, 1988, 352, 37, 10.1, -1, 32, 56.4)); + } + + [Fact] + public void AtmosphericRefraction() + { + Assert.Equal((23, 13, 44.74, 40, 19, 45.76), _paCoordinates.AtmosphericRefraction(23, 14, 0, 40, 10, 0, PACoordinateType.True, 0.17, 51.2036110, 0, 0, 23, 3, 1987, 1, 1, 24, 1012, 21.7)); + } + + [Fact] + public void CorrectionsForGeocentricParallax() + { + var result = _paCoordinates.CorrectionsForGeocentricParallax(22, 35, 19, -7, 41, 13, PACoordinateType.True, 1.019167, -100, 50, 60, 0, -6, 26, 2, 1979, 10, 45, 0); + + Assert.Equal((22, 36, 43.22, -8, 32, 17.4), result); + } + + [Fact] + public void HeliographicCoordinates() + { + Assert.Equal((142.59, -19.94), _paCoordinates.HeliographicCoordinates(220, 10.5, 1, 5, 1988)); + } + + [Fact] + public void CarringtonRotationNumber() + { + Assert.Equal(1624, _paCoordinates.CarringtonRotationNumber(27, 1, 1975)); + } + + [Fact] + public void SelenographicCoordinates1() + { + Assert.Equal((-4.88, 4.04, 19.78), _paCoordinates.SelenographicCoordinates1(1, 5, 1988)); + } + + [Fact] + public void SelenographicCoordinates2() + { + Assert.Equal((6.81, 83.19, 1.19), _paCoordinates.SelenographicCoordinates2(1, 5, 1988)); + } +} diff --git a/PALib.Tests/PADateTime.cs b/PALib.Tests/PADateTime.cs index 7afbaf1..e7004b0 100644 --- a/PALib.Tests/PADateTime.cs +++ b/PALib.Tests/PADateTime.cs @@ -1,80 +1,79 @@ using System; using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PADateTime_Tests { - public class PADateTime_Tests - { - private readonly PADateTime _paDateTime; + private readonly PADateTime _paDateTime; - public PADateTime_Tests() - { - _paDateTime = new PADateTime(); - } + public PADateTime_Tests() + { + _paDateTime = new PADateTime(); + } - [Fact] - public void GetDateOfEaster() - { - Assert.Equal((4, 20, 2003), _paDateTime.GetDateOfEaster(2003)); - Assert.Equal((4, 21, 2019), _paDateTime.GetDateOfEaster(2019)); - Assert.Equal((4, 12, 2020), _paDateTime.GetDateOfEaster(2020)); - } + [Fact] + public void GetDateOfEaster() + { + Assert.Equal((4, 20, 2003), _paDateTime.GetDateOfEaster(2003)); + Assert.Equal((4, 21, 2019), _paDateTime.GetDateOfEaster(2019)); + Assert.Equal((4, 12, 2020), _paDateTime.GetDateOfEaster(2020)); + } - [Fact] - public void CivilDateToDayNumber() - { - Assert.Equal(1, _paDateTime.CivilDateToDayNumber(1, 1, 2000)); - Assert.Equal(61, _paDateTime.CivilDateToDayNumber(3, 1, 2000)); - Assert.Equal(152, _paDateTime.CivilDateToDayNumber(6, 1, 2003)); - Assert.Equal(331, _paDateTime.CivilDateToDayNumber(11, 27, 2009)); - } + [Fact] + public void CivilDateToDayNumber() + { + Assert.Equal(1, _paDateTime.CivilDateToDayNumber(1, 1, 2000)); + Assert.Equal(61, _paDateTime.CivilDateToDayNumber(3, 1, 2000)); + Assert.Equal(152, _paDateTime.CivilDateToDayNumber(6, 1, 2003)); + Assert.Equal(331, _paDateTime.CivilDateToDayNumber(11, 27, 2009)); + } - [Fact] - public void CivilTimeToDecimalHours() - { - Assert.Equal(18.52416667, Math.Round(_paDateTime.CivilTimeToDecimalHours(18, 31, 27), 8)); - } + [Fact] + public void CivilTimeToDecimalHours() + { + Assert.Equal(18.52416667, Math.Round(_paDateTime.CivilTimeToDecimalHours(18, 31, 27), 8)); + } - [Fact] - public void DecimalHoursToCivilTime() - { - Assert.Equal((18, 31, 27), _paDateTime.DecimalHoursToCivilTime(18.52416667)); - } + [Fact] + public void DecimalHoursToCivilTime() + { + Assert.Equal((18, 31, 27), _paDateTime.DecimalHoursToCivilTime(18.52416667)); + } - [Fact] - public void LocalCivilTimeToUniversalTime() - { - Assert.Equal((22, 37, 0, 30, 6, 2013), _paDateTime.LocalCivilTimeToUniversalTime(3, 37, 0, true, 4, 1, 7, 2013)); - } + [Fact] + public void LocalCivilTimeToUniversalTime() + { + Assert.Equal((22, 37, 0, 30, 6, 2013), _paDateTime.LocalCivilTimeToUniversalTime(3, 37, 0, true, 4, 1, 7, 2013)); + } - [Fact] - public void UniversalTimeToLocalCivilTime() - { - Assert.Equal((3, 37, 0, 1, 7, 2013), _paDateTime.UniversalTimeToLocalCivilTime(22, 37, 0, true, 4, 30, 6, 2013)); - } + [Fact] + public void UniversalTimeToLocalCivilTime() + { + Assert.Equal((3, 37, 0, 1, 7, 2013), _paDateTime.UniversalTimeToLocalCivilTime(22, 37, 0, true, 4, 30, 6, 2013)); + } - [Fact] - public void UniversalTimeToGreenwichSiderealTime() - { - Assert.Equal((4, 40, 5.23), _paDateTime.UniversalTimeToGreenwichSiderealTime(14, 36, 51.67, 22, 4, 1980)); - } + [Fact] + public void UniversalTimeToGreenwichSiderealTime() + { + Assert.Equal((4, 40, 5.23), _paDateTime.UniversalTimeToGreenwichSiderealTime(14, 36, 51.67, 22, 4, 1980)); + } - [Fact] - public void GreenwichSiderealTimeToUniversalTime() - { - Assert.Equal((14, 36, 51.67, PAWarningFlag.OK), _paDateTime.GreenwichSiderealTimeToUniversalTime(4, 40, 5.23, 22, 4, 1980)); - } + [Fact] + public void GreenwichSiderealTimeToUniversalTime() + { + Assert.Equal((14, 36, 51.67, PAWarningFlag.OK), _paDateTime.GreenwichSiderealTimeToUniversalTime(4, 40, 5.23, 22, 4, 1980)); + } - [Fact] - public void GreenwichSiderealTimeToLocalSiderealTime() - { - Assert.Equal((0, 24, 5.23), _paDateTime.GreenwichSiderealTimeToLocalSiderealTime(4, 40, 5.23, -64)); - } + [Fact] + public void GreenwichSiderealTimeToLocalSiderealTime() + { + Assert.Equal((0, 24, 5.23), _paDateTime.GreenwichSiderealTimeToLocalSiderealTime(4, 40, 5.23, -64)); + } - [Fact] - public void LocalSiderealTimeToGreenwichSiderealTime() - { - Assert.Equal((4, 40, 5.23), _paDateTime.LocalSiderealTimeToGreenwichSiderealTime(0, 24, 5.23, -64)); - } + [Fact] + public void LocalSiderealTimeToGreenwichSiderealTime() + { + Assert.Equal((4, 40, 5.23), _paDateTime.LocalSiderealTimeToGreenwichSiderealTime(0, 24, 5.23, -64)); } } diff --git a/PALib.Tests/PAEclipses.cs b/PALib.Tests/PAEclipses.cs index 4902bbb..807f48f 100644 --- a/PALib.Tests/PAEclipses.cs +++ b/PALib.Tests/PAEclipses.cs @@ -1,38 +1,37 @@ using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PAEclipses_Tests { - public class PAEclipses_Tests - { - private readonly PAEclipses _paEclipses; + private readonly PAEclipses _paEclipses; - public PAEclipses_Tests() - { - _paEclipses = new PAEclipses(); - } + public PAEclipses_Tests() + { + _paEclipses = new PAEclipses(); + } - [Fact] - public void LunarEclipseOccurrence() - { - Assert.Equal(("Lunar eclipse certain", 4, 4, 2015), _paEclipses.LunarEclipseOccurrence(1, 4, 2015, false, 10)); - } + [Fact] + public void LunarEclipseOccurrence() + { + Assert.Equal(("Lunar eclipse certain", 4, 4, 2015), _paEclipses.LunarEclipseOccurrence(1, 4, 2015, false, 10)); + } - [Fact] - public void LunarEclipseCircumstances() - { - Assert.Equal((4, 4, 2015, 9, 0, 10, 16, 11, 55, 12, 1, 12, 7, 13, 46, 15, 1, 1.01), _paEclipses.LunarEclipseCircumstances(1, 4, 2015, false, 10)); - } + [Fact] + public void LunarEclipseCircumstances() + { + Assert.Equal((4, 4, 2015, 9, 0, 10, 16, 11, 55, 12, 1, 12, 7, 13, 46, 15, 1, 1.01), _paEclipses.LunarEclipseCircumstances(1, 4, 2015, false, 10)); + } - [Fact] - public void SolarEclipseOccurrence() - { - Assert.Equal(("Solar eclipse certain", 20, 3, 2015), _paEclipses.SolarEclipseOccurrence(1, 4, 2015, false, 0)); - } + [Fact] + public void SolarEclipseOccurrence() + { + Assert.Equal(("Solar eclipse certain", 20, 3, 2015), _paEclipses.SolarEclipseOccurrence(1, 4, 2015, false, 0)); + } - [Fact] - public void SolarEclipseCircumstances() - { - Assert.Equal((20, 3, 2015, 8, 55, 9, 57, 10, 58, 1.016), _paEclipses.SolarEclipseCircumstances(20, 3, 2015, false, 0, 0, 68.65)); - } + [Fact] + public void SolarEclipseCircumstances() + { + Assert.Equal((20, 3, 2015, 8, 55, 9, 57, 10, 58, 1.016), _paEclipses.SolarEclipseCircumstances(20, 3, 2015, false, 0, 0, 68.65)); } -} \ No newline at end of file +} diff --git a/PALib.Tests/PAMoon.cs b/PALib.Tests/PAMoon.cs index 8cb9800..b7f0324 100644 --- a/PALib.Tests/PAMoon.cs +++ b/PALib.Tests/PAMoon.cs @@ -1,50 +1,49 @@ using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PAMoon_Tests { - public class PAMoon_Tests + private readonly PAMoon _paMoon; + + public PAMoon_Tests() + { + _paMoon = new PAMoon(); + } + + [Fact] + public void ApproximatePositionOfMoon() + { + Assert.Equal((14, 12, 42.31, -11, 31, 38.27), _paMoon.ApproximatePositionOfMoon(0, 0, 0, false, 0, 1, 9, 2003)); + } + + [Fact] + public void PrecisePositionOfMoon() + { + Assert.Equal((14, 12, 10.21, -11, 34, 57.83, 367964, 0.993191), _paMoon.PrecisePositionOfMoon(0, 0, 0, false, 0, 1, 9, 2003)); + } + + [Fact] + public void MoonPhase() + { + Assert.Equal((0.22, -71.58), _paMoon.MoonPhase(0, 0, 0, false, 0, 1, 9, 2003, PAAccuracyLevel.Approximate)); + } + + [Fact] + public void TimesOfNewMoonAndFullMoon() + { + Assert.Equal((17, 27, 27, 8, 2003, 16, 36, 10, 9, 2003), _paMoon.TimesOfNewMoonAndFullMoon(false, 0, 1, 9, 2003)); + } + + [Fact] + public void MoonDistAngDiamHorParallax() + { + Assert.Equal((367964, 0, 32, 0, 59, 35.49), _paMoon.MoonDistAngDiamHorParallax(0, 0, 0, false, 0, 1, 9, 2003)); + } + + [Fact] + public void MoonriseAndMoonset() { - private readonly PAMoon _paMoon; - - public PAMoon_Tests() - { - _paMoon = new PAMoon(); - } - - [Fact] - public void ApproximatePositionOfMoon() - { - Assert.Equal((14, 12, 42.31, -11, 31, 38.27), _paMoon.ApproximatePositionOfMoon(0, 0, 0, false, 0, 1, 9, 2003)); - } - - [Fact] - public void PrecisePositionOfMoon() - { - Assert.Equal((14, 12, 10.21, -11, 34, 57.83, 367964, 0.993191), _paMoon.PrecisePositionOfMoon(0, 0, 0, false, 0, 1, 9, 2003)); - } - - [Fact] - public void MoonPhase() - { - Assert.Equal((0.22, -71.58), _paMoon.MoonPhase(0, 0, 0, false, 0, 1, 9, 2003, PAAccuracyLevel.Approximate)); - } - - [Fact] - public void TimesOfNewMoonAndFullMoon() - { - Assert.Equal((17, 27, 27, 8, 2003, 16, 36, 10, 9, 2003), _paMoon.TimesOfNewMoonAndFullMoon(false, 0, 1, 9, 2003)); - } - - [Fact] - public void MoonDistAngDiamHorParallax() - { - Assert.Equal((367964, 0, 32, 0, 59, 35.49), _paMoon.MoonDistAngDiamHorParallax(0, 0, 0, false, 0, 1, 9, 2003)); - } - - [Fact] - public void MoonriseAndMoonset() - { - Assert.Equal((4, 21, 6, 3, 1986, 127.34, 13, 8, 6, 3, 1986, 234.05), _paMoon.MoonriseAndMoonset(6, 3, 1986, false, -5, -71.05, 42.3667)); - } + Assert.Equal((4, 21, 6, 3, 1986, 127.34, 13, 8, 6, 3, 1986, 234.05), _paMoon.MoonriseAndMoonset(6, 3, 1986, false, -5, -71.05, 42.3667)); } -} \ No newline at end of file +} diff --git a/PALib.Tests/PAPlanet.cs b/PALib.Tests/PAPlanet.cs index 8e64620..baa87cb 100644 --- a/PALib.Tests/PAPlanet.cs +++ b/PALib.Tests/PAPlanet.cs @@ -1,32 +1,31 @@ using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PAPlanet_Tests { - public class PAPlanet_Tests - { - private readonly PAPlanet _paPlanet; + private readonly PAPlanet _paPlanet; - public PAPlanet_Tests() - { - _paPlanet = new PAPlanet(); - } + public PAPlanet_Tests() + { + _paPlanet = new PAPlanet(); + } - [Fact] - public void ApproximatePositionOfPlanet() - { - Assert.Equal((11, 11, 13.8, 6, 21, 25.1), _paPlanet.ApproximatePositionOfPlanet(0, 0, 0, false, 0, 22, 11, 2003, "Jupiter")); - } + [Fact] + public void ApproximatePositionOfPlanet() + { + Assert.Equal((11, 11, 13.8, 6, 21, 25.1), _paPlanet.ApproximatePositionOfPlanet(0, 0, 0, false, 0, 22, 11, 2003, "Jupiter")); + } - [Fact] - public void PrecisePositionOfPlanet() - { - Assert.Equal((11, 10, 30.99, 6, 25, 49.46), _paPlanet.PrecisePositionOfPlanet(0, 0, 0, false, 0, 22, 11, 2003, "Jupiter")); - } + [Fact] + public void PrecisePositionOfPlanet() + { + Assert.Equal((11, 10, 30.99, 6, 25, 49.46), _paPlanet.PrecisePositionOfPlanet(0, 0, 0, false, 0, 22, 11, 2003, "Jupiter")); + } - [Fact] - public void VisualAspectsOfAPlanet() - { - Assert.Equal((5.59829, 35.1, 0.99, 0, 46, 33.32, 113.2, -2.0), _paPlanet.VisualAspectsOfAPlanet(0, 0, 0, false, 0, 22, 11, 2003, "Jupiter")); - } + [Fact] + public void VisualAspectsOfAPlanet() + { + Assert.Equal((5.59829, 35.1, 0.99, 0, 46, 33.32, 113.2, -2.0), _paPlanet.VisualAspectsOfAPlanet(0, 0, 0, false, 0, 22, 11, 2003, "Jupiter")); } -} \ No newline at end of file +} diff --git a/PALib.Tests/PASun.cs b/PALib.Tests/PASun.cs index fb06789..f3b24d7 100644 --- a/PALib.Tests/PASun.cs +++ b/PALib.Tests/PASun.cs @@ -1,57 +1,56 @@ using System; using Xunit; -namespace PALib.Tests +namespace PALib.Tests; + +public class PASun_Tests { - public class PASun_Tests - { - private readonly PASun _paSun; - - public PASun_Tests() - { - _paSun = new PASun(); - } - - [Fact] - public void ApproximatePositionOfSun() - { - Assert.Equal((8, 23, 33.73, 19, 21, 14.33), _paSun.ApproximatePositionOfSun(0, 0, 0, 27, 7, 2003, false, 0)); - } - - [Fact] - public void PrecisePositionOfSun() - { - Assert.Equal((8, 26, 3.83, 19, 12, 49.72), _paSun.PrecisePositionOfSun(0, 0, 0, 27, 7, 1988, false, 0)); - } - - [Fact] - public void SunDistanceAndAngularSize() - { - Assert.Equal((151920130, 0, 31, 29.93), _paSun.SunDistanceAndAngularSize(0, 0, 0, 27, 7, 1988, false, 0)); - } - - [Fact] - public void SunriseAndSunset() - { - Assert.Equal((6, 5, 17, 45, 94.83, 265.43, "OK"), _paSun.SunriseAndSunset(10, 3, 1986, false, -5, -71.05, 42.37)); - } - - [Fact] - public void MorningAndEveningTwilight() - { - Assert.Equal((3, 17, 20, 37, "OK"), _paSun.MorningAndEveningTwilight(7, 9, 1979, false, 0, 0, 52, PATwilightType.Astronomical)); - } - - [Fact] - public void EquationOfTime() - { - Assert.Equal((6, 31.52), _paSun.EquationOfTime(27, 7, 2010)); - } - - [Fact] - public void SolarElongation() - { - Assert.Equal(24.78, _paSun.SolarElongation(10, 6, 45, 11, 57, 27, 27.8333333, 7, 2010)); - } - } -} \ No newline at end of file + private readonly PASun _paSun; + + public PASun_Tests() + { + _paSun = new PASun(); + } + + [Fact] + public void ApproximatePositionOfSun() + { + Assert.Equal((8, 23, 33.73, 19, 21, 14.33), _paSun.ApproximatePositionOfSun(0, 0, 0, 27, 7, 2003, false, 0)); + } + + [Fact] + public void PrecisePositionOfSun() + { + Assert.Equal((8, 26, 3.83, 19, 12, 49.72), _paSun.PrecisePositionOfSun(0, 0, 0, 27, 7, 1988, false, 0)); + } + + [Fact] + public void SunDistanceAndAngularSize() + { + Assert.Equal((151920130, 0, 31, 29.93), _paSun.SunDistanceAndAngularSize(0, 0, 0, 27, 7, 1988, false, 0)); + } + + [Fact] + public void SunriseAndSunset() + { + Assert.Equal((6, 5, 17, 45, 94.83, 265.43, "OK"), _paSun.SunriseAndSunset(10, 3, 1986, false, -5, -71.05, 42.37)); + } + + [Fact] + public void MorningAndEveningTwilight() + { + Assert.Equal((3, 17, 20, 37, "OK"), _paSun.MorningAndEveningTwilight(7, 9, 1979, false, 0, 0, 52, PATwilightType.Astronomical)); + } + + [Fact] + public void EquationOfTime() + { + Assert.Equal((6, 31.52), _paSun.EquationOfTime(27, 7, 2010)); + } + + [Fact] + public void SolarElongation() + { + Assert.Equal(24.78, _paSun.SolarElongation(10, 6, 45, 11, 57, 27, 27.8333333, 7, 2010)); + } +} diff --git a/PALib/Data/BinaryData.cs b/PALib/Data/BinaryData.cs index e35c01f..2f5900a 100644 --- a/PALib/Data/BinaryData.cs +++ b/PALib/Data/BinaryData.cs @@ -1,64 +1,64 @@ using System.Collections.Generic; using System.Linq; -namespace PALib.Data +namespace PALib.Data; + +/// +/// Holds information about binary star systems. +/// +public class BinaryData { /// - /// Holds information about binary star systems. + /// Name of binary system. /// - public class BinaryData - { - /// - /// Name of binary system. - /// - public string Name { get; set; } - - /// - /// Period of the orbit. - /// - public double Period { get; set; } + public string Name { get; set; } - /// - /// Epoch of the perihelion. - /// - public double EpochPeri { get; set; } + /// + /// Period of the orbit. + /// + public double Period { get; set; } - /// - /// Longitude of the perihelion. - /// - public double LongPeri { get; set; } + /// + /// Epoch of the perihelion. + /// + public double EpochPeri { get; set; } - /// - /// Eccentricity of the orbit. - /// - public double Ecc { get; set; } + /// + /// Longitude of the perihelion. + /// + public double LongPeri { get; set; } - /// - /// Semi-major axis of the orbit. - /// - public double Axis { get; set; } + /// + /// Eccentricity of the orbit. + /// + public double Ecc { get; set; } - /// - /// Orbital inclination. - /// - public double Incl { get; set; } + /// + /// Semi-major axis of the orbit. + /// + public double Axis { get; set; } - /// - /// Position angle of the ascending node. - /// - public double PANode { get; set; } - } + /// + /// Orbital inclination. + /// + public double Incl { get; set; } /// - /// Binary star system data manager. + /// Position angle of the ascending node. /// - public static class BinaryInfo - { - static List _binaryData; + public double PANode { get; set; } +} + +/// +/// Binary star system data manager. +/// +public static class BinaryInfo +{ + static List _binaryData; - static BinaryInfo() - { - _binaryData = new List() + static BinaryInfo() + { + _binaryData = new List() { new BinaryData() { Name = "eta-Cor", @@ -161,20 +161,19 @@ static BinaryInfo() PANode = 273.0, } }; - } + } - /// - /// Retrieve information about a specific binary star system. - /// - /// - public static BinaryData GetBinaryInfo(string name) - { - var returnValue = _binaryData - .Where(x => x.Name == name) - .Select(x => x) - .FirstOrDefault(); + /// + /// Retrieve information about a specific binary star system. + /// + /// + public static BinaryData GetBinaryInfo(string name) + { + var returnValue = _binaryData + .Where(x => x.Name == name) + .Select(x => x) + .FirstOrDefault(); - return (returnValue == null) ? new BinaryData() { Name = "NotFound" } : returnValue; - } + return (returnValue == null) ? new BinaryData() { Name = "NotFound" } : returnValue; } -} \ No newline at end of file +} diff --git a/PALib/Data/CometData.cs b/PALib/Data/CometData.cs index bcaee19..3bb2cb5 100644 --- a/PALib/Data/CometData.cs +++ b/PALib/Data/CometData.cs @@ -1,110 +1,110 @@ using System.Collections.Generic; using System.Linq; -namespace PALib.Data +namespace PALib.Data; + +/// +/// Information about a comet with an elliptical orbit. +/// +public class CometDataElliptical { /// - /// Information about a comet with an elliptical orbit. + /// Name of comet /// - public class CometDataElliptical - { - /// - /// Name of comet - /// - public string Name { get; set; } - - /// - /// Epoch of the perihelion - /// - public double epoch_EpochOfPerihelion { get; set; } + public string Name { get; set; } - /// - /// Longitude of the perihelion - /// - public double peri_LongitudeOfPerihelion { get; set; } + /// + /// Epoch of the perihelion + /// + public double epoch_EpochOfPerihelion { get; set; } - /// - /// Longitude of the ascending node - /// - public double node_LongitudeOfAscendingNode { get; set; } + /// + /// Longitude of the perihelion + /// + public double peri_LongitudeOfPerihelion { get; set; } - /// - /// Period of the orbit - /// - public double period_PeriodOfOrbit { get; set; } + /// + /// Longitude of the ascending node + /// + public double node_LongitudeOfAscendingNode { get; set; } - /// - /// Semi-major axis of the orbit - /// - public double axis_SemiMajorAxisOfOrbit { get; set; } + /// + /// Period of the orbit + /// + public double period_PeriodOfOrbit { get; set; } - /// - /// Eccentricity of the orbit - /// - public double ecc_EccentricityOfOrbit { get; set; } + /// + /// Semi-major axis of the orbit + /// + public double axis_SemiMajorAxisOfOrbit { get; set; } - /// - /// Inclination of the orbit - /// - public double incl_InclinationOfOrbit { get; set; } - } + /// + /// Eccentricity of the orbit + /// + public double ecc_EccentricityOfOrbit { get; set; } /// - /// Information about a comet with a parabolic orbit. + /// Inclination of the orbit /// - public class CometDataParabolic - { - /// - /// Name of the comet - /// - public string Name { get; set; } + public double incl_InclinationOfOrbit { get; set; } +} - /// - /// Epoch perihelion day - /// - public double EpochPeriDay { get; set; } +/// +/// Information about a comet with a parabolic orbit. +/// +public class CometDataParabolic +{ + /// + /// Name of the comet + /// + public string Name { get; set; } - /// - /// Epoch perihelion month - /// - public int EpochPeriMonth { get; set; } + /// + /// Epoch perihelion day + /// + public double EpochPeriDay { get; set; } - /// - /// Epoch perihelion year - /// - public int EpochPeriYear { get; set; } + /// + /// Epoch perihelion month + /// + public int EpochPeriMonth { get; set; } - /// - /// Arg perihelion - /// - public double ArgPeri { get; set; } + /// + /// Epoch perihelion year + /// + public int EpochPeriYear { get; set; } - /// - /// Comet's node - /// - public double Node { get; set; } + /// + /// Arg perihelion + /// + public double ArgPeri { get; set; } - /// - /// Distance at the perihelion - /// - public double PeriDist { get; set; } + /// + /// Comet's node + /// + public double Node { get; set; } - /// - /// Inclination - /// - public double Incl { get; set; } - } + /// + /// Distance at the perihelion + /// + public double PeriDist { get; set; } /// - /// Data manager for comets with elliptical orbits. + /// Inclination /// - public static class CometInfoElliptical - { - static List _cometDataElliptical; + public double Incl { get; set; } +} + +/// +/// Data manager for comets with elliptical orbits. +/// +public static class CometInfoElliptical +{ + static List _cometDataElliptical; - static CometInfoElliptical() - { - _cometDataElliptical = new List() { + static CometInfoElliptical() + { + _cometDataElliptical = new List() { new CometDataElliptical() { Name = "Encke", epoch_EpochOfPerihelion = 1974.32, @@ -257,32 +257,32 @@ static CometInfoElliptical() } }; - } - - /// - /// Get information about a comet with an elliptical orbit. - /// - public static CometDataElliptical GetCometEllipticalInfo(string name) - { - var returnValue = _cometDataElliptical - .Where(x => x.Name == name) - .Select(x => x) - .FirstOrDefault(); - - return (returnValue == null) ? new CometDataElliptical() { Name = "NotFound" } : returnValue; - } } /// - /// Data manager for comets with parabolic orbits. + /// Get information about a comet with an elliptical orbit. /// - public static class CometInfoParabolic + public static CometDataElliptical GetCometEllipticalInfo(string name) { - static List _cometDataParabolic; + var returnValue = _cometDataElliptical + .Where(x => x.Name == name) + .Select(x => x) + .FirstOrDefault(); + + return (returnValue == null) ? new CometDataElliptical() { Name = "NotFound" } : returnValue; + } +} + +/// +/// Data manager for comets with parabolic orbits. +/// +public static class CometInfoParabolic +{ + static List _cometDataParabolic; - static CometInfoParabolic() - { - _cometDataParabolic = new List() { + static CometInfoParabolic() + { + _cometDataParabolic = new List() { new CometDataParabolic() { Name = "Kohler", EpochPeriDay = 10.5659, @@ -294,19 +294,18 @@ static CometInfoParabolic() Incl = 48.7196 } }; - } + } - /// - /// Get information about a comet with a parabolic orbit. - /// - public static CometDataParabolic GetCometParabolicInfo(string name) - { - var returnValue = _cometDataParabolic - .Where(x => x.Name == name) - .Select(x => x) - .FirstOrDefault(); + /// + /// Get information about a comet with a parabolic orbit. + /// + public static CometDataParabolic GetCometParabolicInfo(string name) + { + var returnValue = _cometDataParabolic + .Where(x => x.Name == name) + .Select(x => x) + .FirstOrDefault(); - return (returnValue == null) ? new CometDataParabolic() { Name = "NotFound" } : returnValue; - } + return (returnValue == null) ? new CometDataParabolic() { Name = "NotFound" } : returnValue; } -} \ No newline at end of file +} diff --git a/PALib/Data/PlanetData.cs b/PALib/Data/PlanetData.cs index 3ffe72e..3fdaa81 100644 --- a/PALib/Data/PlanetData.cs +++ b/PALib/Data/PlanetData.cs @@ -1,171 +1,171 @@ using System.Collections.Generic; using System.Linq; -namespace PALib.Data +namespace PALib.Data; + +/// +/// Information about a planet. +/// +public class PlanetData { /// - /// Information about a planet. + /// Name of planet. /// - public class PlanetData - { - /// - /// Name of planet. - /// - public string Name { get; set; } + public string Name { get; set; } - /// - /// Period of orbit. - /// - /// - /// Original element name: tp - /// - /// - public double tp_PeriodOrbit { get; set; } - - /// - /// Longitude at the epoch. - /// - /// - /// Original element name: long - /// - /// - public double long_LongitudeEpoch { get; set; } + /// + /// Period of orbit. + /// + /// + /// Original element name: tp + /// + /// + public double tp_PeriodOrbit { get; set; } - /// - /// Longitude of the perihelion. - /// - /// - /// Original element name: peri - /// - /// - public double peri_LongitudePerihelion { get; set; } + /// + /// Longitude at the epoch. + /// + /// + /// Original element name: long + /// + /// + public double long_LongitudeEpoch { get; set; } - /// - /// Eccentricity of the orbit. - /// - /// - /// Original element name: ecc - /// - /// - public double ecc_EccentricityOrbit { get; set; } + /// + /// Longitude of the perihelion. + /// + /// + /// Original element name: peri + /// + /// + public double peri_LongitudePerihelion { get; set; } - /// - /// Semi-major axis of the orbit. - /// - /// - /// Original element name: axis - /// - /// - public double axis_AxisOrbit { get; set; } + /// + /// Eccentricity of the orbit. + /// + /// + /// Original element name: ecc + /// + /// + public double ecc_EccentricityOrbit { get; set; } - /// - /// Orbital inclination. - /// - /// - /// Original element name: incl - /// - /// - public double incl_OrbitalInclination { get; set; } + /// + /// Semi-major axis of the orbit. + /// + /// + /// Original element name: axis + /// + /// + public double axis_AxisOrbit { get; set; } - /// - /// Longitude of the ascending node. - /// - /// - /// Original element name: node - /// - /// - public double node_LongitudeAscendingNode { get; set; } + /// + /// Orbital inclination. + /// + /// + /// Original element name: incl + /// + /// + public double incl_OrbitalInclination { get; set; } - /// - /// Angular diameter at 1 AU. - /// - /// - /// Original element name: theta0 - /// - /// - public double theta0_AngularDiameter { get; set; } + /// + /// Longitude of the ascending node. + /// + /// + /// Original element name: node + /// + /// + public double node_LongitudeAscendingNode { get; set; } - /// - /// Visual magnitude at 1 AU. - /// - /// - /// Original element name: v0 - /// - /// - public double v0_VisualMagnitude { get; set; } - } + /// + /// Angular diameter at 1 AU. + /// + /// + /// Original element name: theta0 + /// + /// + public double theta0_AngularDiameter { get; set; } /// - /// Working data for precise planet calculations. + /// Visual magnitude at 1 AU. /// - public class PlanetDataPrecise - { - /// - /// Name of planet. - /// - public string Name { get; set; } + /// + /// Original element name: v0 + /// + /// + public double v0_VisualMagnitude { get; set; } +} - /// - /// Working value 1. - /// - public double Value1 { get; set; } +/// +/// Working data for precise planet calculations. +/// +public class PlanetDataPrecise +{ + /// + /// Name of planet. + /// + public string Name { get; set; } - /// - /// Working value 2. - /// - public double Value2 { get; set; } + /// + /// Working value 1. + /// + public double Value1 { get; set; } - /// - /// Working value 3. - /// - public double Value3 { get; set; } + /// + /// Working value 2. + /// + public double Value2 { get; set; } - /// - /// Working value 4. - /// - public double Value4 { get; set; } + /// + /// Working value 3. + /// + public double Value3 { get; set; } - /// - /// Working value 5. - /// - public double Value5 { get; set; } + /// + /// Working value 4. + /// + public double Value4 { get; set; } - /// - /// Working value 6. - /// - public double Value6 { get; set; } + /// + /// Working value 5. + /// + public double Value5 { get; set; } - /// - /// Working value 7. - /// - public double Value7 { get; set; } + /// + /// Working value 6. + /// + public double Value6 { get; set; } - /// - /// Working value 8. - /// - public double Value8 { get; set; } + /// + /// Working value 7. + /// + public double Value7 { get; set; } - /// - /// Working value 9. - /// - public double Value9 { get; set; } + /// + /// Working value 8. + /// + public double Value8 { get; set; } - /// - /// Working AP value. - /// - public double APValue { get; set; } - } + /// + /// Working value 9. + /// + public double Value9 { get; set; } /// - /// Data manager for planets. + /// Working AP value. /// - public static class PlanetInfo - { - static List _planetData; + public double APValue { get; set; } +} + +/// +/// Data manager for planets. +/// +public static class PlanetInfo +{ + static List _planetData; - static PlanetInfo() - { - _planetData = new List() { + static PlanetInfo() + { + _planetData = new List() { new PlanetData() { Name = "Mercury", tp_PeriodOrbit = 0.24085, @@ -263,19 +263,18 @@ static PlanetInfo() v0_VisualMagnitude = -6.87 } }; - } + } - /// - /// Get information about a planet. - /// - public static PlanetData GetPlanetInfo(string name) - { - var returnValue = _planetData - .Where(x => x.Name == name) - .Select(x => x) - .FirstOrDefault(); + /// + /// Get information about a planet. + /// + public static PlanetData GetPlanetInfo(string name) + { + var returnValue = _planetData + .Where(x => x.Name == name) + .Select(x => x) + .FirstOrDefault(); - return (returnValue == null) ? new PlanetData() { Name = "NotFound" } : returnValue; - } + return (returnValue == null) ? new PlanetData() { Name = "NotFound" } : returnValue; } -} \ No newline at end of file +} diff --git a/PALib/Helpers/MathExtensions.cs b/PALib/Helpers/MathExtensions.cs index 0f91278..856a4a4 100644 --- a/PALib/Helpers/MathExtensions.cs +++ b/PALib/Helpers/MathExtensions.cs @@ -1,128 +1,127 @@ using System; -namespace PALib.Helpers +namespace PALib.Helpers; + +/// +/// Extension methods for mathematical calculations. +/// +public static class MathExtensions { /// - /// Extension methods for mathematical calculations. + /// Returns the angle whose cosine is the specified number. /// - public static class MathExtensions + /// + /// + public static double ACosine(this double d) { - /// - /// Returns the angle whose cosine is the specified number. - /// - /// - /// - public static double ACosine(this double d) - { - return Math.Acos(d); - } + return Math.Acos(d); + } - /// - /// Returns the angle whose tangent is the specified number. - /// - /// - /// - public static double AngleTangent(this double d) - { - return Math.Atan(d); - } + /// + /// Returns the angle whose tangent is the specified number. + /// + /// + /// + public static double AngleTangent(this double d) + { + return Math.Atan(d); + } - /// - /// Returns the angle whose tangent is the quotient of two specified numbers. - /// - /// - /// - /// - public static double AngleTangent2(this double y, double x) - { - return Math.Atan2(y, x); - } + /// + /// Returns the angle whose tangent is the quotient of two specified numbers. + /// + /// + /// + /// + public static double AngleTangent2(this double y, double x) + { + return Math.Atan2(y, x); + } - /// - /// Returns the angle whose sine is the specified number. - /// - /// - /// - public static double ASine(this double d) - { - return Math.Asin(d); - } + /// + /// Returns the angle whose sine is the specified number. + /// + /// + /// + public static double ASine(this double d) + { + return Math.Asin(d); + } - /// - /// Returns the cosine of the specified angle. - /// - public static double Cosine(this double d) - { - return Math.Cos(d); - } + /// + /// Returns the cosine of the specified angle. + /// + public static double Cosine(this double d) + { + return Math.Cos(d); + } - /// - /// Returns the largest integral value less than or equal to the specified double-precision floating-point number. - /// - /// - /// - public static double Floor(this double d) - { - return Math.Floor(d); - } + /// + /// Returns the largest integral value less than or equal to the specified double-precision floating-point number. + /// + /// + /// + public static double Floor(this double d) + { + return Math.Floor(d); + } - /// - /// Returns the base 10 logarithm of a specified number. - /// - /// - /// - public static double Log10(this double d) - { - return Math.Log10(d); + /// + /// Returns the base 10 logarithm of a specified number. + /// + /// + /// + public static double Log10(this double d) + { + return Math.Log10(d); - } + } - /// - /// Returns the sine of the specified angle. - /// - public static double Sine(this double a) - { - return Math.Sin(a); - } + /// + /// Returns the sine of the specified angle. + /// + public static double Sine(this double a) + { + return Math.Sin(a); + } - /// - /// Returns the square root of a specified number. - /// - /// - /// - public static double SquareRoot(this double d) - { - return Math.Sqrt(d); - } + /// + /// Returns the square root of a specified number. + /// + /// + /// + public static double SquareRoot(this double d) + { + return Math.Sqrt(d); + } - /// - /// Returns the tangent of the specified angle. - /// /// - /// - /// - public static double Tangent(this double a) - { - return Math.Tan(a); - } + /// + /// Returns the tangent of the specified angle. + /// /// + /// + /// + public static double Tangent(this double a) + { + return Math.Tan(a); + } - /// - /// Convert radians to degrees. - /// - /// - /// - public static double ToDegrees(this double radians) - { - return radians * Math.PI / 180; - } + /// + /// Convert radians to degrees. + /// + /// + /// + public static double ToDegrees(this double radians) + { + return radians * Math.PI / 180; + } - /// - /// Convert degrees to radians. - /// - /// - /// - public static double ToRadians(this double degrees) - { - return degrees * (Math.PI / 180); - } + /// + /// Convert degrees to radians. + /// + /// + /// + public static double ToRadians(this double degrees) + { + return degrees * (Math.PI / 180); } -} \ No newline at end of file +} diff --git a/PALib/PABinary.cs b/PALib/PABinary.cs index 4444ee9..de06e06 100644 --- a/PALib/PABinary.cs +++ b/PALib/PABinary.cs @@ -2,43 +2,42 @@ using PALib.Data; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Binary star calculations. +/// +public class PABinary { /// - /// Binary star calculations. + /// Calculate orbital data for binary star. /// - public class PABinary + /// + /// positionAngleDeg -- Position angle (degrees) + /// separationArcsec -- Separation of binary members (arcseconds) + /// + public (double positionAngleDeg, double separationArcsec) BinaryStarOrbit(double greenwichDateDay, int greenwichDateMonth, int greenwichDateYear, string binaryName) { - /// - /// Calculate orbital data for binary star. - /// - /// - /// positionAngleDeg -- Position angle (degrees) - /// separationArcsec -- Separation of binary members (arcseconds) - /// - public (double positionAngleDeg, double separationArcsec) BinaryStarOrbit(double greenwichDateDay, int greenwichDateMonth, int greenwichDateYear, string binaryName) - { - var binaryInfo = BinaryInfo.GetBinaryInfo(binaryName); + var binaryInfo = BinaryInfo.GetBinaryInfo(binaryName); - var yYears = (greenwichDateYear + (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0, 1, greenwichDateYear)) / 365.242191) - binaryInfo.EpochPeri; - var mDeg = 360 * yYears / binaryInfo.Period; - var mRad = (mDeg - 360 * (mDeg / 360).Floor()).ToRadians(); - var eccentricity = binaryInfo.Ecc; - var trueAnomalyRad = PAMacros.TrueAnomaly(mRad, eccentricity); - var rArcsec = (1 - eccentricity * (PAMacros.EccentricAnomaly(mRad, eccentricity)).Cosine()) * binaryInfo.Axis; - var taPeriRad = trueAnomalyRad + binaryInfo.LongPeri.ToRadians(); + var yYears = (greenwichDateYear + (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0, 1, greenwichDateYear)) / 365.242191) - binaryInfo.EpochPeri; + var mDeg = 360 * yYears / binaryInfo.Period; + var mRad = (mDeg - 360 * (mDeg / 360).Floor()).ToRadians(); + var eccentricity = binaryInfo.Ecc; + var trueAnomalyRad = PAMacros.TrueAnomaly(mRad, eccentricity); + var rArcsec = (1 - eccentricity * (PAMacros.EccentricAnomaly(mRad, eccentricity)).Cosine()) * binaryInfo.Axis; + var taPeriRad = trueAnomalyRad + binaryInfo.LongPeri.ToRadians(); - var y = (taPeriRad).Sine() * ((binaryInfo.Incl).ToRadians()).Cosine(); - var x = (taPeriRad).Cosine(); - var aDeg = PAMacros.Degrees(y.AngleTangent2(x)); - var thetaDeg1 = aDeg + binaryInfo.PANode; - var thetaDeg2 = thetaDeg1 - 360 * (thetaDeg1 / 360).Floor(); - var rhoArcsec = rArcsec * (taPeriRad).Cosine() / ((thetaDeg2 - binaryInfo.PANode).ToRadians()).Cosine(); + var y = (taPeriRad).Sine() * ((binaryInfo.Incl).ToRadians()).Cosine(); + var x = (taPeriRad).Cosine(); + var aDeg = PAMacros.Degrees(y.AngleTangent2(x)); + var thetaDeg1 = aDeg + binaryInfo.PANode; + var thetaDeg2 = thetaDeg1 - 360 * (thetaDeg1 / 360).Floor(); + var rhoArcsec = rArcsec * (taPeriRad).Cosine() / ((thetaDeg2 - binaryInfo.PANode).ToRadians()).Cosine(); - var positionAngleDeg = Math.Round(thetaDeg2, 1); - var separationArcsec = Math.Round(rhoArcsec, 2); + var positionAngleDeg = Math.Round(thetaDeg2, 1); + var separationArcsec = Math.Round(rhoArcsec, 2); - return (positionAngleDeg, separationArcsec); - } + return (positionAngleDeg, separationArcsec); } } \ No newline at end of file diff --git a/PALib/PAComet.cs b/PALib/PAComet.cs index 37739c7..0401889 100644 --- a/PALib/PAComet.cs +++ b/PALib/PAComet.cs @@ -2,116 +2,115 @@ using PALib.Data; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Comet calculations. +/// +public class PAComet { /// - /// Comet calculations. + /// Calculate position of an elliptical comet. /// - public class PAComet + /// + /// cometRAHour -- Right ascension of comet (hour part) + /// cometRAMin -- Right ascension of comet (minutes part) + /// cometDecDeg -- Declination of comet (degrees part) + /// cometDecMin -- Declination of comet (minutes part) + /// cometDistEarth -- Comet's distance from Earth (AU) + /// + public (double cometRAHour, double cometRAMin, double cometDecDeg, double cometDecMin, double cometDistEarth) PositionOfEllipticalComet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string cometName) { - /// - /// Calculate position of an elliptical comet. - /// - /// - /// cometRAHour -- Right ascension of comet (hour part) - /// cometRAMin -- Right ascension of comet (minutes part) - /// cometDecDeg -- Declination of comet (degrees part) - /// cometDecMin -- Declination of comet (minutes part) - /// cometDistEarth -- Comet's distance from Earth (AU) - /// - public (double cometRAHour, double cometRAMin, double cometDecDeg, double cometDecMin, double cometDistEarth) PositionOfEllipticalComet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string cometName) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var cometInfo = CometInfoElliptical.GetCometEllipticalInfo(cometName); - - var timeSinceEpochYears = (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0.0, 1, greenwichDateYear)) / 365.242191 + greenwichDateYear - cometInfo.epoch_EpochOfPerihelion; - var mcDeg = 360 * timeSinceEpochYears / cometInfo.period_PeriodOfOrbit; - var mcRad = (mcDeg - 360 * (mcDeg / 360).Floor()).ToRadians(); - var eccentricity = cometInfo.ecc_EccentricityOfOrbit; - var trueAnomalyDeg = PAMacros.Degrees(PAMacros.TrueAnomaly(mcRad, eccentricity)); - var lcDeg = trueAnomalyDeg + cometInfo.peri_LongitudeOfPerihelion; - var rAU = cometInfo.axis_SemiMajorAxisOfOrbit * (1 - eccentricity * eccentricity) / (1 + eccentricity * ((trueAnomalyDeg).ToRadians()).Cosine()); - var lcNodeRad = (lcDeg - cometInfo.node_LongitudeOfAscendingNode).ToRadians(); - var psiRad = ((lcNodeRad).Sine() * ((cometInfo.incl_InclinationOfOrbit).ToRadians()).Sine()).ASine(); - - var y = (lcNodeRad).Sine() * ((cometInfo.incl_InclinationOfOrbit).ToRadians()).Cosine(); - var x = (lcNodeRad).Cosine(); - - var ldDeg = PAMacros.Degrees(y.AngleTangent2(x)) + cometInfo.node_LongitudeOfAscendingNode; - var rdAU = rAU * (psiRad).Cosine(); - - var earthLongitudeLeDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear) + 180.0; - var earthRadiusVectorAU = PAMacros.SunDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var leLdRad = (earthLongitudeLeDeg - ldDeg).ToRadians(); - var aRad = (rdAU < earthRadiusVectorAU) ? (rdAU * (leLdRad).Sine()).AngleTangent2(earthRadiusVectorAU - rdAU * (leLdRad).Cosine()) : (earthRadiusVectorAU * (-leLdRad).Sine()).AngleTangent2(rdAU - earthRadiusVectorAU * (leLdRad).Cosine()); - - var cometLongDeg1 = (rdAU < earthRadiusVectorAU) ? 180.0 + earthLongitudeLeDeg + PAMacros.Degrees(aRad) : PAMacros.Degrees(aRad) + ldDeg; - var cometLongDeg = cometLongDeg1 - 360 * (cometLongDeg1 / 360).Floor(); - var cometLatDeg = PAMacros.Degrees((rdAU * (psiRad).Tangent() * ((cometLongDeg1 - ldDeg).ToRadians()).Sine() / (earthRadiusVectorAU * (-leLdRad).Sine())).AngleTangent()); - var cometRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)); - var cometDecDeg1 = PAMacros.EcDec(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); - var cometDistanceAU = (Math.Pow(earthRadiusVectorAU, 2) + Math.Pow(rAU, 2) - 2.0 * earthRadiusVectorAU * rAU * ((lcDeg - earthLongitudeLeDeg).ToRadians()).Cosine() * (psiRad).Cosine()).SquareRoot(); - - var cometRAHour = PAMacros.DecimalHoursHour(cometRAHours1 + 0.008333); - var cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours1 + 0.008333); - var cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1 + 0.008333); - var cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1 + 0.008333); - var cometDistEarth = Math.Round(cometDistanceAU, 2); - - return (cometRAHour, cometRAMin, cometDecDeg, cometDecMin, cometDistEarth); - } - - /// - /// Calculate position of a parabolic comet. - /// - /// - /// cometRAHour -- Right ascension of comet (hour part) - /// cometRAMin -- Right ascension of comet (minutes part) - /// cometRASec -- Right ascension of comet (seconds part) - /// cometDecDeg -- Declination of comet (degrees part) - /// cometDecMin -- Declination of comet (minutes part) - /// cometDecSec -- Declination of comet (seconds part) - /// cometDistEarth -- Comet's distance from Earth (AU) - /// - /// - public (double cometRAHour, double cometRAMin, double cometRASec, double cometDecDeg, double cometDecMin, double cometDecSec, double cometDistEarth) PositionOfParabolicComet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string cometName) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var cometInfo = CometInfoParabolic.GetCometParabolicInfo(cometName); - - var perihelionEpochDay = cometInfo.EpochPeriDay; - var perihelionEpochMonth = cometInfo.EpochPeriMonth; - var perihelionEpochYear = cometInfo.EpochPeriYear; - var qAU = cometInfo.PeriDist; - var inclinationDeg = cometInfo.Incl; - var perihelionDeg = cometInfo.ArgPeri; - var nodeDeg = cometInfo.Node; - - var cometLongLatDist = PAMacros.PCometLongLatDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, perihelionEpochDay, perihelionEpochMonth, perihelionEpochYear, qAU, inclinationDeg, perihelionDeg, nodeDeg); - - var cometRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)); - var cometDecDeg1 = PAMacros.EcDec(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); - - var cometRAHour = PAMacros.DecimalHoursHour(cometRAHours); - var cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours); - var cometRASec = PAMacros.DecimalHoursSecond(cometRAHours); - var cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1); - var cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1); - var cometDecSec = PAMacros.DecimalDegreesSeconds(cometDecDeg1); - var cometDistEarth = Math.Round(cometLongLatDist.cometDistAU, 2); - - return (cometRAHour, cometRAMin, cometRASec, cometDecDeg, cometDecMin, cometDecSec, cometDistEarth); - } + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var cometInfo = CometInfoElliptical.GetCometEllipticalInfo(cometName); + + var timeSinceEpochYears = (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0.0, 1, greenwichDateYear)) / 365.242191 + greenwichDateYear - cometInfo.epoch_EpochOfPerihelion; + var mcDeg = 360 * timeSinceEpochYears / cometInfo.period_PeriodOfOrbit; + var mcRad = (mcDeg - 360 * (mcDeg / 360).Floor()).ToRadians(); + var eccentricity = cometInfo.ecc_EccentricityOfOrbit; + var trueAnomalyDeg = PAMacros.Degrees(PAMacros.TrueAnomaly(mcRad, eccentricity)); + var lcDeg = trueAnomalyDeg + cometInfo.peri_LongitudeOfPerihelion; + var rAU = cometInfo.axis_SemiMajorAxisOfOrbit * (1 - eccentricity * eccentricity) / (1 + eccentricity * ((trueAnomalyDeg).ToRadians()).Cosine()); + var lcNodeRad = (lcDeg - cometInfo.node_LongitudeOfAscendingNode).ToRadians(); + var psiRad = ((lcNodeRad).Sine() * ((cometInfo.incl_InclinationOfOrbit).ToRadians()).Sine()).ASine(); + + var y = (lcNodeRad).Sine() * ((cometInfo.incl_InclinationOfOrbit).ToRadians()).Cosine(); + var x = (lcNodeRad).Cosine(); + + var ldDeg = PAMacros.Degrees(y.AngleTangent2(x)) + cometInfo.node_LongitudeOfAscendingNode; + var rdAU = rAU * (psiRad).Cosine(); + + var earthLongitudeLeDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear) + 180.0; + var earthRadiusVectorAU = PAMacros.SunDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var leLdRad = (earthLongitudeLeDeg - ldDeg).ToRadians(); + var aRad = (rdAU < earthRadiusVectorAU) ? (rdAU * (leLdRad).Sine()).AngleTangent2(earthRadiusVectorAU - rdAU * (leLdRad).Cosine()) : (earthRadiusVectorAU * (-leLdRad).Sine()).AngleTangent2(rdAU - earthRadiusVectorAU * (leLdRad).Cosine()); + + var cometLongDeg1 = (rdAU < earthRadiusVectorAU) ? 180.0 + earthLongitudeLeDeg + PAMacros.Degrees(aRad) : PAMacros.Degrees(aRad) + ldDeg; + var cometLongDeg = cometLongDeg1 - 360 * (cometLongDeg1 / 360).Floor(); + var cometLatDeg = PAMacros.Degrees((rdAU * (psiRad).Tangent() * ((cometLongDeg1 - ldDeg).ToRadians()).Sine() / (earthRadiusVectorAU * (-leLdRad).Sine())).AngleTangent()); + var cometRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)); + var cometDecDeg1 = PAMacros.EcDec(cometLongDeg, 0, 0, cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); + var cometDistanceAU = (Math.Pow(earthRadiusVectorAU, 2) + Math.Pow(rAU, 2) - 2.0 * earthRadiusVectorAU * rAU * ((lcDeg - earthLongitudeLeDeg).ToRadians()).Cosine() * (psiRad).Cosine()).SquareRoot(); + + var cometRAHour = PAMacros.DecimalHoursHour(cometRAHours1 + 0.008333); + var cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours1 + 0.008333); + var cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1 + 0.008333); + var cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1 + 0.008333); + var cometDistEarth = Math.Round(cometDistanceAU, 2); + + return (cometRAHour, cometRAMin, cometDecDeg, cometDecMin, cometDistEarth); + } + + /// + /// Calculate position of a parabolic comet. + /// + /// + /// cometRAHour -- Right ascension of comet (hour part) + /// cometRAMin -- Right ascension of comet (minutes part) + /// cometRASec -- Right ascension of comet (seconds part) + /// cometDecDeg -- Declination of comet (degrees part) + /// cometDecMin -- Declination of comet (minutes part) + /// cometDecSec -- Declination of comet (seconds part) + /// cometDistEarth -- Comet's distance from Earth (AU) + /// + /// + public (double cometRAHour, double cometRAMin, double cometRASec, double cometDecDeg, double cometDecMin, double cometDecSec, double cometDistEarth) PositionOfParabolicComet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string cometName) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var cometInfo = CometInfoParabolic.GetCometParabolicInfo(cometName); + + var perihelionEpochDay = cometInfo.EpochPeriDay; + var perihelionEpochMonth = cometInfo.EpochPeriMonth; + var perihelionEpochYear = cometInfo.EpochPeriYear; + var qAU = cometInfo.PeriDist; + var inclinationDeg = cometInfo.Incl; + var perihelionDeg = cometInfo.ArgPeri; + var nodeDeg = cometInfo.Node; + + var cometLongLatDist = PAMacros.PCometLongLatDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, perihelionEpochDay, perihelionEpochMonth, perihelionEpochYear, qAU, inclinationDeg, perihelionDeg, nodeDeg); + + var cometRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)); + var cometDecDeg1 = PAMacros.EcDec(cometLongLatDist.cometLongDeg, 0, 0, cometLongLatDist.cometLatDeg, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); + + var cometRAHour = PAMacros.DecimalHoursHour(cometRAHours); + var cometRAMin = PAMacros.DecimalHoursMinute(cometRAHours); + var cometRASec = PAMacros.DecimalHoursSecond(cometRAHours); + var cometDecDeg = PAMacros.DecimalDegreesDegrees(cometDecDeg1); + var cometDecMin = PAMacros.DecimalDegreesMinutes(cometDecDeg1); + var cometDecSec = PAMacros.DecimalDegreesSeconds(cometDecDeg1); + var cometDistEarth = Math.Round(cometLongLatDist.cometDistAU, 2); + + return (cometRAHour, cometRAMin, cometRASec, cometDecDeg, cometDecMin, cometDecSec, cometDistEarth); } -} \ No newline at end of file +} diff --git a/PALib/PACoordinates.cs b/PALib/PACoordinates.cs index 77e281f..9fe4acc 100644 --- a/PALib/PACoordinates.cs +++ b/PALib/PACoordinates.cs @@ -1,576 +1,575 @@ using System; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Coordinate system calculations and conversions. +/// +public class PACoordinates { /// - /// Coordinate system calculations and conversions. + /// Convert an Angle (degrees, minutes, and seconds) to Decimal Degrees + /// + /// Decimal Degrees (double) + public double AngleToDecimalDegrees(double degrees, double minutes, double seconds) + { + var a = Math.Abs(seconds) / 60; + var b = (Math.Abs(minutes) + a) / 60; + var c = Math.Abs(degrees) + b; + var d = (degrees < 0 || minutes < 0 || seconds < 0) ? -c : c; + + return d; + } + + /// + /// Convert Decimal Degrees to an Angle (degrees, minutes, and seconds) + /// + /// Tuple (degrees, minutes, seconds) + public (double degrees, double minutes, double seconds) DecimalDegreesToAngle(double decimalDegrees) + { + var unsignedDecimal = Math.Abs(decimalDegrees); + var totalSeconds = unsignedDecimal * 3600; + var seconds2DP = Math.Round(totalSeconds % 60, 2); + var correctedSeconds = (seconds2DP == 60) ? 0 : seconds2DP; + var correctedRemainder = (seconds2DP == 60) ? totalSeconds + 60 : totalSeconds; + var minutes = (correctedRemainder / 60).Floor() % 60; + var unsignedDegrees = (correctedRemainder / 3600).Floor(); + var signedDegrees = (decimalDegrees < 0) ? -1 * unsignedDegrees : unsignedDegrees; + + return (signedDegrees, minutes, correctedSeconds.Floor()); + } + + /// + /// Convert Right Ascension to Hour Angle + /// + /// Tuple (hourAngleHours, hourAngleMinutes, hourAngleSeconds) + public (double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds) RightAscensionToHourAngle(double raHours, double raMinutes, double raSeconds, double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSavings, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) + { + var daylightSaving = (isDaylightSavings) ? 1 : 0; + + var hourAngle = PAMacros.RightAscensionToHourAngle(raHours, raMinutes, raSeconds, lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear, geographicalLongitude); + + var hourAngleHours = PAMacros.DecimalHoursHour(hourAngle); + var hourAngleMinutes = PAMacros.DecimalHoursMinute(hourAngle); + var hourAngleSeconds = PAMacros.DecimalHoursSecond(hourAngle); + + return (hourAngleHours, hourAngleMinutes, hourAngleSeconds); + } + + /// + /// Convert Hour Angle to Right Ascension + /// + /// Tuple (rightAscensionHours, rightAscensionMinutes, rightAscensionSeconds) + public (double raHours, double raMinutes, double raSeconds) HourAngleToRightAscension(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var rightAscension = PAMacros.HourAngleToRightAscension(hourAngleHours, hourAngleMinutes, hourAngleSeconds, lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear, geographicalLongitude); + + var rightAscensionHours = PAMacros.DecimalHoursHour(rightAscension); + var rightAscensionMinutes = PAMacros.DecimalHoursMinute(rightAscension); + var rightAscensionSeconds = PAMacros.DecimalHoursSecond(rightAscension); + + return (rightAscensionHours, rightAscensionMinutes, rightAscensionSeconds); + } + + /// + /// Convert Equatorial Coordinates to Horizon Coordinates + /// + /// Tuple (azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds) + public (double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds) EquatorialCoordinatesToHorizonCoordinates(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double declinationDegrees, double declinationMinutes, double declinationSeconds, double geographicalLatitude) + { + var azimuthInDecimalDegrees = PAMacros.EquatorialCoordinatesToAzimuth(hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds, geographicalLatitude); + + var altitudeInDecimalDegrees = PAMacros.EquatorialCoordinatesToAltitude(hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds, geographicalLatitude); + + var azimuthDegrees = PAMacros.DecimalDegreesDegrees(azimuthInDecimalDegrees); + var azimuthMinutes = PAMacros.DecimalDegreesMinutes(azimuthInDecimalDegrees); + var azimuthSeconds = PAMacros.DecimalDegreesSeconds(azimuthInDecimalDegrees); + + var altitudeDegrees = PAMacros.DecimalDegreesDegrees(altitudeInDecimalDegrees); + var altitudeMinutes = PAMacros.DecimalDegreesMinutes(altitudeInDecimalDegrees); + var altitudeSeconds = PAMacros.DecimalDegreesSeconds(altitudeInDecimalDegrees); + + return (azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds); + } + + /// + /// Convert Horizon Coordinates to Equatorial Coordinates + /// + /// Tuple (hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds) + public (double hour_angle_hours, double hour_angle_minutes, double hour_angle_seconds, double declination_degrees, double declination_minutes, double declinationseconds) HorizonCoordinatesToEquatorialCoordinates(double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds, double geographicalLatitude) + { + var hourAngleInDecimalDegrees = PAMacros.HorizonCoordinatesToHourAngle(azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds, geographicalLatitude); + + var declinationInDecimalDegrees = PAMacros.HorizonCoordinatesToDeclination(azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds, geographicalLatitude); + + var hourAngleHours = PAMacros.DecimalHoursHour(hourAngleInDecimalDegrees); + var hourAngleMinutes = PAMacros.DecimalHoursMinute(hourAngleInDecimalDegrees); + var hourAngleSeconds = PAMacros.DecimalHoursSecond(hourAngleInDecimalDegrees); + + var declinationDegrees = PAMacros.DecimalDegreesDegrees(declinationInDecimalDegrees); + var declinationMinutes = PAMacros.DecimalDegreesMinutes(declinationInDecimalDegrees); + var declinationSeconds = PAMacros.DecimalDegreesSeconds(declinationInDecimalDegrees); + + return (hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds); + } + + /// + /// Calculate Mean Obliquity of the Ecliptic for a Greenwich Date + /// + public double MeanObliquityOfTheEcliptic(double greenwichDay, int greenwichMonth, int greenwichYear) + { + var jd = PAMacros.CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); + var mjd = jd - 2451545; + var t = mjd / 36525; + var de1 = t * (46.815 + t * (0.0006 - (t * 0.00181))); + var de2 = de1 / 3600; + + return 23.439292 - de2; + } + + /// + /// Convert Ecliptic Coordinates to Equatorial Coordinates + /// + /// Tuple (outRAHours, outRAMinutes, outRASeconds, outDecDegrees, outDecMinutes, outDecSeconds) + public (double outRAHours, double outRAMinutes, double outRASeconds, double outDecDegrees, double outDecMinutes, double outDecSeconds) EclipticCoordinateToEquatorialCoordinate(double eclipticLongitudeDegrees, double eclipticLongitudeMinutes, double eclipticLongitudeSeconds, double eclipticLatitudeDegrees, double eclipticLatitudeMinutes, double eclipticLatitudeSeconds, double greenwichDay, int greenwichMonth, int greenwichYear) + { + var eclonDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(eclipticLongitudeDegrees, eclipticLongitudeMinutes, eclipticLongitudeSeconds); + var eclatDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(eclipticLatitudeDegrees, eclipticLatitudeMinutes, eclipticLatitudeSeconds); + var eclonRad = eclonDeg.ToRadians(); + var eclatRad = eclatDeg.ToRadians(); + var obliqDeg = PAMacros.Obliq(greenwichDay, greenwichMonth, greenwichYear); + var obliqRad = obliqDeg.ToRadians(); + var sinDec = eclatRad.Sine() * obliqRad.Cosine() + eclatRad.Cosine() * obliqRad.Sine() * eclonRad.Sine(); + var decRad = sinDec.ASine(); + var decDeg = PAMacros.Degrees(decRad); + var y = eclonRad.Sine() * obliqRad.Cosine() - eclatRad.Tangent() * obliqRad.Sine(); + var x = eclonRad.Cosine(); + var raRad = y.AngleTangent2(x); + var raDeg1 = PAMacros.Degrees(raRad); + var raDeg2 = raDeg1 - 360 * (raDeg1 / 360).Floor(); + var raHours = PAMacros.DecimalDegreesToDegreeHours(raDeg2); + + var outRAHours = PAMacros.DecimalHoursHour(raHours); + var outRAMinutes = PAMacros.DecimalHoursMinute(raHours); + var outRASeconds = PAMacros.DecimalHoursSecond(raHours); + var outDecDegrees = PAMacros.DecimalDegreesDegrees(decDeg); + var outDecMinutes = PAMacros.DecimalDegreesMinutes(decDeg); + var outDecSeconds = PAMacros.DecimalDegreesSeconds(decDeg); + + return (outRAHours, outRAMinutes, outRASeconds, outDecDegrees, outDecMinutes, outDecSeconds); + } + + /// + /// Convert Equatorial Coordinates to Ecliptic Coordinates + /// + /// Tuple (outEclLongDeg, outEclLongMin, outEclLongSec, outEclLatDeg, outEclLatMin, outEclLatSec) + public (double outEclLongDeg, double outEclLongMin, double outEclLongSec, double outEclLatDeg, double outEclLatMin, double outEclLatSec) EquatorialCoordinateToEclipticCoordinate(double raHours, double raMinutes, double raSeconds, double decDegrees, double decMinutes, double decSeconds, double gwDay, int gwMonth, int gwYear) + { + var raDeg = PAMacros.DegreeHoursToDecimalDegrees(PAMacros.HMStoDH(raHours, raMinutes, raSeconds)); + var decDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDegrees, decMinutes, decSeconds); + var raRad = raDeg.ToRadians(); + var decRad = decDeg.ToRadians(); + var obliqDeg = PAMacros.Obliq(gwDay, gwMonth, gwYear); + var obliqRad = obliqDeg.ToRadians(); + var sinEclLat = decRad.Sine() * obliqRad.Cosine() - decRad.Cosine() * obliqRad.Sine() * raRad.Sine(); + var eclLatRad = sinEclLat.ASine(); + var eclLatDeg = PAMacros.Degrees(eclLatRad); + var y = raRad.Sine() * obliqRad.Cosine() + decRad.Tangent() * obliqRad.Sine(); + var x = raRad.Cosine(); + var eclLongRad = y.AngleTangent2(x); + var eclLongDeg1 = PAMacros.Degrees(eclLongRad); + var eclLongDeg2 = eclLongDeg1 - 360 * (eclLongDeg1 / 360).Floor(); + + var outEclLongDeg = PAMacros.DecimalDegreesDegrees(eclLongDeg2); + var outEclLongMin = PAMacros.DecimalDegreesMinutes(eclLongDeg2); + var outEclLongSec = PAMacros.DecimalDegreesSeconds(eclLongDeg2); + var outEclLatDeg = PAMacros.DecimalDegreesDegrees(eclLatDeg); + var outEclLatMin = PAMacros.DecimalDegreesMinutes(eclLatDeg); + var outEclLatSec = PAMacros.DecimalDegreesSeconds(eclLatDeg); + + return (outEclLongDeg, outEclLongMin, outEclLongSec, outEclLatDeg, outEclLatMin, outEclLatSec); + } + + /// + /// Convert Equatorial Coordinates to Galactic Coordinates + /// + /// Tuple (galLongDeg, galLongMin, galLongSec, galLatDeg, galLatMin, galLatSec) + public (double galLongDeg, double galLongMin, double galLongSec, double galLatDeg, double galLatMin, double galLatSec) EquatorialCoordinateToGalacticCoordinate(double raHours, double raMinutes, double raSeconds, double decDegrees, double decMinutes, double decSeconds) + { + var raDeg = PAMacros.DegreeHoursToDecimalDegrees(PAMacros.HMStoDH(raHours, raMinutes, raSeconds)); + var decDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDegrees, decMinutes, decSeconds); + var raRad = raDeg.ToRadians(); + var decRad = decDeg.ToRadians(); + var sinB = decRad.Cosine() * (27.4).ToRadians().Cosine() * (raRad - (192.25).ToRadians()).Cosine() + decRad.Sine() * (27.4).ToRadians().Sine(); + var bRadians = sinB.ASine(); + var bDeg = PAMacros.Degrees(bRadians); + var y = decRad.Sine() - sinB * (27.4).ToRadians().Sine(); + var x = decRad.Cosine() * (raRad - (192.25).ToRadians()).Sine() * (27.4).ToRadians().Cosine(); + var longDeg1 = PAMacros.Degrees(y.AngleTangent2(x)) + 33; + var longDeg2 = longDeg1 - 360 * (longDeg1 / 360).Floor(); + + var galLongDeg = PAMacros.DecimalDegreesDegrees(longDeg2); + var galLongMin = PAMacros.DecimalDegreesMinutes(longDeg2); + var galLongSec = PAMacros.DecimalDegreesSeconds(longDeg2); + var galLatDeg = PAMacros.DecimalDegreesDegrees(bDeg); + var galLatMin = PAMacros.DecimalDegreesMinutes(bDeg); + var galLatSec = PAMacros.DecimalDegreesSeconds(bDeg); + + return (galLongDeg, galLongMin, galLongSec, galLatDeg, galLatMin, galLatSec); + } + + /// + /// Convert Galactic Coordinates to Equatorial Coordinates + /// + /// Tuple (raHours, raMinutes, raSeconds, decDegrees, decMinutes, decSeconds) + public (double raHours, double raMinutes, double raSeconds, double decDegrees, double decMinutes, double decSeconds) GalacticCoordinateToEquatorialCoordinate(double galLongDeg, double galLongMin, double galLongSec, double galLatDeg, double galLatMin, double galLatSec) + { + var glongDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(galLongDeg, galLongMin, galLongSec); + var glatDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(galLatDeg, galLatMin, galLatSec); + var glongRad = glongDeg.ToRadians(); + var glatRad = glatDeg.ToRadians(); + var sinDec = glatRad.Cosine() * (27.4).ToRadians().Cosine() * (glongRad - (33.0).ToRadians()).Sine() + glatRad.Sine() * (27.4).ToRadians().Sine(); + var decRadians = sinDec.ASine(); + var decDeg = PAMacros.Degrees(decRadians); + var y = glatRad.Cosine() * (glongRad - (33.0).ToRadians()).Cosine(); + var x = glatRad.Sine() * ((27.4).ToRadians()).Cosine() - (glatRad).Cosine() * ((27.4).ToRadians()).Sine() * (glongRad - (33.0).ToRadians()).Sine(); + + var raDeg1 = PAMacros.Degrees(y.AngleTangent2(x)) + 192.25; + var raDeg2 = raDeg1 - 360 * (raDeg1 / 360).Floor(); + var raHours1 = PAMacros.DecimalDegreesToDegreeHours(raDeg2); + + var raHours = PAMacros.DecimalHoursHour(raHours1); + var raMinutes = PAMacros.DecimalHoursMinute(raHours1); + var raSeconds = PAMacros.DecimalHoursSecond(raHours1); + var decDegrees = PAMacros.DecimalDegreesDegrees(decDeg); + var decMinutes = PAMacros.DecimalDegreesMinutes(decDeg); + var decSeconds = PAMacros.DecimalDegreesSeconds(decDeg); + + return (raHours, raMinutes, raSeconds, decDegrees, decMinutes, decSeconds); + } + + /// + /// Calculate the angle between two celestial objects + /// + /// Tuple (angleDeg, angleMin, angleSec) + public (double angleDeg, double angleMin, double angleSec) AngleBetweenTwoObjects(double raLong1HourDeg, double raLong1Min, double raLong1Sec, double decLat1Deg, double decLat1Min, double decLat1Sec, double raLong2HourDeg, double raLong2Min, double raLong2Sec, double decLat2Deg, double decLat2Min, double decLat2Sec, PAAngleMeasure hourOrDegree) + { + var raLong1Decimal = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.HMStoDH(raLong1HourDeg, raLong1Min, raLong1Sec) : PAMacros.DegreesMinutesSecondsToDecimalDegrees(raLong1HourDeg, raLong1Min, raLong1Sec); + var raLong1Deg = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.DegreeHoursToDecimalDegrees(raLong1Decimal) : raLong1Decimal; + + var raLong1Rad = raLong1Deg.ToRadians(); + var decLat1Deg1 = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decLat1Deg, decLat1Min, decLat1Sec); + var decLat1Rad = decLat1Deg1.ToRadians(); + + var raLong2Decimal = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.HMStoDH(raLong2HourDeg, raLong2Min, raLong2Sec) : PAMacros.DegreesMinutesSecondsToDecimalDegrees(raLong2HourDeg, raLong2Min, raLong2Sec); + var raLong2Deg = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.DegreeHoursToDecimalDegrees(raLong2Decimal) : raLong2Decimal; + var raLong2Rad = raLong2Deg.ToRadians(); + var decLat2Deg1 = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decLat2Deg, decLat2Min, decLat2Sec); + var decLat2Rad = decLat2Deg1.ToRadians(); + + var cosD = decLat1Rad.Sine() * decLat2Rad.Sine() + decLat1Rad.Cosine() * decLat2Rad.Cosine() * (raLong1Rad - raLong2Rad).Cosine(); + var dRad = cosD.ACosine(); + var dDeg = PAMacros.Degrees(dRad); + + var angleDeg = PAMacros.DecimalDegreesDegrees(dDeg); + var angleMin = PAMacros.DecimalDegreesMinutes(dDeg); + var angleSec = PAMacros.DecimalDegreesSeconds(dDeg); + + return (angleDeg, angleMin, angleSec); + } + + + /// + /// Calculate rising and setting times for an object. + /// + /// Tuple (riseSetStatus, utRiseHour, utRiseMin, utSetHour, utSetMin, azRise, azSet) + public (string riseSetStatus, double utRiseHour, double utRiseMin, double utSetHour, double utSetMin, double azRise, double azSet) RisingAndSetting(double raHours, double raMinutes, double raSeconds, double decDeg, double decMin, double decSec, double gwDateDay, int gwDateMonth, int gwDateYear, double geogLongDeg, double geogLatDeg, double vertShiftDeg) + { + var raHours1 = PAMacros.HMStoDH(raHours, raMinutes, raSeconds); + var decRad = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDeg, decMin, decSec).ToRadians(); + var verticalDisplRadians = vertShiftDeg.ToRadians(); + var geoLatRadians = geogLatDeg.ToRadians(); + var cosH = -(verticalDisplRadians.Sine() + geoLatRadians.Sine() * decRad.Sine()) / (geoLatRadians.Cosine() * decRad.Cosine()); + var hHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.Degrees(cosH.ACosine())); + var lstRiseHours = (raHours1 - hHours) - 24 * ((raHours1 - hHours) / 24).Floor(); + var lstSetHours = (raHours1 + hHours) - 24 * ((raHours1 + hHours) / 24).Floor(); + var aDeg = PAMacros.Degrees((((decRad).Sine() + (verticalDisplRadians).Sine() * (geoLatRadians).Sine()) / ((verticalDisplRadians).Cosine() * (geoLatRadians).Cosine())).ACosine()); + var azRiseDeg = aDeg - 360 * (aDeg / 360).Floor(); + var azSetDeg = (360 - aDeg) - 360 * ((360 - aDeg) / 360).Floor(); + var utRiseHours1 = PAMacros.GreenwichSiderealTimeToUniversalTime(PAMacros.LocalSiderealTimeToGreenwichSiderealTime(lstRiseHours, 0, 0, geogLongDeg), 0, 0, gwDateDay, gwDateMonth, gwDateYear); + var utSetHours1 = PAMacros.GreenwichSiderealTimeToUniversalTime(PAMacros.LocalSiderealTimeToGreenwichSiderealTime(lstSetHours, 0, 0, geogLongDeg), 0, 0, gwDateDay, gwDateMonth, gwDateYear); + var utRiseAdjustedHours = utRiseHours1 + 0.008333; + var utSetAdjustedHours = utSetHours1 + 0.008333; + + var riseSetStatus = "OK"; + if (cosH > 1) + riseSetStatus = "never rises"; + if (cosH < -1) + riseSetStatus = "circumpolar"; + + var utRiseHour = (riseSetStatus == "OK") ? PAMacros.DecimalHoursHour(utRiseAdjustedHours) : 0; + var utRiseMin = (riseSetStatus == "OK") ? PAMacros.DecimalHoursMinute(utRiseAdjustedHours) : 0; + var utSetHour = (riseSetStatus == "OK") ? PAMacros.DecimalHoursHour(utSetAdjustedHours) : 0; + var utSetMin = (riseSetStatus == "OK") ? PAMacros.DecimalHoursMinute(utSetAdjustedHours) : 0; + var azRise = (riseSetStatus == "OK") ? Math.Round(azRiseDeg, 2) : 0; + var azSet = (riseSetStatus == "OK") ? Math.Round(azSetDeg, 2) : 0; + + return (riseSetStatus, utRiseHour, utRiseMin, utSetHour, utSetMin, azRise, azSet); + } + + /// + /// Calculate precession (corrected coordinates between two epochs) + /// + /// Tuple (correctedRAHour, correctedRAMinutes, correctedRASeconds, correctedDecDeg, correctedDecMinutes, correctedDecSeconds) + public (double correctedRAHour, double correctedRAMinutes, double correctedRASeconds, double correctedDecDeg, double correctedDecMinutes, double correctedDecSeconds) CorrectForPrecession(double raHour, double raMinutes, double raSeconds, double decDeg, double decMinutes, double decSeconds, double epoch1Day, int epoch1Month, int epoch1Year, double epoch2Day, int epoch2Month, int epoch2Year) + { + var ra1Rad = (PAMacros.DegreeHoursToDecimalDegrees(PAMacros.HMStoDH(raHour, raMinutes, raSeconds))).ToRadians(); + var dec1Rad = (PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDeg, decMinutes, decSeconds)).ToRadians(); + var tCenturies = (PAMacros.CivilDateToJulianDate(epoch1Day, epoch1Month, epoch1Year) - 2415020) / 36525; + var mSec = 3.07234 + (0.00186 * tCenturies); + var nArcsec = 20.0468 - (0.0085 * tCenturies); + var nYears = (PAMacros.CivilDateToJulianDate(epoch2Day, epoch2Month, epoch2Year) - PAMacros.CivilDateToJulianDate(epoch1Day, epoch1Month, epoch1Year)) / 365.25; + var s1Hours = ((mSec + (nArcsec * (ra1Rad).Sine() * (dec1Rad).Tangent() / 15)) * nYears) / 3600; + var ra2Hours = PAMacros.HMStoDH(raHour, raMinutes, raSeconds) + s1Hours; + var s2Deg = (nArcsec * (ra1Rad).Cosine() * nYears) / 3600; + var dec2Deg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDeg, decMinutes, decSeconds) + s2Deg; + + var correctedRAHour = PAMacros.DecimalHoursHour(ra2Hours); + var correctedRAMinutes = PAMacros.DecimalHoursMinute(ra2Hours); + var correctedRASeconds = PAMacros.DecimalHoursSecond(ra2Hours); + var correctedDecDeg = PAMacros.DecimalDegreesDegrees(dec2Deg); + var correctedDecMinutes = PAMacros.DecimalDegreesMinutes(dec2Deg); + var correctedDecSeconds = PAMacros.DecimalDegreesSeconds(dec2Deg); + + return (correctedRAHour, correctedRAMinutes, correctedRASeconds, correctedDecDeg, correctedDecMinutes, correctedDecSeconds); + } + + /// + /// Calculate nutation for two values: ecliptic longitude and obliquity, for a Greenwich date. + /// + /// Tuple (nutation in ecliptic longitude (degrees), nutation in obliquity (degrees)) + public (double nutInLongDeg, double nutInOblDeg) NutationInEclipticLongitudeAndObliquity(double greenwichDay, int greenwichMonth, int greenwichYear) + { + var jdDays = PAMacros.CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); + var tCenturies = (jdDays - 2415020) / 36525; + var aDeg = 100.0021358 * tCenturies; + var l1Deg = 279.6967 + (0.000303 * tCenturies * tCenturies); + var lDeg1 = l1Deg + 360 * (aDeg - aDeg.Floor()); + var lDeg2 = lDeg1 - 360 * (lDeg1 / 360).Floor(); + var lRad = lDeg2.ToRadians(); + var bDeg = 5.372617 * tCenturies; + var nDeg1 = 259.1833 - 360 * (bDeg - bDeg.Floor()); + var nDeg2 = nDeg1 - 360 * ((nDeg1 / 360).Floor()); + var nRad = nDeg2.ToRadians(); + var nutInLongArcsec = -17.2 * nRad.Sine() - 1.3 * (2 * lRad).Sine(); + var nutInOblArcsec = 9.2 * nRad.Cosine() + 0.5 * (2 * lRad).Cosine(); + + var nutInLongDeg = nutInLongArcsec / 3600; + var nutInOblDeg = nutInOblArcsec / 3600; + + return (nutInLongDeg, nutInOblDeg); + } + + /// + /// Correct ecliptic coordinates for the effects of aberration. + /// + /// + /// apparent ecliptic longitude (degrees, minutes, seconds), + /// apparent ecliptic latitude (degrees, minutes, seconds) + /// + public (double apparentEclLongDeg, double apparentEclLongMin, double apparentEclLongSec, double apparentEclLatDeg, double apparentEclLatMin, double apparentEclLatSec) CorrectForAberration(double utHour, double utMinutes, double utSeconds, double gwDay, int gwMonth, int gwYear, double trueEclLongDeg, double trueEclLongMin, double trueEclLongSec, double trueEclLatDeg, double trueEclLatMin, double trueEclLatSec) + { + var trueLongDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(trueEclLongDeg, trueEclLongMin, trueEclLongSec); + var trueLatDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(trueEclLatDeg, trueEclLatMin, trueEclLatSec); + var sunTrueLongDeg = PAMacros.SunLong(utHour, utMinutes, utSeconds, 0, 0, gwDay, gwMonth, gwYear); + var dlongArcsec = -20.5 * ((sunTrueLongDeg - trueLongDeg).ToRadians()).Cosine() / ((trueLatDeg).ToRadians()).Cosine(); + var dlatArcsec = -20.5 * ((sunTrueLongDeg - trueLongDeg).ToRadians()).Sine() * ((trueLatDeg).ToRadians()).Sine(); + var apparentLongDeg = trueLongDeg + (dlongArcsec / 3600); + var apparentLatDeg = trueLatDeg + (dlatArcsec / 3600); + + var apparentEclLongDeg = PAMacros.DecimalDegreesDegrees(apparentLongDeg); + var apparentEclLongMin = PAMacros.DecimalDegreesMinutes(apparentLongDeg); + var apparentEclLongSec = PAMacros.DecimalDegreesSeconds(apparentLongDeg); + var apparentEclLatDeg = PAMacros.DecimalDegreesDegrees(apparentLatDeg); + var apparentEclLatMin = PAMacros.DecimalDegreesMinutes(apparentLatDeg); + var apparentEclLatSec = PAMacros.DecimalDegreesSeconds(apparentLatDeg); + + return (apparentEclLongDeg, apparentEclLongMin, apparentEclLongSec, apparentEclLatDeg, apparentEclLatMin, apparentEclLatSec); + } + + + /// + /// Calculate corrected RA/Dec, accounting for atmospheric refraction. + /// + /// + /// NOTE: Valid values for coordinate_type are "TRUE" and "APPARENT". + /// + /// + /// corrected RA hours,minutes,seconds + /// corrected Declination degrees,minutes,seconds + /// + public (double correctedRAHour, double correctedRAMin, double correctedRASec, double correctedDecDeg, double correctedDecMin, double correctedDecSec) AtmosphericRefraction(double trueRAHour, double trueRAMin, double trueRASec, double trueDecDeg, double trueDecMin, double trueDecSec, PACoordinateType coordinateType, double geogLongDeg, double geogLatDeg, int daylightSavingHours, int timezoneHours, double lcdDay, int lcdMonth, int lcdYear, double lctHour, double lctMin, double lctSec, double atmosphericPressureMbar, double atmosphericTemperatureCelsius) + { + var haHour = PAMacros.RightAscensionToHourAngle(trueRAHour, trueRAMin, trueRASec, lctHour, lctMin, lctSec, daylightSavingHours, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); + var azimuthDeg = PAMacros.EquatorialCoordinatesToAzimuth(haHour, 0, 0, trueDecDeg, trueDecMin, trueDecSec, geogLatDeg); + var altitudeDeg = PAMacros.EquatorialCoordinatesToAltitude(haHour, 0, 0, trueDecDeg, trueDecMin, trueDecSec, geogLatDeg); + var correctedAltitudeDeg = PAMacros.Refract(altitudeDeg, coordinateType, atmosphericPressureMbar, atmosphericTemperatureCelsius); + + var correctedHAHour = PAMacros.HorizonCoordinatesToHourAngle(azimuthDeg, 0, 0, correctedAltitudeDeg, 0, 0, geogLatDeg); + var correctedRAHour1 = PAMacros.HourAngleToRightAscension(correctedHAHour, 0, 0, lctHour, lctMin, lctSec, daylightSavingHours, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); + var correctedDecDeg1 = PAMacros.HorizonCoordinatesToDeclination(azimuthDeg, 0, 0, correctedAltitudeDeg, 0, 0, geogLatDeg); + + var correctedRAHour = PAMacros.DecimalHoursHour(correctedRAHour1); + var correctedRAMin = PAMacros.DecimalHoursMinute(correctedRAHour1); + var correctedRASec = PAMacros.DecimalHoursSecond(correctedRAHour1); + var correctedDecDeg = PAMacros.DecimalDegreesDegrees(correctedDecDeg1); + var correctedDecMin = PAMacros.DecimalDegreesMinutes(correctedDecDeg1); + var correctedDecSec = PAMacros.DecimalDegreesSeconds(correctedDecDeg1); + + return (correctedRAHour, correctedRAMin, correctedRASec, correctedDecDeg, correctedDecMin, correctedDecSec); + } + + + /// + /// Calculate corrected RA/Dec, accounting for geocentric parallax. + /// + /// corrected RA hours,minutes,seconds and corrected Declination degrees,minutes,seconds + public (double correctedRAHour, double correctedRAMin, double correctedRASec, double correctedDecDeg, double correctedDecMin, double correctedDecSec) CorrectionsForGeocentricParallax(double raHour, double raMin, double raSec, double decDeg, double decMin, double decSec, PACoordinateType coordinateType, double equatorialHorParallaxDeg, double geogLongDeg, double geogLatDeg, double heightM, int daylightSaving, int timezoneHours, double lcdDay, int lcdMonth, int lcdYear, double lctHour, double lctMin, double lctSec) + { + var haHours = PAMacros.RightAscensionToHourAngle(raHour, raMin, raSec, lctHour, lctMin, lctSec, daylightSaving, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); + + var correctedHAHours = PAMacros.ParallaxHA(haHours, 0, 0, decDeg, decMin, decSec, coordinateType, geogLatDeg, heightM, equatorialHorParallaxDeg); + + var correctedRAHours = PAMacros.HourAngleToRightAscension(correctedHAHours, 0, 0, lctHour, lctMin, lctSec, daylightSaving, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); + + var correctedDecDeg1 = PAMacros.ParallaxDec(haHours, 0, 0, decDeg, decMin, decSec, coordinateType, geogLatDeg, heightM, equatorialHorParallaxDeg); + + var correctedRAHour = PAMacros.DecimalHoursHour(correctedRAHours); + var correctedRAMin = PAMacros.DecimalHoursMinute(correctedRAHours); + var correctedRASec = PAMacros.DecimalHoursSecond(correctedRAHours); + var correctedDecDeg = PAMacros.DecimalDegreesDegrees(correctedDecDeg1); + var correctedDecMin = PAMacros.DecimalDegreesMinutes(correctedDecDeg1); + var correctedDecSec = PAMacros.DecimalDegreesSeconds(correctedDecDeg1); + + return (correctedRAHour, correctedRAMin, correctedRASec, correctedDecDeg, correctedDecMin, correctedDecSec); + } + + /// + /// Calculate heliographic coordinates for a given Greenwich date, with a given heliographic position angle and heliographic displacement in arc minutes. + /// + /// heliographic longitude and heliographic latitude, in degrees + public (double helioLongDeg, double helioLatDeg) HeliographicCoordinates(double helioPositionAngleDeg, double helioDisplacementArcmin, double gwdateDay, int gwdateMonth, int gwdateYear) + { + var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); + var tCenturies = (julianDateDays - 2415020) / 36525; + var longAscNodeDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(74, 22, 0) + (84 * tCenturies / 60); + var sunLongDeg = PAMacros.SunLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var y = ((longAscNodeDeg - sunLongDeg).ToRadians()).Sine() * ((PAMacros.DegreesMinutesSecondsToDecimalDegrees(7, 15, 0)).ToRadians()).Cosine(); + var x = -((longAscNodeDeg - sunLongDeg).ToRadians()).Cosine(); + var aDeg = PAMacros.Degrees(y.AngleTangent2(x)); + var mDeg1 = 360 - (360 * (julianDateDays - 2398220) / 25.38); + var mDeg2 = mDeg1 - 360 * (mDeg1 / 360).Floor(); + var l0Deg1 = mDeg2 + aDeg; + var b0Rad = (((sunLongDeg - longAscNodeDeg).ToRadians()).Sine() * ((PAMacros.DegreesMinutesSecondsToDecimalDegrees(7, 15, 0)).ToRadians()).Sine()).ASine(); + var theta1Rad = (-((sunLongDeg).ToRadians()).Cosine() * ((PAMacros.Obliq(gwdateDay, gwdateMonth, gwdateYear)).ToRadians()).Tangent()).AngleTangent(); + var theta2Rad = (-((longAscNodeDeg - sunLongDeg).ToRadians()).Cosine() * ((PAMacros.DegreesMinutesSecondsToDecimalDegrees(7, 15, 0)).ToRadians()).Tangent()).AngleTangent(); + var pDeg = PAMacros.Degrees(theta1Rad + theta2Rad); + var rho1Deg = helioDisplacementArcmin / 60; + var rhoRad = (2 * rho1Deg / PAMacros.SunDia(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)).ASine() - (rho1Deg).ToRadians(); + var bRad = ((b0Rad).Sine() * (rhoRad).Cosine() + (b0Rad).Cosine() * (rhoRad).Sine() * ((pDeg - helioPositionAngleDeg).ToRadians()).Cosine()).ASine(); + var bDeg = PAMacros.Degrees(bRad); + var lDeg1 = PAMacros.Degrees(((rhoRad).Sine() * ((pDeg - helioPositionAngleDeg).ToRadians()).Sine() / (bRad).Cosine()).ASine()) + l0Deg1; + var lDeg2 = lDeg1 - 360 * (lDeg1 / 360).Floor(); + + var helioLongDeg = Math.Round(lDeg2, 2); + var helioLatDeg = Math.Round(bDeg, 2); + + return (helioLongDeg, helioLatDeg); + } + + /// + /// Calculate carrington rotation number for a Greenwich date + /// + /// carrington rotation number + public int CarringtonRotationNumber(double gwdateDay, int gwdateMonth, int gwdateYear) + { + var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); + + var crn = 1690 + (int)Math.Round((julianDateDays - 2444235.34) / 27.2753, 0); + + return crn; + } + + /// + /// Calculate selenographic (lunar) coordinates (sub-Earth) + /// + /// sub-earth longitude, sub-earth latitude, and position angle of pole + public (double subEarthLongitude, double subEarthLatitude, double positionAngleOfPole) SelenographicCoordinates1(double gwdateDay, int gwdateMonth, int gwdateYear) + { + var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); + var tCenturies = (julianDateDays - 2451545) / 36525; + var longAscNodeDeg = 125.044522 - 1934.136261 * tCenturies; + var f1 = 93.27191 + 483202.0175 * tCenturies; + var f2 = f1 - 360 * (f1 / 360).Floor(); + var geocentricMoonLongDeg = PAMacros.MoonLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var geocentricMoonLatRad = (PAMacros.MoonLat(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)).ToRadians(); + var inclinationRad = (PAMacros.DegreesMinutesSecondsToDecimalDegrees(1, 32, 32.7)).ToRadians(); + var nodeLongRad = (longAscNodeDeg - geocentricMoonLongDeg).ToRadians(); + var sinBe = -(inclinationRad).Cosine() * (geocentricMoonLatRad).Sine() + (inclinationRad).Sine() * (geocentricMoonLatRad).Cosine() * (nodeLongRad).Sine(); + var subEarthLatDeg = PAMacros.Degrees((sinBe).ASine()); + var aRad = (-(geocentricMoonLatRad).Sine() * (inclinationRad).Sine() - (geocentricMoonLatRad).Cosine() * (inclinationRad).Cosine() * (nodeLongRad).Sine()).AngleTangent2((geocentricMoonLatRad).Cosine() * (nodeLongRad).Cosine()); + var aDeg = PAMacros.Degrees(aRad); + var subEarthLongDeg1 = aDeg - f2; + var subEarthLongDeg2 = subEarthLongDeg1 - 360 * (subEarthLongDeg1 / 360).Floor(); + var subEarthLongDeg3 = (subEarthLongDeg2 > 180) ? subEarthLongDeg2 - 360 : subEarthLongDeg2; + var c1Rad = ((nodeLongRad).Cosine() * (inclinationRad).Sine() / ((geocentricMoonLatRad).Cosine() * (inclinationRad).Cosine() + (geocentricMoonLatRad).Sine() * (inclinationRad).Sine() * (nodeLongRad).Sine())).AngleTangent(); + var obliquityRad = (PAMacros.Obliq(gwdateDay, gwdateMonth, gwdateYear)).ToRadians(); + var c2Rad = ((obliquityRad).Sine() * ((geocentricMoonLongDeg).ToRadians()).Cosine() / ((obliquityRad).Sine() * (geocentricMoonLatRad).Sine() * ((geocentricMoonLongDeg).ToRadians()).Sine() - (obliquityRad).Cosine() * (geocentricMoonLatRad).Cosine())).AngleTangent(); + var cDeg = PAMacros.Degrees(c1Rad + c2Rad); + + var subEarthLongitude = Math.Round(subEarthLongDeg3, 2); + var subEarthLatitude = Math.Round(subEarthLatDeg, 2); + var positionAngleOfPole = Math.Round(cDeg, 2); + + return (subEarthLongitude, subEarthLatitude, positionAngleOfPole); + } + + /// + /// Calculate selenographic (lunar) coordinates (sub-Solar) /// - public class PACoordinates + /// sub-solar longitude, sub-solar colongitude, and sub-solar latitude + public (double subSolarLongitude, double subSolarColongitude, double subSolarLatitude) SelenographicCoordinates2(double gwdateDay, int gwdateMonth, int gwdateYear) { - /// - /// Convert an Angle (degrees, minutes, and seconds) to Decimal Degrees - /// - /// Decimal Degrees (double) - public double AngleToDecimalDegrees(double degrees, double minutes, double seconds) - { - var a = Math.Abs(seconds) / 60; - var b = (Math.Abs(minutes) + a) / 60; - var c = Math.Abs(degrees) + b; - var d = (degrees < 0 || minutes < 0 || seconds < 0) ? -c : c; - - return d; - } - - /// - /// Convert Decimal Degrees to an Angle (degrees, minutes, and seconds) - /// - /// Tuple (degrees, minutes, seconds) - public (double degrees, double minutes, double seconds) DecimalDegreesToAngle(double decimalDegrees) - { - var unsignedDecimal = Math.Abs(decimalDegrees); - var totalSeconds = unsignedDecimal * 3600; - var seconds2DP = Math.Round(totalSeconds % 60, 2); - var correctedSeconds = (seconds2DP == 60) ? 0 : seconds2DP; - var correctedRemainder = (seconds2DP == 60) ? totalSeconds + 60 : totalSeconds; - var minutes = (correctedRemainder / 60).Floor() % 60; - var unsignedDegrees = (correctedRemainder / 3600).Floor(); - var signedDegrees = (decimalDegrees < 0) ? -1 * unsignedDegrees : unsignedDegrees; - - return (signedDegrees, minutes, correctedSeconds.Floor()); - } - - /// - /// Convert Right Ascension to Hour Angle - /// - /// Tuple (hourAngleHours, hourAngleMinutes, hourAngleSeconds) - public (double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds) RightAscensionToHourAngle(double raHours, double raMinutes, double raSeconds, double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSavings, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) - { - var daylightSaving = (isDaylightSavings) ? 1 : 0; - - var hourAngle = PAMacros.RightAscensionToHourAngle(raHours, raMinutes, raSeconds, lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear, geographicalLongitude); - - var hourAngleHours = PAMacros.DecimalHoursHour(hourAngle); - var hourAngleMinutes = PAMacros.DecimalHoursMinute(hourAngle); - var hourAngleSeconds = PAMacros.DecimalHoursSecond(hourAngle); - - return (hourAngleHours, hourAngleMinutes, hourAngleSeconds); - } - - /// - /// Convert Hour Angle to Right Ascension - /// - /// Tuple (rightAscensionHours, rightAscensionMinutes, rightAscensionSeconds) - public (double raHours, double raMinutes, double raSeconds) HourAngleToRightAscension(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var rightAscension = PAMacros.HourAngleToRightAscension(hourAngleHours, hourAngleMinutes, hourAngleSeconds, lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear, geographicalLongitude); - - var rightAscensionHours = PAMacros.DecimalHoursHour(rightAscension); - var rightAscensionMinutes = PAMacros.DecimalHoursMinute(rightAscension); - var rightAscensionSeconds = PAMacros.DecimalHoursSecond(rightAscension); - - return (rightAscensionHours, rightAscensionMinutes, rightAscensionSeconds); - } - - /// - /// Convert Equatorial Coordinates to Horizon Coordinates - /// - /// Tuple (azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds) - public (double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds) EquatorialCoordinatesToHorizonCoordinates(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double declinationDegrees, double declinationMinutes, double declinationSeconds, double geographicalLatitude) - { - var azimuthInDecimalDegrees = PAMacros.EquatorialCoordinatesToAzimuth(hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds, geographicalLatitude); - - var altitudeInDecimalDegrees = PAMacros.EquatorialCoordinatesToAltitude(hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds, geographicalLatitude); - - var azimuthDegrees = PAMacros.DecimalDegreesDegrees(azimuthInDecimalDegrees); - var azimuthMinutes = PAMacros.DecimalDegreesMinutes(azimuthInDecimalDegrees); - var azimuthSeconds = PAMacros.DecimalDegreesSeconds(azimuthInDecimalDegrees); - - var altitudeDegrees = PAMacros.DecimalDegreesDegrees(altitudeInDecimalDegrees); - var altitudeMinutes = PAMacros.DecimalDegreesMinutes(altitudeInDecimalDegrees); - var altitudeSeconds = PAMacros.DecimalDegreesSeconds(altitudeInDecimalDegrees); - - return (azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds); - } - - /// - /// Convert Horizon Coordinates to Equatorial Coordinates - /// - /// Tuple (hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds) - public (double hour_angle_hours, double hour_angle_minutes, double hour_angle_seconds, double declination_degrees, double declination_minutes, double declinationseconds) HorizonCoordinatesToEquatorialCoordinates(double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds, double geographicalLatitude) - { - var hourAngleInDecimalDegrees = PAMacros.HorizonCoordinatesToHourAngle(azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds, geographicalLatitude); - - var declinationInDecimalDegrees = PAMacros.HorizonCoordinatesToDeclination(azimuthDegrees, azimuthMinutes, azimuthSeconds, altitudeDegrees, altitudeMinutes, altitudeSeconds, geographicalLatitude); - - var hourAngleHours = PAMacros.DecimalHoursHour(hourAngleInDecimalDegrees); - var hourAngleMinutes = PAMacros.DecimalHoursMinute(hourAngleInDecimalDegrees); - var hourAngleSeconds = PAMacros.DecimalHoursSecond(hourAngleInDecimalDegrees); - - var declinationDegrees = PAMacros.DecimalDegreesDegrees(declinationInDecimalDegrees); - var declinationMinutes = PAMacros.DecimalDegreesMinutes(declinationInDecimalDegrees); - var declinationSeconds = PAMacros.DecimalDegreesSeconds(declinationInDecimalDegrees); - - return (hourAngleHours, hourAngleMinutes, hourAngleSeconds, declinationDegrees, declinationMinutes, declinationSeconds); - } - - /// - /// Calculate Mean Obliquity of the Ecliptic for a Greenwich Date - /// - public double MeanObliquityOfTheEcliptic(double greenwichDay, int greenwichMonth, int greenwichYear) - { - var jd = PAMacros.CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); - var mjd = jd - 2451545; - var t = mjd / 36525; - var de1 = t * (46.815 + t * (0.0006 - (t * 0.00181))); - var de2 = de1 / 3600; - - return 23.439292 - de2; - } - - /// - /// Convert Ecliptic Coordinates to Equatorial Coordinates - /// - /// Tuple (outRAHours, outRAMinutes, outRASeconds, outDecDegrees, outDecMinutes, outDecSeconds) - public (double outRAHours, double outRAMinutes, double outRASeconds, double outDecDegrees, double outDecMinutes, double outDecSeconds) EclipticCoordinateToEquatorialCoordinate(double eclipticLongitudeDegrees, double eclipticLongitudeMinutes, double eclipticLongitudeSeconds, double eclipticLatitudeDegrees, double eclipticLatitudeMinutes, double eclipticLatitudeSeconds, double greenwichDay, int greenwichMonth, int greenwichYear) - { - var eclonDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(eclipticLongitudeDegrees, eclipticLongitudeMinutes, eclipticLongitudeSeconds); - var eclatDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(eclipticLatitudeDegrees, eclipticLatitudeMinutes, eclipticLatitudeSeconds); - var eclonRad = eclonDeg.ToRadians(); - var eclatRad = eclatDeg.ToRadians(); - var obliqDeg = PAMacros.Obliq(greenwichDay, greenwichMonth, greenwichYear); - var obliqRad = obliqDeg.ToRadians(); - var sinDec = eclatRad.Sine() * obliqRad.Cosine() + eclatRad.Cosine() * obliqRad.Sine() * eclonRad.Sine(); - var decRad = sinDec.ASine(); - var decDeg = PAMacros.Degrees(decRad); - var y = eclonRad.Sine() * obliqRad.Cosine() - eclatRad.Tangent() * obliqRad.Sine(); - var x = eclonRad.Cosine(); - var raRad = y.AngleTangent2(x); - var raDeg1 = PAMacros.Degrees(raRad); - var raDeg2 = raDeg1 - 360 * (raDeg1 / 360).Floor(); - var raHours = PAMacros.DecimalDegreesToDegreeHours(raDeg2); - - var outRAHours = PAMacros.DecimalHoursHour(raHours); - var outRAMinutes = PAMacros.DecimalHoursMinute(raHours); - var outRASeconds = PAMacros.DecimalHoursSecond(raHours); - var outDecDegrees = PAMacros.DecimalDegreesDegrees(decDeg); - var outDecMinutes = PAMacros.DecimalDegreesMinutes(decDeg); - var outDecSeconds = PAMacros.DecimalDegreesSeconds(decDeg); - - return (outRAHours, outRAMinutes, outRASeconds, outDecDegrees, outDecMinutes, outDecSeconds); - } - - /// - /// Convert Equatorial Coordinates to Ecliptic Coordinates - /// - /// Tuple (outEclLongDeg, outEclLongMin, outEclLongSec, outEclLatDeg, outEclLatMin, outEclLatSec) - public (double outEclLongDeg, double outEclLongMin, double outEclLongSec, double outEclLatDeg, double outEclLatMin, double outEclLatSec) EquatorialCoordinateToEclipticCoordinate(double raHours, double raMinutes, double raSeconds, double decDegrees, double decMinutes, double decSeconds, double gwDay, int gwMonth, int gwYear) - { - var raDeg = PAMacros.DegreeHoursToDecimalDegrees(PAMacros.HMStoDH(raHours, raMinutes, raSeconds)); - var decDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDegrees, decMinutes, decSeconds); - var raRad = raDeg.ToRadians(); - var decRad = decDeg.ToRadians(); - var obliqDeg = PAMacros.Obliq(gwDay, gwMonth, gwYear); - var obliqRad = obliqDeg.ToRadians(); - var sinEclLat = decRad.Sine() * obliqRad.Cosine() - decRad.Cosine() * obliqRad.Sine() * raRad.Sine(); - var eclLatRad = sinEclLat.ASine(); - var eclLatDeg = PAMacros.Degrees(eclLatRad); - var y = raRad.Sine() * obliqRad.Cosine() + decRad.Tangent() * obliqRad.Sine(); - var x = raRad.Cosine(); - var eclLongRad = y.AngleTangent2(x); - var eclLongDeg1 = PAMacros.Degrees(eclLongRad); - var eclLongDeg2 = eclLongDeg1 - 360 * (eclLongDeg1 / 360).Floor(); - - var outEclLongDeg = PAMacros.DecimalDegreesDegrees(eclLongDeg2); - var outEclLongMin = PAMacros.DecimalDegreesMinutes(eclLongDeg2); - var outEclLongSec = PAMacros.DecimalDegreesSeconds(eclLongDeg2); - var outEclLatDeg = PAMacros.DecimalDegreesDegrees(eclLatDeg); - var outEclLatMin = PAMacros.DecimalDegreesMinutes(eclLatDeg); - var outEclLatSec = PAMacros.DecimalDegreesSeconds(eclLatDeg); - - return (outEclLongDeg, outEclLongMin, outEclLongSec, outEclLatDeg, outEclLatMin, outEclLatSec); - } - - /// - /// Convert Equatorial Coordinates to Galactic Coordinates - /// - /// Tuple (galLongDeg, galLongMin, galLongSec, galLatDeg, galLatMin, galLatSec) - public (double galLongDeg, double galLongMin, double galLongSec, double galLatDeg, double galLatMin, double galLatSec) EquatorialCoordinateToGalacticCoordinate(double raHours, double raMinutes, double raSeconds, double decDegrees, double decMinutes, double decSeconds) - { - var raDeg = PAMacros.DegreeHoursToDecimalDegrees(PAMacros.HMStoDH(raHours, raMinutes, raSeconds)); - var decDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDegrees, decMinutes, decSeconds); - var raRad = raDeg.ToRadians(); - var decRad = decDeg.ToRadians(); - var sinB = decRad.Cosine() * (27.4).ToRadians().Cosine() * (raRad - (192.25).ToRadians()).Cosine() + decRad.Sine() * (27.4).ToRadians().Sine(); - var bRadians = sinB.ASine(); - var bDeg = PAMacros.Degrees(bRadians); - var y = decRad.Sine() - sinB * (27.4).ToRadians().Sine(); - var x = decRad.Cosine() * (raRad - (192.25).ToRadians()).Sine() * (27.4).ToRadians().Cosine(); - var longDeg1 = PAMacros.Degrees(y.AngleTangent2(x)) + 33; - var longDeg2 = longDeg1 - 360 * (longDeg1 / 360).Floor(); - - var galLongDeg = PAMacros.DecimalDegreesDegrees(longDeg2); - var galLongMin = PAMacros.DecimalDegreesMinutes(longDeg2); - var galLongSec = PAMacros.DecimalDegreesSeconds(longDeg2); - var galLatDeg = PAMacros.DecimalDegreesDegrees(bDeg); - var galLatMin = PAMacros.DecimalDegreesMinutes(bDeg); - var galLatSec = PAMacros.DecimalDegreesSeconds(bDeg); - - return (galLongDeg, galLongMin, galLongSec, galLatDeg, galLatMin, galLatSec); - } - - /// - /// Convert Galactic Coordinates to Equatorial Coordinates - /// - /// Tuple (raHours, raMinutes, raSeconds, decDegrees, decMinutes, decSeconds) - public (double raHours, double raMinutes, double raSeconds, double decDegrees, double decMinutes, double decSeconds) GalacticCoordinateToEquatorialCoordinate(double galLongDeg, double galLongMin, double galLongSec, double galLatDeg, double galLatMin, double galLatSec) - { - var glongDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(galLongDeg, galLongMin, galLongSec); - var glatDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(galLatDeg, galLatMin, galLatSec); - var glongRad = glongDeg.ToRadians(); - var glatRad = glatDeg.ToRadians(); - var sinDec = glatRad.Cosine() * (27.4).ToRadians().Cosine() * (glongRad - (33.0).ToRadians()).Sine() + glatRad.Sine() * (27.4).ToRadians().Sine(); - var decRadians = sinDec.ASine(); - var decDeg = PAMacros.Degrees(decRadians); - var y = glatRad.Cosine() * (glongRad - (33.0).ToRadians()).Cosine(); - var x = glatRad.Sine() * ((27.4).ToRadians()).Cosine() - (glatRad).Cosine() * ((27.4).ToRadians()).Sine() * (glongRad - (33.0).ToRadians()).Sine(); - - var raDeg1 = PAMacros.Degrees(y.AngleTangent2(x)) + 192.25; - var raDeg2 = raDeg1 - 360 * (raDeg1 / 360).Floor(); - var raHours1 = PAMacros.DecimalDegreesToDegreeHours(raDeg2); - - var raHours = PAMacros.DecimalHoursHour(raHours1); - var raMinutes = PAMacros.DecimalHoursMinute(raHours1); - var raSeconds = PAMacros.DecimalHoursSecond(raHours1); - var decDegrees = PAMacros.DecimalDegreesDegrees(decDeg); - var decMinutes = PAMacros.DecimalDegreesMinutes(decDeg); - var decSeconds = PAMacros.DecimalDegreesSeconds(decDeg); - - return (raHours, raMinutes, raSeconds, decDegrees, decMinutes, decSeconds); - } - - /// - /// Calculate the angle between two celestial objects - /// - /// Tuple (angleDeg, angleMin, angleSec) - public (double angleDeg, double angleMin, double angleSec) AngleBetweenTwoObjects(double raLong1HourDeg, double raLong1Min, double raLong1Sec, double decLat1Deg, double decLat1Min, double decLat1Sec, double raLong2HourDeg, double raLong2Min, double raLong2Sec, double decLat2Deg, double decLat2Min, double decLat2Sec, PAAngleMeasure hourOrDegree) - { - var raLong1Decimal = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.HMStoDH(raLong1HourDeg, raLong1Min, raLong1Sec) : PAMacros.DegreesMinutesSecondsToDecimalDegrees(raLong1HourDeg, raLong1Min, raLong1Sec); - var raLong1Deg = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.DegreeHoursToDecimalDegrees(raLong1Decimal) : raLong1Decimal; - - var raLong1Rad = raLong1Deg.ToRadians(); - var decLat1Deg1 = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decLat1Deg, decLat1Min, decLat1Sec); - var decLat1Rad = decLat1Deg1.ToRadians(); - - var raLong2Decimal = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.HMStoDH(raLong2HourDeg, raLong2Min, raLong2Sec) : PAMacros.DegreesMinutesSecondsToDecimalDegrees(raLong2HourDeg, raLong2Min, raLong2Sec); - var raLong2Deg = (hourOrDegree == PAAngleMeasure.Hours) ? PAMacros.DegreeHoursToDecimalDegrees(raLong2Decimal) : raLong2Decimal; - var raLong2Rad = raLong2Deg.ToRadians(); - var decLat2Deg1 = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decLat2Deg, decLat2Min, decLat2Sec); - var decLat2Rad = decLat2Deg1.ToRadians(); - - var cosD = decLat1Rad.Sine() * decLat2Rad.Sine() + decLat1Rad.Cosine() * decLat2Rad.Cosine() * (raLong1Rad - raLong2Rad).Cosine(); - var dRad = cosD.ACosine(); - var dDeg = PAMacros.Degrees(dRad); - - var angleDeg = PAMacros.DecimalDegreesDegrees(dDeg); - var angleMin = PAMacros.DecimalDegreesMinutes(dDeg); - var angleSec = PAMacros.DecimalDegreesSeconds(dDeg); - - return (angleDeg, angleMin, angleSec); - } - - - /// - /// Calculate rising and setting times for an object. - /// - /// Tuple (riseSetStatus, utRiseHour, utRiseMin, utSetHour, utSetMin, azRise, azSet) - public (string riseSetStatus, double utRiseHour, double utRiseMin, double utSetHour, double utSetMin, double azRise, double azSet) RisingAndSetting(double raHours, double raMinutes, double raSeconds, double decDeg, double decMin, double decSec, double gwDateDay, int gwDateMonth, int gwDateYear, double geogLongDeg, double geogLatDeg, double vertShiftDeg) - { - var raHours1 = PAMacros.HMStoDH(raHours, raMinutes, raSeconds); - var decRad = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDeg, decMin, decSec).ToRadians(); - var verticalDisplRadians = vertShiftDeg.ToRadians(); - var geoLatRadians = geogLatDeg.ToRadians(); - var cosH = -(verticalDisplRadians.Sine() + geoLatRadians.Sine() * decRad.Sine()) / (geoLatRadians.Cosine() * decRad.Cosine()); - var hHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.Degrees(cosH.ACosine())); - var lstRiseHours = (raHours1 - hHours) - 24 * ((raHours1 - hHours) / 24).Floor(); - var lstSetHours = (raHours1 + hHours) - 24 * ((raHours1 + hHours) / 24).Floor(); - var aDeg = PAMacros.Degrees((((decRad).Sine() + (verticalDisplRadians).Sine() * (geoLatRadians).Sine()) / ((verticalDisplRadians).Cosine() * (geoLatRadians).Cosine())).ACosine()); - var azRiseDeg = aDeg - 360 * (aDeg / 360).Floor(); - var azSetDeg = (360 - aDeg) - 360 * ((360 - aDeg) / 360).Floor(); - var utRiseHours1 = PAMacros.GreenwichSiderealTimeToUniversalTime(PAMacros.LocalSiderealTimeToGreenwichSiderealTime(lstRiseHours, 0, 0, geogLongDeg), 0, 0, gwDateDay, gwDateMonth, gwDateYear); - var utSetHours1 = PAMacros.GreenwichSiderealTimeToUniversalTime(PAMacros.LocalSiderealTimeToGreenwichSiderealTime(lstSetHours, 0, 0, geogLongDeg), 0, 0, gwDateDay, gwDateMonth, gwDateYear); - var utRiseAdjustedHours = utRiseHours1 + 0.008333; - var utSetAdjustedHours = utSetHours1 + 0.008333; - - var riseSetStatus = "OK"; - if (cosH > 1) - riseSetStatus = "never rises"; - if (cosH < -1) - riseSetStatus = "circumpolar"; - - var utRiseHour = (riseSetStatus == "OK") ? PAMacros.DecimalHoursHour(utRiseAdjustedHours) : 0; - var utRiseMin = (riseSetStatus == "OK") ? PAMacros.DecimalHoursMinute(utRiseAdjustedHours) : 0; - var utSetHour = (riseSetStatus == "OK") ? PAMacros.DecimalHoursHour(utSetAdjustedHours) : 0; - var utSetMin = (riseSetStatus == "OK") ? PAMacros.DecimalHoursMinute(utSetAdjustedHours) : 0; - var azRise = (riseSetStatus == "OK") ? Math.Round(azRiseDeg, 2) : 0; - var azSet = (riseSetStatus == "OK") ? Math.Round(azSetDeg, 2) : 0; - - return (riseSetStatus, utRiseHour, utRiseMin, utSetHour, utSetMin, azRise, azSet); - } - - /// - /// Calculate precession (corrected coordinates between two epochs) - /// - /// Tuple (correctedRAHour, correctedRAMinutes, correctedRASeconds, correctedDecDeg, correctedDecMinutes, correctedDecSeconds) - public (double correctedRAHour, double correctedRAMinutes, double correctedRASeconds, double correctedDecDeg, double correctedDecMinutes, double correctedDecSeconds) CorrectForPrecession(double raHour, double raMinutes, double raSeconds, double decDeg, double decMinutes, double decSeconds, double epoch1Day, int epoch1Month, int epoch1Year, double epoch2Day, int epoch2Month, int epoch2Year) - { - var ra1Rad = (PAMacros.DegreeHoursToDecimalDegrees(PAMacros.HMStoDH(raHour, raMinutes, raSeconds))).ToRadians(); - var dec1Rad = (PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDeg, decMinutes, decSeconds)).ToRadians(); - var tCenturies = (PAMacros.CivilDateToJulianDate(epoch1Day, epoch1Month, epoch1Year) - 2415020) / 36525; - var mSec = 3.07234 + (0.00186 * tCenturies); - var nArcsec = 20.0468 - (0.0085 * tCenturies); - var nYears = (PAMacros.CivilDateToJulianDate(epoch2Day, epoch2Month, epoch2Year) - PAMacros.CivilDateToJulianDate(epoch1Day, epoch1Month, epoch1Year)) / 365.25; - var s1Hours = ((mSec + (nArcsec * (ra1Rad).Sine() * (dec1Rad).Tangent() / 15)) * nYears) / 3600; - var ra2Hours = PAMacros.HMStoDH(raHour, raMinutes, raSeconds) + s1Hours; - var s2Deg = (nArcsec * (ra1Rad).Cosine() * nYears) / 3600; - var dec2Deg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(decDeg, decMinutes, decSeconds) + s2Deg; - - var correctedRAHour = PAMacros.DecimalHoursHour(ra2Hours); - var correctedRAMinutes = PAMacros.DecimalHoursMinute(ra2Hours); - var correctedRASeconds = PAMacros.DecimalHoursSecond(ra2Hours); - var correctedDecDeg = PAMacros.DecimalDegreesDegrees(dec2Deg); - var correctedDecMinutes = PAMacros.DecimalDegreesMinutes(dec2Deg); - var correctedDecSeconds = PAMacros.DecimalDegreesSeconds(dec2Deg); - - return (correctedRAHour, correctedRAMinutes, correctedRASeconds, correctedDecDeg, correctedDecMinutes, correctedDecSeconds); - } - - /// - /// Calculate nutation for two values: ecliptic longitude and obliquity, for a Greenwich date. - /// - /// Tuple (nutation in ecliptic longitude (degrees), nutation in obliquity (degrees)) - public (double nutInLongDeg, double nutInOblDeg) NutationInEclipticLongitudeAndObliquity(double greenwichDay, int greenwichMonth, int greenwichYear) - { - var jdDays = PAMacros.CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); - var tCenturies = (jdDays - 2415020) / 36525; - var aDeg = 100.0021358 * tCenturies; - var l1Deg = 279.6967 + (0.000303 * tCenturies * tCenturies); - var lDeg1 = l1Deg + 360 * (aDeg - aDeg.Floor()); - var lDeg2 = lDeg1 - 360 * (lDeg1 / 360).Floor(); - var lRad = lDeg2.ToRadians(); - var bDeg = 5.372617 * tCenturies; - var nDeg1 = 259.1833 - 360 * (bDeg - bDeg.Floor()); - var nDeg2 = nDeg1 - 360 * ((nDeg1 / 360).Floor()); - var nRad = nDeg2.ToRadians(); - var nutInLongArcsec = -17.2 * nRad.Sine() - 1.3 * (2 * lRad).Sine(); - var nutInOblArcsec = 9.2 * nRad.Cosine() + 0.5 * (2 * lRad).Cosine(); - - var nutInLongDeg = nutInLongArcsec / 3600; - var nutInOblDeg = nutInOblArcsec / 3600; - - return (nutInLongDeg, nutInOblDeg); - } - - /// - /// Correct ecliptic coordinates for the effects of aberration. - /// - /// - /// apparent ecliptic longitude (degrees, minutes, seconds), - /// apparent ecliptic latitude (degrees, minutes, seconds) - /// - public (double apparentEclLongDeg, double apparentEclLongMin, double apparentEclLongSec, double apparentEclLatDeg, double apparentEclLatMin, double apparentEclLatSec) CorrectForAberration(double utHour, double utMinutes, double utSeconds, double gwDay, int gwMonth, int gwYear, double trueEclLongDeg, double trueEclLongMin, double trueEclLongSec, double trueEclLatDeg, double trueEclLatMin, double trueEclLatSec) - { - var trueLongDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(trueEclLongDeg, trueEclLongMin, trueEclLongSec); - var trueLatDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(trueEclLatDeg, trueEclLatMin, trueEclLatSec); - var sunTrueLongDeg = PAMacros.SunLong(utHour, utMinutes, utSeconds, 0, 0, gwDay, gwMonth, gwYear); - var dlongArcsec = -20.5 * ((sunTrueLongDeg - trueLongDeg).ToRadians()).Cosine() / ((trueLatDeg).ToRadians()).Cosine(); - var dlatArcsec = -20.5 * ((sunTrueLongDeg - trueLongDeg).ToRadians()).Sine() * ((trueLatDeg).ToRadians()).Sine(); - var apparentLongDeg = trueLongDeg + (dlongArcsec / 3600); - var apparentLatDeg = trueLatDeg + (dlatArcsec / 3600); - - var apparentEclLongDeg = PAMacros.DecimalDegreesDegrees(apparentLongDeg); - var apparentEclLongMin = PAMacros.DecimalDegreesMinutes(apparentLongDeg); - var apparentEclLongSec = PAMacros.DecimalDegreesSeconds(apparentLongDeg); - var apparentEclLatDeg = PAMacros.DecimalDegreesDegrees(apparentLatDeg); - var apparentEclLatMin = PAMacros.DecimalDegreesMinutes(apparentLatDeg); - var apparentEclLatSec = PAMacros.DecimalDegreesSeconds(apparentLatDeg); - - return (apparentEclLongDeg, apparentEclLongMin, apparentEclLongSec, apparentEclLatDeg, apparentEclLatMin, apparentEclLatSec); - } - - - /// - /// Calculate corrected RA/Dec, accounting for atmospheric refraction. - /// - /// - /// NOTE: Valid values for coordinate_type are "TRUE" and "APPARENT". - /// - /// - /// corrected RA hours,minutes,seconds - /// corrected Declination degrees,minutes,seconds - /// - public (double correctedRAHour, double correctedRAMin, double correctedRASec, double correctedDecDeg, double correctedDecMin, double correctedDecSec) AtmosphericRefraction(double trueRAHour, double trueRAMin, double trueRASec, double trueDecDeg, double trueDecMin, double trueDecSec, PACoordinateType coordinateType, double geogLongDeg, double geogLatDeg, int daylightSavingHours, int timezoneHours, double lcdDay, int lcdMonth, int lcdYear, double lctHour, double lctMin, double lctSec, double atmosphericPressureMbar, double atmosphericTemperatureCelsius) - { - var haHour = PAMacros.RightAscensionToHourAngle(trueRAHour, trueRAMin, trueRASec, lctHour, lctMin, lctSec, daylightSavingHours, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); - var azimuthDeg = PAMacros.EquatorialCoordinatesToAzimuth(haHour, 0, 0, trueDecDeg, trueDecMin, trueDecSec, geogLatDeg); - var altitudeDeg = PAMacros.EquatorialCoordinatesToAltitude(haHour, 0, 0, trueDecDeg, trueDecMin, trueDecSec, geogLatDeg); - var correctedAltitudeDeg = PAMacros.Refract(altitudeDeg, coordinateType, atmosphericPressureMbar, atmosphericTemperatureCelsius); - - var correctedHAHour = PAMacros.HorizonCoordinatesToHourAngle(azimuthDeg, 0, 0, correctedAltitudeDeg, 0, 0, geogLatDeg); - var correctedRAHour1 = PAMacros.HourAngleToRightAscension(correctedHAHour, 0, 0, lctHour, lctMin, lctSec, daylightSavingHours, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); - var correctedDecDeg1 = PAMacros.HorizonCoordinatesToDeclination(azimuthDeg, 0, 0, correctedAltitudeDeg, 0, 0, geogLatDeg); - - var correctedRAHour = PAMacros.DecimalHoursHour(correctedRAHour1); - var correctedRAMin = PAMacros.DecimalHoursMinute(correctedRAHour1); - var correctedRASec = PAMacros.DecimalHoursSecond(correctedRAHour1); - var correctedDecDeg = PAMacros.DecimalDegreesDegrees(correctedDecDeg1); - var correctedDecMin = PAMacros.DecimalDegreesMinutes(correctedDecDeg1); - var correctedDecSec = PAMacros.DecimalDegreesSeconds(correctedDecDeg1); - - return (correctedRAHour, correctedRAMin, correctedRASec, correctedDecDeg, correctedDecMin, correctedDecSec); - } - - - /// - /// Calculate corrected RA/Dec, accounting for geocentric parallax. - /// - /// corrected RA hours,minutes,seconds and corrected Declination degrees,minutes,seconds - public (double correctedRAHour, double correctedRAMin, double correctedRASec, double correctedDecDeg, double correctedDecMin, double correctedDecSec) CorrectionsForGeocentricParallax(double raHour, double raMin, double raSec, double decDeg, double decMin, double decSec, PACoordinateType coordinateType, double equatorialHorParallaxDeg, double geogLongDeg, double geogLatDeg, double heightM, int daylightSaving, int timezoneHours, double lcdDay, int lcdMonth, int lcdYear, double lctHour, double lctMin, double lctSec) - { - var haHours = PAMacros.RightAscensionToHourAngle(raHour, raMin, raSec, lctHour, lctMin, lctSec, daylightSaving, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); - - var correctedHAHours = PAMacros.ParallaxHA(haHours, 0, 0, decDeg, decMin, decSec, coordinateType, geogLatDeg, heightM, equatorialHorParallaxDeg); - - var correctedRAHours = PAMacros.HourAngleToRightAscension(correctedHAHours, 0, 0, lctHour, lctMin, lctSec, daylightSaving, timezoneHours, lcdDay, lcdMonth, lcdYear, geogLongDeg); - - var correctedDecDeg1 = PAMacros.ParallaxDec(haHours, 0, 0, decDeg, decMin, decSec, coordinateType, geogLatDeg, heightM, equatorialHorParallaxDeg); - - var correctedRAHour = PAMacros.DecimalHoursHour(correctedRAHours); - var correctedRAMin = PAMacros.DecimalHoursMinute(correctedRAHours); - var correctedRASec = PAMacros.DecimalHoursSecond(correctedRAHours); - var correctedDecDeg = PAMacros.DecimalDegreesDegrees(correctedDecDeg1); - var correctedDecMin = PAMacros.DecimalDegreesMinutes(correctedDecDeg1); - var correctedDecSec = PAMacros.DecimalDegreesSeconds(correctedDecDeg1); - - return (correctedRAHour, correctedRAMin, correctedRASec, correctedDecDeg, correctedDecMin, correctedDecSec); - } - - /// - /// Calculate heliographic coordinates for a given Greenwich date, with a given heliographic position angle and heliographic displacement in arc minutes. - /// - /// heliographic longitude and heliographic latitude, in degrees - public (double helioLongDeg, double helioLatDeg) HeliographicCoordinates(double helioPositionAngleDeg, double helioDisplacementArcmin, double gwdateDay, int gwdateMonth, int gwdateYear) - { - var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); - var tCenturies = (julianDateDays - 2415020) / 36525; - var longAscNodeDeg = PAMacros.DegreesMinutesSecondsToDecimalDegrees(74, 22, 0) + (84 * tCenturies / 60); - var sunLongDeg = PAMacros.SunLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var y = ((longAscNodeDeg - sunLongDeg).ToRadians()).Sine() * ((PAMacros.DegreesMinutesSecondsToDecimalDegrees(7, 15, 0)).ToRadians()).Cosine(); - var x = -((longAscNodeDeg - sunLongDeg).ToRadians()).Cosine(); - var aDeg = PAMacros.Degrees(y.AngleTangent2(x)); - var mDeg1 = 360 - (360 * (julianDateDays - 2398220) / 25.38); - var mDeg2 = mDeg1 - 360 * (mDeg1 / 360).Floor(); - var l0Deg1 = mDeg2 + aDeg; - var b0Rad = (((sunLongDeg - longAscNodeDeg).ToRadians()).Sine() * ((PAMacros.DegreesMinutesSecondsToDecimalDegrees(7, 15, 0)).ToRadians()).Sine()).ASine(); - var theta1Rad = (-((sunLongDeg).ToRadians()).Cosine() * ((PAMacros.Obliq(gwdateDay, gwdateMonth, gwdateYear)).ToRadians()).Tangent()).AngleTangent(); - var theta2Rad = (-((longAscNodeDeg - sunLongDeg).ToRadians()).Cosine() * ((PAMacros.DegreesMinutesSecondsToDecimalDegrees(7, 15, 0)).ToRadians()).Tangent()).AngleTangent(); - var pDeg = PAMacros.Degrees(theta1Rad + theta2Rad); - var rho1Deg = helioDisplacementArcmin / 60; - var rhoRad = (2 * rho1Deg / PAMacros.SunDia(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)).ASine() - (rho1Deg).ToRadians(); - var bRad = ((b0Rad).Sine() * (rhoRad).Cosine() + (b0Rad).Cosine() * (rhoRad).Sine() * ((pDeg - helioPositionAngleDeg).ToRadians()).Cosine()).ASine(); - var bDeg = PAMacros.Degrees(bRad); - var lDeg1 = PAMacros.Degrees(((rhoRad).Sine() * ((pDeg - helioPositionAngleDeg).ToRadians()).Sine() / (bRad).Cosine()).ASine()) + l0Deg1; - var lDeg2 = lDeg1 - 360 * (lDeg1 / 360).Floor(); - - var helioLongDeg = Math.Round(lDeg2, 2); - var helioLatDeg = Math.Round(bDeg, 2); - - return (helioLongDeg, helioLatDeg); - } - - /// - /// Calculate carrington rotation number for a Greenwich date - /// - /// carrington rotation number - public int CarringtonRotationNumber(double gwdateDay, int gwdateMonth, int gwdateYear) - { - var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); - - var crn = 1690 + (int)Math.Round((julianDateDays - 2444235.34) / 27.2753, 0); - - return crn; - } - - /// - /// Calculate selenographic (lunar) coordinates (sub-Earth) - /// - /// sub-earth longitude, sub-earth latitude, and position angle of pole - public (double subEarthLongitude, double subEarthLatitude, double positionAngleOfPole) SelenographicCoordinates1(double gwdateDay, int gwdateMonth, int gwdateYear) - { - var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); - var tCenturies = (julianDateDays - 2451545) / 36525; - var longAscNodeDeg = 125.044522 - 1934.136261 * tCenturies; - var f1 = 93.27191 + 483202.0175 * tCenturies; - var f2 = f1 - 360 * (f1 / 360).Floor(); - var geocentricMoonLongDeg = PAMacros.MoonLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var geocentricMoonLatRad = (PAMacros.MoonLat(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)).ToRadians(); - var inclinationRad = (PAMacros.DegreesMinutesSecondsToDecimalDegrees(1, 32, 32.7)).ToRadians(); - var nodeLongRad = (longAscNodeDeg - geocentricMoonLongDeg).ToRadians(); - var sinBe = -(inclinationRad).Cosine() * (geocentricMoonLatRad).Sine() + (inclinationRad).Sine() * (geocentricMoonLatRad).Cosine() * (nodeLongRad).Sine(); - var subEarthLatDeg = PAMacros.Degrees((sinBe).ASine()); - var aRad = (-(geocentricMoonLatRad).Sine() * (inclinationRad).Sine() - (geocentricMoonLatRad).Cosine() * (inclinationRad).Cosine() * (nodeLongRad).Sine()).AngleTangent2((geocentricMoonLatRad).Cosine() * (nodeLongRad).Cosine()); - var aDeg = PAMacros.Degrees(aRad); - var subEarthLongDeg1 = aDeg - f2; - var subEarthLongDeg2 = subEarthLongDeg1 - 360 * (subEarthLongDeg1 / 360).Floor(); - var subEarthLongDeg3 = (subEarthLongDeg2 > 180) ? subEarthLongDeg2 - 360 : subEarthLongDeg2; - var c1Rad = ((nodeLongRad).Cosine() * (inclinationRad).Sine() / ((geocentricMoonLatRad).Cosine() * (inclinationRad).Cosine() + (geocentricMoonLatRad).Sine() * (inclinationRad).Sine() * (nodeLongRad).Sine())).AngleTangent(); - var obliquityRad = (PAMacros.Obliq(gwdateDay, gwdateMonth, gwdateYear)).ToRadians(); - var c2Rad = ((obliquityRad).Sine() * ((geocentricMoonLongDeg).ToRadians()).Cosine() / ((obliquityRad).Sine() * (geocentricMoonLatRad).Sine() * ((geocentricMoonLongDeg).ToRadians()).Sine() - (obliquityRad).Cosine() * (geocentricMoonLatRad).Cosine())).AngleTangent(); - var cDeg = PAMacros.Degrees(c1Rad + c2Rad); - - var subEarthLongitude = Math.Round(subEarthLongDeg3, 2); - var subEarthLatitude = Math.Round(subEarthLatDeg, 2); - var positionAngleOfPole = Math.Round(cDeg, 2); - - return (subEarthLongitude, subEarthLatitude, positionAngleOfPole); - } - - /// - /// Calculate selenographic (lunar) coordinates (sub-Solar) - /// - /// sub-solar longitude, sub-solar colongitude, and sub-solar latitude - public (double subSolarLongitude, double subSolarColongitude, double subSolarLatitude) SelenographicCoordinates2(double gwdateDay, int gwdateMonth, int gwdateYear) - { - var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); - var tCenturies = (julianDateDays - 2451545) / 36525; - var longAscNodeDeg = 125.044522 - 1934.136261 * tCenturies; - var f1 = 93.27191 + 483202.0175 * tCenturies; - var f2 = f1 - 360 * (f1 / 360).Floor(); - var sunGeocentricLongDeg = PAMacros.SunLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var moonEquHorParallaxArcMin = PAMacros.MoonHP(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear) * 60; - var sunEarthDistAU = PAMacros.SunDist(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var geocentricMoonLatRad = (PAMacros.MoonLat(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)).ToRadians(); - var geocentricMoonLongDeg = PAMacros.MoonLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var adjustedMoonLongDeg = sunGeocentricLongDeg + 180 + (26.4 * (geocentricMoonLatRad).Cosine() * ((sunGeocentricLongDeg - geocentricMoonLongDeg).ToRadians()).Sine() / (moonEquHorParallaxArcMin * sunEarthDistAU)); - var adjustedMoonLatRad = 0.14666 * geocentricMoonLatRad / (moonEquHorParallaxArcMin * sunEarthDistAU); - var inclinationRad = (PAMacros.DegreesMinutesSecondsToDecimalDegrees(1, 32, 32.7)).ToRadians(); - var nodeLongRad = (longAscNodeDeg - adjustedMoonLongDeg).ToRadians(); - var sinBs = -(inclinationRad).Cosine() * (adjustedMoonLatRad).Sine() + (inclinationRad).Sine() * (adjustedMoonLatRad).Cosine() * (nodeLongRad).Sine(); - var subSolarLatDeg = PAMacros.Degrees((sinBs).ASine()); - var aRad = (-(adjustedMoonLatRad).Sine() * (inclinationRad).Sine() - (adjustedMoonLatRad).Cosine() * (inclinationRad).Cosine() * (nodeLongRad).Sine()).AngleTangent2((adjustedMoonLatRad).Cosine() * (nodeLongRad).Cosine()); - var aDeg = PAMacros.Degrees(aRad); - var subSolarLongDeg1 = aDeg - f2; - var subSolarLongDeg2 = subSolarLongDeg1 - 360 * (subSolarLongDeg1 / 360).Floor(); - var subSolarLongDeg3 = (subSolarLongDeg2 > 180) ? subSolarLongDeg2 - 360 : subSolarLongDeg2; - var subSolarColongDeg = 90 - subSolarLongDeg3; - - var subSolarLongitude = Math.Round(subSolarLongDeg3, 2); - var subSolarColongitude = Math.Round(subSolarColongDeg, 2); - var subSolarLatitude = Math.Round(subSolarLatDeg, 2); - - return (subSolarLongitude, subSolarColongitude, subSolarLatitude); - } + var julianDateDays = PAMacros.CivilDateToJulianDate(gwdateDay, gwdateMonth, gwdateYear); + var tCenturies = (julianDateDays - 2451545) / 36525; + var longAscNodeDeg = 125.044522 - 1934.136261 * tCenturies; + var f1 = 93.27191 + 483202.0175 * tCenturies; + var f2 = f1 - 360 * (f1 / 360).Floor(); + var sunGeocentricLongDeg = PAMacros.SunLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var moonEquHorParallaxArcMin = PAMacros.MoonHP(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear) * 60; + var sunEarthDistAU = PAMacros.SunDist(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var geocentricMoonLatRad = (PAMacros.MoonLat(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)).ToRadians(); + var geocentricMoonLongDeg = PAMacros.MoonLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var adjustedMoonLongDeg = sunGeocentricLongDeg + 180 + (26.4 * (geocentricMoonLatRad).Cosine() * ((sunGeocentricLongDeg - geocentricMoonLongDeg).ToRadians()).Sine() / (moonEquHorParallaxArcMin * sunEarthDistAU)); + var adjustedMoonLatRad = 0.14666 * geocentricMoonLatRad / (moonEquHorParallaxArcMin * sunEarthDistAU); + var inclinationRad = (PAMacros.DegreesMinutesSecondsToDecimalDegrees(1, 32, 32.7)).ToRadians(); + var nodeLongRad = (longAscNodeDeg - adjustedMoonLongDeg).ToRadians(); + var sinBs = -(inclinationRad).Cosine() * (adjustedMoonLatRad).Sine() + (inclinationRad).Sine() * (adjustedMoonLatRad).Cosine() * (nodeLongRad).Sine(); + var subSolarLatDeg = PAMacros.Degrees((sinBs).ASine()); + var aRad = (-(adjustedMoonLatRad).Sine() * (inclinationRad).Sine() - (adjustedMoonLatRad).Cosine() * (inclinationRad).Cosine() * (nodeLongRad).Sine()).AngleTangent2((adjustedMoonLatRad).Cosine() * (nodeLongRad).Cosine()); + var aDeg = PAMacros.Degrees(aRad); + var subSolarLongDeg1 = aDeg - f2; + var subSolarLongDeg2 = subSolarLongDeg1 - 360 * (subSolarLongDeg1 / 360).Floor(); + var subSolarLongDeg3 = (subSolarLongDeg2 > 180) ? subSolarLongDeg2 - 360 : subSolarLongDeg2; + var subSolarColongDeg = 90 - subSolarLongDeg3; + + var subSolarLongitude = Math.Round(subSolarLongDeg3, 2); + var subSolarColongitude = Math.Round(subSolarColongDeg, 2); + var subSolarLatitude = Math.Round(subSolarLatDeg, 2); + + return (subSolarLongitude, subSolarColongitude, subSolarLatitude); } -} \ No newline at end of file +} diff --git a/PALib/PADateTime.cs b/PALib/PADateTime.cs index 33e27a4..e1678d1 100644 --- a/PALib/PADateTime.cs +++ b/PALib/PADateTime.cs @@ -1,224 +1,223 @@ using System; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Date and time calculations. +/// +public class PADateTime { /// - /// Date and time calculations. + /// Gets the date of Easter for the year specified. /// - public class PADateTime + /// (Month, Day, Year) + public (int Month, int Day, int Year) GetDateOfEaster(int inputYear) { - /// - /// Gets the date of Easter for the year specified. - /// - /// (Month, Day, Year) - public (int Month, int Day, int Year) GetDateOfEaster(int inputYear) - { - double year = inputYear; - - var a = year % 19; - var b = (year / 100).Floor(); - var c = year % 100; - var d = (b / 4).Floor(); - var e = b % 4; - var f = ((b + 8) / 25).Floor(); - var g = ((b - f + 1) / 3).Floor(); - var h = ((19 * a) + b - d - g + 15) % 30; - var i = (c / 4).Floor(); - var k = c % 4; - var l = (32 + 2 * (e + i) - h - k) % 7; - var m = ((a + (11 * h) + (22 * l)) / 451).Floor(); - var n = ((h + l - (7 * m) + 114) / 31).Floor(); - var p = (h + l - (7 * m) + 114) % 31; - - var day = p + 1; - var month = n; - - return ((int)month, (int)day, (int)year); - } + double year = inputYear; + + var a = year % 19; + var b = (year / 100).Floor(); + var c = year % 100; + var d = (b / 4).Floor(); + var e = b % 4; + var f = ((b + 8) / 25).Floor(); + var g = ((b - f + 1) / 3).Floor(); + var h = ((19 * a) + b - d - g + 15) % 30; + var i = (c / 4).Floor(); + var k = c % 4; + var l = (32 + 2 * (e + i) - h - k) % 7; + var m = ((a + (11 * h) + (22 * l)) / 451).Floor(); + var n = ((h + l - (7 * m) + 114) / 31).Floor(); + var p = (h + l - (7 * m) + 114) % 31; + + var day = p + 1; + var month = n; + + return ((int)month, (int)day, (int)year); + } - /// - /// Calculate day number for a date. - /// - public int CivilDateToDayNumber(int month, int day, int year) + /// + /// Calculate day number for a date. + /// + public int CivilDateToDayNumber(int month, int day, int year) + { + if (month <= 2) { - if (month <= 2) - { - month = month - 1; - month = (year.IsLeapYear()) ? month * 62 : month * 63; - month = (int)((double)month / 2).Floor(); - } - else - { - month = (int)(((double)month + 1) * 30.6).Floor(); - month = (year.IsLeapYear()) ? month - 62 : month - 63; - } - - return month + day; + month = month - 1; + month = (year.IsLeapYear()) ? month * 62 : month * 63; + month = (int)((double)month / 2).Floor(); } - - /// - /// Convert a Civil Time (hours,minutes,seconds) to Decimal Hours - /// - public double CivilTimeToDecimalHours(double hours, double minutes, double seconds) + else { - return PAMacros.HMStoDH(hours, minutes, seconds); + month = (int)(((double)month + 1) * 30.6).Floor(); + month = (year.IsLeapYear()) ? month - 62 : month - 63; } - /// - /// Convert Decimal Hours to Civil Time - /// - /// Tuple(hours (double), minutes (double), seconds (double)) - public (double hours, double minutes, double seconds) DecimalHoursToCivilTime(double decimalHours) - { - var hours = PAMacros.DecimalHoursHour(decimalHours); - var minutes = PAMacros.DecimalHoursMinute(decimalHours); - var seconds = PAMacros.DecimalHoursSecond(decimalHours); + return month + day; + } - return (hours, minutes, seconds); - } + /// + /// Convert a Civil Time (hours,minutes,seconds) to Decimal Hours + /// + public double CivilTimeToDecimalHours(double hours, double minutes, double seconds) + { + return PAMacros.HMStoDH(hours, minutes, seconds); + } - /// - /// Convert local Civil Time to Universal Time - /// - /// Tuple (int utHours, int utMinutes, int utSeconds, int gwDay, int gwMonth, int gwYear) - public (int utHours, int utMinutes, int utSeconds, int gwDay, int gwMonth, int gwYear) LocalCivilTimeToUniversalTime(double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSavings, int zoneCorrection, double localDay, int localMonth, int localYear) - { - var lct = CivilTimeToDecimalHours(lctHours, lctMinutes, lctSeconds); + /// + /// Convert Decimal Hours to Civil Time + /// + /// Tuple(hours (double), minutes (double), seconds (double)) + public (double hours, double minutes, double seconds) DecimalHoursToCivilTime(double decimalHours) + { + var hours = PAMacros.DecimalHoursHour(decimalHours); + var minutes = PAMacros.DecimalHoursMinute(decimalHours); + var seconds = PAMacros.DecimalHoursSecond(decimalHours); - var daylightSavingsOffset = (isDaylightSavings) ? 1 : 0; + return (hours, minutes, seconds); + } - var utInterim = lct - daylightSavingsOffset - zoneCorrection; - var gdayInterim = localDay + (utInterim / 24); + /// + /// Convert local Civil Time to Universal Time + /// + /// Tuple (int utHours, int utMinutes, int utSeconds, int gwDay, int gwMonth, int gwYear) + public (int utHours, int utMinutes, int utSeconds, int gwDay, int gwMonth, int gwYear) LocalCivilTimeToUniversalTime(double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSavings, int zoneCorrection, double localDay, int localMonth, int localYear) + { + var lct = CivilTimeToDecimalHours(lctHours, lctMinutes, lctSeconds); - var jd = PAMacros.CivilDateToJulianDate(gdayInterim, localMonth, localYear); + var daylightSavingsOffset = (isDaylightSavings) ? 1 : 0; - var gDay = PAMacros.JulianDateDay(jd); - var gMonth = PAMacros.JulianDateMonth(jd); - var gYear = PAMacros.JulianDateYear(jd); + var utInterim = lct - daylightSavingsOffset - zoneCorrection; + var gdayInterim = localDay + (utInterim / 24); - var ut = 24 * (gDay - gDay.Floor()); + var jd = PAMacros.CivilDateToJulianDate(gdayInterim, localMonth, localYear); - return ( - PAMacros.DecimalHoursHour(ut), - PAMacros.DecimalHoursMinute(ut), - (int)PAMacros.DecimalHoursSecond(ut), - (int)gDay.Floor(), - gMonth, - gYear - ); - } + var gDay = PAMacros.JulianDateDay(jd); + var gMonth = PAMacros.JulianDateMonth(jd); + var gYear = PAMacros.JulianDateYear(jd); - /// - /// Convert Universal Time to local Civil Time - /// - /// Tuple (int lctHours, int lctMinutes, int lctSeconds, int localDay, int localMonth, int localYear) - public (int lctHours, int lctMinutes, int lctSeconds, int localDay, int localMonth, int localYear) UniversalTimeToLocalCivilTime(double utHours, double utMinutes, double utSeconds, bool isDaylightSavings, int zoneCorrection, int gwDay, int gwMonth, int gwYear) - { - var dstValue = (isDaylightSavings) ? 1 : 0; - var ut = PAMacros.HMStoDH(utHours, utMinutes, utSeconds); - var zoneTime = ut + zoneCorrection; - var localTime = zoneTime + dstValue; - var localJDPlusLocalTime = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear) + (localTime / 24); - var localDay = PAMacros.JulianDateDay(localJDPlusLocalTime); - var integerDay = localDay.Floor(); - var localMonth = PAMacros.JulianDateMonth(localJDPlusLocalTime); - var localYear = PAMacros.JulianDateYear(localJDPlusLocalTime); - - var lct = 24 * (localDay - integerDay); - - return ( - PAMacros.DecimalHoursHour(lct), - PAMacros.DecimalHoursMinute(lct), - (int)PAMacros.DecimalHoursSecond(lct), - (int)integerDay, - localMonth, - localYear - ); - } + var ut = 24 * (gDay - gDay.Floor()); - /// - /// Convert Universal Time to Greenwich Sidereal Time - /// - /// Tuple (int gstHours, int gstMinutes, double gstSeconds) - public (int gstHours, int gstMinutes, double gstSeconds) UniversalTimeToGreenwichSiderealTime(double utHours, double utMinutes, double utSeconds, double gwDay, int gwMonth, int gwYear) - { - var jd = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear); - var s = jd - 2451545; - var t = s / 36525; - var t01 = 6.697374558 + (2400.051336 * t) + (0.000025862 * t * t); - var t02 = t01 - (24.0 * (t01 / 24).Floor()); - var ut = PAMacros.HMStoDH(utHours, utMinutes, utSeconds); - var a = ut * 1.002737909; - var gst1 = t02 + a; - var gst2 = gst1 - (24.0 * (gst1 / 24).Floor()); - - var gstHours = PAMacros.DecimalHoursHour(gst2); - var gstMinutes = PAMacros.DecimalHoursMinute(gst2); - var gstSeconds = PAMacros.DecimalHoursSecond(gst2); - - return (gstHours, gstMinutes, gstSeconds); - } + return ( + PAMacros.DecimalHoursHour(ut), + PAMacros.DecimalHoursMinute(ut), + (int)PAMacros.DecimalHoursSecond(ut), + (int)gDay.Floor(), + gMonth, + gYear + ); + } - /// - /// Convert Greenwich Sidereal Time to Universal Time - /// - /// Tuple (int utHours, int utMinutes, double utSeconds, PAWarningFlag warningFlag) - public (int utHours, int utMinutes, double utSeconds, PAWarningFlag warningFlag) GreenwichSiderealTimeToUniversalTime(double gstHours, double gstMinutes, double gstSeconds, double gwDay, int gwMonth, int gwYear) - { - var jd = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear); - var s = jd - 2451545; - var t = s / 36525; - var t01 = 6.697374558 + (2400.051336 * t) + (0.000025862 * t * t); - var t02 = t01 - (24 * (t01 / 24).Floor()); - var gstHours1 = PAMacros.HMStoDH(gstHours, gstMinutes, gstSeconds); - - var a = gstHours1 - t02; - var b = a - (24 * (a / 24).Floor()); - var ut = b * 0.9972695663; - var utHours = PAMacros.DecimalHoursHour(ut); - var utMinutes = PAMacros.DecimalHoursMinute(ut); - var utSeconds = PAMacros.DecimalHoursSecond(ut); - - var warningFlag = (ut < 0.065574) ? PAWarningFlag.Warning : PAWarningFlag.OK; - - return (utHours, utMinutes, utSeconds, warningFlag); - } + /// + /// Convert Universal Time to local Civil Time + /// + /// Tuple (int lctHours, int lctMinutes, int lctSeconds, int localDay, int localMonth, int localYear) + public (int lctHours, int lctMinutes, int lctSeconds, int localDay, int localMonth, int localYear) UniversalTimeToLocalCivilTime(double utHours, double utMinutes, double utSeconds, bool isDaylightSavings, int zoneCorrection, int gwDay, int gwMonth, int gwYear) + { + var dstValue = (isDaylightSavings) ? 1 : 0; + var ut = PAMacros.HMStoDH(utHours, utMinutes, utSeconds); + var zoneTime = ut + zoneCorrection; + var localTime = zoneTime + dstValue; + var localJDPlusLocalTime = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear) + (localTime / 24); + var localDay = PAMacros.JulianDateDay(localJDPlusLocalTime); + var integerDay = localDay.Floor(); + var localMonth = PAMacros.JulianDateMonth(localJDPlusLocalTime); + var localYear = PAMacros.JulianDateYear(localJDPlusLocalTime); + + var lct = 24 * (localDay - integerDay); + + return ( + PAMacros.DecimalHoursHour(lct), + PAMacros.DecimalHoursMinute(lct), + (int)PAMacros.DecimalHoursSecond(lct), + (int)integerDay, + localMonth, + localYear + ); + } - /// - /// Convert Greenwich Sidereal Time to Local Sidereal Time - /// - /// Tuple (int lstHours, int lstMinutes, double lstSeconds) - public (int lstHours, int lstMinutes, double lstSeconds) GreenwichSiderealTimeToLocalSiderealTime(double gstHours, double gstMinutes, double gstSeconds, double geographicalLongitude) - { - var gst = PAMacros.HMStoDH(gstHours, gstMinutes, gstSeconds); - var offset = geographicalLongitude / 15; - var lstHours1 = gst + offset; - var lstHours2 = lstHours1 - (24 * (lstHours1 / 24).Floor()); + /// + /// Convert Universal Time to Greenwich Sidereal Time + /// + /// Tuple (int gstHours, int gstMinutes, double gstSeconds) + public (int gstHours, int gstMinutes, double gstSeconds) UniversalTimeToGreenwichSiderealTime(double utHours, double utMinutes, double utSeconds, double gwDay, int gwMonth, int gwYear) + { + var jd = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear); + var s = jd - 2451545; + var t = s / 36525; + var t01 = 6.697374558 + (2400.051336 * t) + (0.000025862 * t * t); + var t02 = t01 - (24.0 * (t01 / 24).Floor()); + var ut = PAMacros.HMStoDH(utHours, utMinutes, utSeconds); + var a = ut * 1.002737909; + var gst1 = t02 + a; + var gst2 = gst1 - (24.0 * (gst1 / 24).Floor()); + + var gstHours = PAMacros.DecimalHoursHour(gst2); + var gstMinutes = PAMacros.DecimalHoursMinute(gst2); + var gstSeconds = PAMacros.DecimalHoursSecond(gst2); + + return (gstHours, gstMinutes, gstSeconds); + } + + /// + /// Convert Greenwich Sidereal Time to Universal Time + /// + /// Tuple (int utHours, int utMinutes, double utSeconds, PAWarningFlag warningFlag) + public (int utHours, int utMinutes, double utSeconds, PAWarningFlag warningFlag) GreenwichSiderealTimeToUniversalTime(double gstHours, double gstMinutes, double gstSeconds, double gwDay, int gwMonth, int gwYear) + { + var jd = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear); + var s = jd - 2451545; + var t = s / 36525; + var t01 = 6.697374558 + (2400.051336 * t) + (0.000025862 * t * t); + var t02 = t01 - (24 * (t01 / 24).Floor()); + var gstHours1 = PAMacros.HMStoDH(gstHours, gstMinutes, gstSeconds); + + var a = gstHours1 - t02; + var b = a - (24 * (a / 24).Floor()); + var ut = b * 0.9972695663; + var utHours = PAMacros.DecimalHoursHour(ut); + var utMinutes = PAMacros.DecimalHoursMinute(ut); + var utSeconds = PAMacros.DecimalHoursSecond(ut); + + var warningFlag = (ut < 0.065574) ? PAWarningFlag.Warning : PAWarningFlag.OK; + + return (utHours, utMinutes, utSeconds, warningFlag); + } - var lstHours = PAMacros.DecimalHoursHour(lstHours2); - var lstMinutes = PAMacros.DecimalHoursMinute(lstHours2); - var lstSeconds = PAMacros.DecimalHoursSecond(lstHours2); + /// + /// Convert Greenwich Sidereal Time to Local Sidereal Time + /// + /// Tuple (int lstHours, int lstMinutes, double lstSeconds) + public (int lstHours, int lstMinutes, double lstSeconds) GreenwichSiderealTimeToLocalSiderealTime(double gstHours, double gstMinutes, double gstSeconds, double geographicalLongitude) + { + var gst = PAMacros.HMStoDH(gstHours, gstMinutes, gstSeconds); + var offset = geographicalLongitude / 15; + var lstHours1 = gst + offset; + var lstHours2 = lstHours1 - (24 * (lstHours1 / 24).Floor()); - return (lstHours, lstMinutes, lstSeconds); - } + var lstHours = PAMacros.DecimalHoursHour(lstHours2); + var lstMinutes = PAMacros.DecimalHoursMinute(lstHours2); + var lstSeconds = PAMacros.DecimalHoursSecond(lstHours2); - /// - /// Convert Local Sidereal Time to Greenwich Sidereal Time - /// - /// Tuple (int gstHours, int gstMinutes, double gstSeconds) - public (int gstHours, int gstMinutes, double gstSeconds) LocalSiderealTimeToGreenwichSiderealTime(double lstHours, double lstMinutes, double lstSeconds, double geographicalLongitude) - { - var gst = PAMacros.HMStoDH(lstHours, lstMinutes, lstSeconds); - var longHours = geographicalLongitude / 15; - var gst1 = gst - longHours; - var gst2 = gst1 - (24 * (gst1 / 24).Floor()); + return (lstHours, lstMinutes, lstSeconds); + } - var gstHours = PAMacros.DecimalHoursHour(gst2); - var gstMinutes = PAMacros.DecimalHoursMinute(gst2); - var gstSeconds = PAMacros.DecimalHoursSecond(gst2); + /// + /// Convert Local Sidereal Time to Greenwich Sidereal Time + /// + /// Tuple (int gstHours, int gstMinutes, double gstSeconds) + public (int gstHours, int gstMinutes, double gstSeconds) LocalSiderealTimeToGreenwichSiderealTime(double lstHours, double lstMinutes, double lstSeconds, double geographicalLongitude) + { + var gst = PAMacros.HMStoDH(lstHours, lstMinutes, lstSeconds); + var longHours = geographicalLongitude / 15; + var gst1 = gst - longHours; + var gst2 = gst1 - (24 * (gst1 / 24).Floor()); - return (gstHours, gstMinutes, gstSeconds); - } + var gstHours = PAMacros.DecimalHoursHour(gst2); + var gstMinutes = PAMacros.DecimalHoursMinute(gst2); + var gstSeconds = PAMacros.DecimalHoursSecond(gst2); + + return (gstHours, gstMinutes, gstSeconds); } } diff --git a/PALib/PAEclipses.cs b/PALib/PAEclipses.cs index c23209c..cd34205 100644 --- a/PALib/PAEclipses.cs +++ b/PALib/PAEclipses.cs @@ -1,210 +1,209 @@ using System; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Eclipse calculations. +/// +public class PAEclipses { /// - /// Eclipse calculations. + /// Determine if a lunar eclipse is likely to occur. /// - public class PAEclipses + /// + /// status -- One of "Lunar eclipse certain", "Lunar eclipse possible", or "No lunar eclipse". + /// eventDateDay -- Date of eclipse event (day). + /// eventDateMonth -- Date of eclipse event (month). + /// eventDateYear -- Date of eclipse event (year). + /// + public (string status, double eventDateDay, int eventDateMonth, int eventDateYear) LunarEclipseOccurrence(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours) { - /// - /// Determine if a lunar eclipse is likely to occur. - /// - /// - /// status -- One of "Lunar eclipse certain", "Lunar eclipse possible", or "No lunar eclipse". - /// eventDateDay -- Date of eclipse event (day). - /// eventDateMonth -- Date of eclipse event (month). - /// eventDateYear -- Date of eclipse event (year). - /// - public (string status, double eventDateDay, int eventDateMonth, int eventDateYear) LunarEclipseOccurrence(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var julianDateOfFullMoon = PAMacros.FullMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var gDateOfFullMoonDay = PAMacros.JulianDateDay(julianDateOfFullMoon); - var integerDay = (gDateOfFullMoonDay).Floor(); - var gDateOfFullMoonMonth = PAMacros.JulianDateMonth(julianDateOfFullMoon); - var gDateOfFullMoonYear = PAMacros.JulianDateYear(julianDateOfFullMoon); - var utOfFullMoonHours = gDateOfFullMoonDay - integerDay; - - var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); - var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); - var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); - - var eclipseOccurrence = PAMacros.LunarEclipseOccurrence(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var status = eclipseOccurrence; - var eventDateDay = localCivilDateDay; - var eventDateMonth = localCivilDateMonth; - var eventDateYear = localCivilDateYear; - - return (status, eventDateDay, eventDateMonth, eventDateYear); - } - - /// - /// Calculate the circumstances of a lunar eclipse. - /// - /// - /// lunarEclipseCertainDateDay -- Lunar eclipse date (day) - /// lunarEclipseCertainDateMonth -- Lunar eclipse date (month) - /// lunarEclipseCertainDateYear -- Lunar eclipse date (year) - /// utstartPenPhaseHour -- Start of penumbral phase (hour) - /// utStartPenPhaseMinutes -- Start of penumbral phase (minutes) - /// utStartUmbralPhaseHour -- Start of umbral phase (hour) - /// utStartUmbralPhaseMinutes -- Start of umbral phase (minutes) - /// utStartTotalPhaseHour -- Start of total phase (hour) - /// utStartTotalPhaseMinutes -- Start of total phase (minutes) - /// utMidEclipseHour -- Mid-eclipse (hour) - /// utMidEclipseMinutes -- Mid-eclipse (minutes) - /// utEndTotalPhaseHour -- End of total phase (hour) - /// utEndTotalPhaseMinutes -- End of total phase (minutes) - /// utEndUmbralPhaseHour -- End of umbral phase (hour) - /// utEndUmbralPhaseMinutes -- End of umbral phase (minutes) - /// utEndPenPhaseHour -- End of penumbral phase (hour) - /// utEndPenPhaseMinutes -- End of penumbral phase (minutes) - /// eclipseMagnitude -- Eclipse magnitude - /// - public (double lunarEclipseCertainDateDay, double lunarEclipseCertainDateMonth, double lunarEclipseCertainDateYear, double utStartPenPhaseHour, double utStartPenPhaseMinutes, double utStartUmbralPhaseHour, double utStartUmbralPhaseMinutes, double utStartTotalPhaseHour, double utStartTotalPhaseMinutes, double utMidEclipseHour, double utMidEclipseMinutes, double utEndTotalPhaseHour, double utEndTotalPhaseMinutes, double utEndUmbralPhaseHour, double utEndUmbralPhaseMinutes, double utEndPenPhaseHour, double utEndPenPhaseMinutes, double eclipseMagnitude) LunarEclipseCircumstances(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var julianDateOfFullMoon = PAMacros.FullMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gDateOfFullMoonDay = PAMacros.JulianDateDay(julianDateOfFullMoon); - var integerDay = gDateOfFullMoonDay.Floor(); - var gDateOfFullMoonMonth = PAMacros.JulianDateMonth(julianDateOfFullMoon); - var gDateOfFullMoonYear = PAMacros.JulianDateYear(julianDateOfFullMoon); - var utOfFullMoonHours = gDateOfFullMoonDay - integerDay; - - var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); - var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); - var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); - - var utMaxEclipse = PAMacros.UTMaxLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - var utFirstContact = PAMacros.UTFirstContactLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - var utLastContact = PAMacros.UTLastContactLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - var utStartUmbralPhase = PAMacros.UTStartUmbraLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - var utEndUmbralPhase = PAMacros.UTEndUmbraLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - var utStartTotalPhase = PAMacros.UTStartTotalLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - var utEndTotalPhase = PAMacros.UTEndTotalLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - - var eclipseMagnitude1 = PAMacros.MagLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); - - var lunarEclipseCertainDateDay = localCivilDateDay; - var lunarEclipseCertainDateMonth = localCivilDateMonth; - var lunarEclipseCertainDateYear = localCivilDateYear; - - var utStartPenPhaseHour = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utFirstContact + 0.008333); - var utStartPenPhaseMinutes = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utFirstContact + 0.008333); - - var utStartUmbralPhaseHour = (utStartUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utStartUmbralPhase + 0.008333); - var utStartUmbralPhaseMinutes = (utStartUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utStartUmbralPhase + 0.008333); - - var utStartTotalPhaseHour = (utStartTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utStartTotalPhase + 0.008333); - var utStartTotalPhaseMinutes = (utStartTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utStartTotalPhase + 0.008333); - - var utMidEclipseHour = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utMaxEclipse + 0.008333); - var utMidEclipseMinutes = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utMaxEclipse + 0.008333); - - var utEndTotalPhaseHour = (utEndTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utEndTotalPhase + 0.008333); - var utEndTotalPhaseMinutes = (utEndTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utEndTotalPhase + 0.008333); - - var utEndUmbralPhaseHour = (utEndUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utEndUmbralPhase + 0.008333); - var utEndUmbralPhaseMinutes = (utEndUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utEndUmbralPhase + 0.008333); - - var utEndPenPhaseHour = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utLastContact + 0.008333); - var utEndPenPhaseMinutes = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utLastContact + 0.008333); - - var eclipseMagnitude = (eclipseMagnitude1 == -99.0) ? -99.0 : Math.Round(eclipseMagnitude1, 2); - - return (lunarEclipseCertainDateDay, lunarEclipseCertainDateMonth, lunarEclipseCertainDateYear, utStartPenPhaseHour, utStartPenPhaseMinutes, utStartUmbralPhaseHour, utStartUmbralPhaseMinutes, utStartTotalPhaseHour, utStartTotalPhaseMinutes, utMidEclipseHour, utMidEclipseMinutes, utEndTotalPhaseHour, utEndTotalPhaseMinutes, utEndUmbralPhaseHour, utEndUmbralPhaseMinutes, utEndPenPhaseHour, utEndPenPhaseMinutes, eclipseMagnitude); - } - - /// - /// Determine if a solar eclipse is likely to occur. - /// - /// - /// status -- One of "Solar eclipse certain", "Solar eclipse possible", or "No solar eclipse". - /// event_date_day -- Date of eclipse event (day). - /// event_date_month -- Date of eclipse event (month). - /// event_date_year -- Date of eclipse event (year). - /// - public (string status, double eventDateDay, int eventDateMonth, int eventDateYear) SolarEclipseOccurrence(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var julianDateOfNewMoon = PAMacros.NewMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gDateOfNewMoonDay = PAMacros.JulianDateDay(julianDateOfNewMoon); - var integerDay = (gDateOfNewMoonDay).Floor(); - var gDateOfNewMoonMonth = PAMacros.JulianDateMonth(julianDateOfNewMoon); - var gDateOfNewMoonYear = PAMacros.JulianDateYear(julianDateOfNewMoon); - var utOfNewMoonHours = gDateOfNewMoonDay - integerDay; - - var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); - - var eclipseOccurrence = PAMacros.SolarEclipseOccurrence(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var status = eclipseOccurrence; - var eventDateDay = localCivilDateDay; - var eventDateMonth = localCivilDateMonth; - var eventDateYear = localCivilDateYear; - - return (status, eventDateDay, eventDateMonth, eventDateYear); - } - - /// - /// Calculate the circumstances of a solar eclipse. - /// - /// - /// solarEclipseCertainDateDay -- Solar eclipse date (day) - /// solarEclipseCertainDateMonth -- Solar eclipse date (month) - /// solarEclipseCertainDateYear -- Solar eclipse date (year) - /// utFirstContactHour -- First contact of shadow (hour) - /// utFirstContactMinutes -- First contact of shadow (minutes) - /// utMidEclipseHour -- Mid-eclipse (hour) - /// utMidEclipseMinutes -- Mid-eclipse (minutes) - /// utLastContactHour -- Last contact of shadow (hour) - /// utLastContactMinutes -- Last contact of shadow (minutes) - /// eclipseMagnitude -- Eclipse magnitude - /// - public (double solarEclipseCertainDateDay, int solarEclipseCertainDateMonth, int solarEclipseCertainDateYear, double utFirstContactHour, double utFirstContactMinutes, double utMidEclipseHour, double utMidEclipseMinutes, double utLastContactHour, double utLastContactMinutes, double eclipseMagnitude) SolarEclipseCircumstances(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours, double geogLongitudeDeg, double geogLatitudeDeg) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var julianDateOfNewMoon = PAMacros.NewMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gDateOfNewMoonDay = PAMacros.JulianDateDay(julianDateOfNewMoon); - var integerDay = (gDateOfNewMoonDay).Floor(); - var gDateOfNewMoonMonth = PAMacros.JulianDateMonth(julianDateOfNewMoon); - var gDateOfNewMoonYear = PAMacros.JulianDateYear(julianDateOfNewMoon); - var utOfNewMoonHours = gDateOfNewMoonDay - integerDay; - var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); - - var utMaxEclipse = PAMacros.UTMaxSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); - var utFirstContact = PAMacros.UTFirstContactSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); - var utLastContact = PAMacros.UTLastContactSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); - var magnitude = PAMacros.MagSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); - - var solarEclipseCertainDateDay = localCivilDateDay; - var solarEclipseCertainDateMonth = localCivilDateMonth; - var solarEclipseCertainDateYear = localCivilDateYear; - - var utFirstContactHour = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utFirstContact + 0.008333); - var utFirstContactMinutes = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utFirstContact + 0.008333); - - var utMidEclipseHour = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utMaxEclipse + 0.008333); - var utMidEclipseMinutes = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utMaxEclipse + 0.008333); - - var utLastContactHour = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utLastContact + 0.008333); - var utLastContactMinutes = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utLastContact + 0.008333); - - var eclipseMagnitude = (magnitude == -99.0) ? -99.0 : Math.Round(magnitude, 3); - - return (solarEclipseCertainDateDay, solarEclipseCertainDateMonth, solarEclipseCertainDateYear, utFirstContactHour, utFirstContactMinutes, utMidEclipseHour, utMidEclipseMinutes, utLastContactHour, utLastContactMinutes, eclipseMagnitude); - } + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var julianDateOfFullMoon = PAMacros.FullMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var gDateOfFullMoonDay = PAMacros.JulianDateDay(julianDateOfFullMoon); + var integerDay = (gDateOfFullMoonDay).Floor(); + var gDateOfFullMoonMonth = PAMacros.JulianDateMonth(julianDateOfFullMoon); + var gDateOfFullMoonYear = PAMacros.JulianDateYear(julianDateOfFullMoon); + var utOfFullMoonHours = gDateOfFullMoonDay - integerDay; + + var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); + var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); + var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); + + var eclipseOccurrence = PAMacros.LunarEclipseOccurrence(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var status = eclipseOccurrence; + var eventDateDay = localCivilDateDay; + var eventDateMonth = localCivilDateMonth; + var eventDateYear = localCivilDateYear; + + return (status, eventDateDay, eventDateMonth, eventDateYear); + } + + /// + /// Calculate the circumstances of a lunar eclipse. + /// + /// + /// lunarEclipseCertainDateDay -- Lunar eclipse date (day) + /// lunarEclipseCertainDateMonth -- Lunar eclipse date (month) + /// lunarEclipseCertainDateYear -- Lunar eclipse date (year) + /// utstartPenPhaseHour -- Start of penumbral phase (hour) + /// utStartPenPhaseMinutes -- Start of penumbral phase (minutes) + /// utStartUmbralPhaseHour -- Start of umbral phase (hour) + /// utStartUmbralPhaseMinutes -- Start of umbral phase (minutes) + /// utStartTotalPhaseHour -- Start of total phase (hour) + /// utStartTotalPhaseMinutes -- Start of total phase (minutes) + /// utMidEclipseHour -- Mid-eclipse (hour) + /// utMidEclipseMinutes -- Mid-eclipse (minutes) + /// utEndTotalPhaseHour -- End of total phase (hour) + /// utEndTotalPhaseMinutes -- End of total phase (minutes) + /// utEndUmbralPhaseHour -- End of umbral phase (hour) + /// utEndUmbralPhaseMinutes -- End of umbral phase (minutes) + /// utEndPenPhaseHour -- End of penumbral phase (hour) + /// utEndPenPhaseMinutes -- End of penumbral phase (minutes) + /// eclipseMagnitude -- Eclipse magnitude + /// + public (double lunarEclipseCertainDateDay, double lunarEclipseCertainDateMonth, double lunarEclipseCertainDateYear, double utStartPenPhaseHour, double utStartPenPhaseMinutes, double utStartUmbralPhaseHour, double utStartUmbralPhaseMinutes, double utStartTotalPhaseHour, double utStartTotalPhaseMinutes, double utMidEclipseHour, double utMidEclipseMinutes, double utEndTotalPhaseHour, double utEndTotalPhaseMinutes, double utEndUmbralPhaseHour, double utEndUmbralPhaseMinutes, double utEndPenPhaseHour, double utEndPenPhaseMinutes, double eclipseMagnitude) LunarEclipseCircumstances(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var julianDateOfFullMoon = PAMacros.FullMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gDateOfFullMoonDay = PAMacros.JulianDateDay(julianDateOfFullMoon); + var integerDay = gDateOfFullMoonDay.Floor(); + var gDateOfFullMoonMonth = PAMacros.JulianDateMonth(julianDateOfFullMoon); + var gDateOfFullMoonYear = PAMacros.JulianDateYear(julianDateOfFullMoon); + var utOfFullMoonHours = gDateOfFullMoonDay - integerDay; + + var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); + var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); + var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfFullMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfFullMoonMonth, gDateOfFullMoonYear); + + var utMaxEclipse = PAMacros.UTMaxLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + var utFirstContact = PAMacros.UTFirstContactLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + var utLastContact = PAMacros.UTLastContactLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + var utStartUmbralPhase = PAMacros.UTStartUmbraLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + var utEndUmbralPhase = PAMacros.UTEndUmbraLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + var utStartTotalPhase = PAMacros.UTStartTotalLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + var utEndTotalPhase = PAMacros.UTEndTotalLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + + var eclipseMagnitude1 = PAMacros.MagLunarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours); + + var lunarEclipseCertainDateDay = localCivilDateDay; + var lunarEclipseCertainDateMonth = localCivilDateMonth; + var lunarEclipseCertainDateYear = localCivilDateYear; + + var utStartPenPhaseHour = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utFirstContact + 0.008333); + var utStartPenPhaseMinutes = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utFirstContact + 0.008333); + + var utStartUmbralPhaseHour = (utStartUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utStartUmbralPhase + 0.008333); + var utStartUmbralPhaseMinutes = (utStartUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utStartUmbralPhase + 0.008333); + + var utStartTotalPhaseHour = (utStartTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utStartTotalPhase + 0.008333); + var utStartTotalPhaseMinutes = (utStartTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utStartTotalPhase + 0.008333); + + var utMidEclipseHour = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utMaxEclipse + 0.008333); + var utMidEclipseMinutes = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utMaxEclipse + 0.008333); + + var utEndTotalPhaseHour = (utEndTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utEndTotalPhase + 0.008333); + var utEndTotalPhaseMinutes = (utEndTotalPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utEndTotalPhase + 0.008333); + + var utEndUmbralPhaseHour = (utEndUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utEndUmbralPhase + 0.008333); + var utEndUmbralPhaseMinutes = (utEndUmbralPhase == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utEndUmbralPhase + 0.008333); + + var utEndPenPhaseHour = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utLastContact + 0.008333); + var utEndPenPhaseMinutes = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utLastContact + 0.008333); + + var eclipseMagnitude = (eclipseMagnitude1 == -99.0) ? -99.0 : Math.Round(eclipseMagnitude1, 2); + + return (lunarEclipseCertainDateDay, lunarEclipseCertainDateMonth, lunarEclipseCertainDateYear, utStartPenPhaseHour, utStartPenPhaseMinutes, utStartUmbralPhaseHour, utStartUmbralPhaseMinutes, utStartTotalPhaseHour, utStartTotalPhaseMinutes, utMidEclipseHour, utMidEclipseMinutes, utEndTotalPhaseHour, utEndTotalPhaseMinutes, utEndUmbralPhaseHour, utEndUmbralPhaseMinutes, utEndPenPhaseHour, utEndPenPhaseMinutes, eclipseMagnitude); + } + + /// + /// Determine if a solar eclipse is likely to occur. + /// + /// + /// status -- One of "Solar eclipse certain", "Solar eclipse possible", or "No solar eclipse". + /// event_date_day -- Date of eclipse event (day). + /// event_date_month -- Date of eclipse event (month). + /// event_date_year -- Date of eclipse event (year). + /// + public (string status, double eventDateDay, int eventDateMonth, int eventDateYear) SolarEclipseOccurrence(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var julianDateOfNewMoon = PAMacros.NewMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gDateOfNewMoonDay = PAMacros.JulianDateDay(julianDateOfNewMoon); + var integerDay = (gDateOfNewMoonDay).Floor(); + var gDateOfNewMoonMonth = PAMacros.JulianDateMonth(julianDateOfNewMoon); + var gDateOfNewMoonYear = PAMacros.JulianDateYear(julianDateOfNewMoon); + var utOfNewMoonHours = gDateOfNewMoonDay - integerDay; + + var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); + + var eclipseOccurrence = PAMacros.SolarEclipseOccurrence(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var status = eclipseOccurrence; + var eventDateDay = localCivilDateDay; + var eventDateMonth = localCivilDateMonth; + var eventDateYear = localCivilDateYear; + + return (status, eventDateDay, eventDateMonth, eventDateYear); + } + + /// + /// Calculate the circumstances of a solar eclipse. + /// + /// + /// solarEclipseCertainDateDay -- Solar eclipse date (day) + /// solarEclipseCertainDateMonth -- Solar eclipse date (month) + /// solarEclipseCertainDateYear -- Solar eclipse date (year) + /// utFirstContactHour -- First contact of shadow (hour) + /// utFirstContactMinutes -- First contact of shadow (minutes) + /// utMidEclipseHour -- Mid-eclipse (hour) + /// utMidEclipseMinutes -- Mid-eclipse (minutes) + /// utLastContactHour -- Last contact of shadow (hour) + /// utLastContactMinutes -- Last contact of shadow (minutes) + /// eclipseMagnitude -- Eclipse magnitude + /// + public (double solarEclipseCertainDateDay, int solarEclipseCertainDateMonth, int solarEclipseCertainDateYear, double utFirstContactHour, double utFirstContactMinutes, double utMidEclipseHour, double utMidEclipseMinutes, double utLastContactHour, double utLastContactMinutes, double eclipseMagnitude) SolarEclipseCircumstances(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours, double geogLongitudeDeg, double geogLatitudeDeg) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var julianDateOfNewMoon = PAMacros.NewMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gDateOfNewMoonDay = PAMacros.JulianDateDay(julianDateOfNewMoon); + var integerDay = (gDateOfNewMoonDay).Floor(); + var gDateOfNewMoonMonth = PAMacros.JulianDateMonth(julianDateOfNewMoon); + var gDateOfNewMoonYear = PAMacros.JulianDateYear(julianDateOfNewMoon); + var utOfNewMoonHours = gDateOfNewMoonDay - integerDay; + var localCivilDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var localCivilDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var localCivilDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfNewMoonHours, 0.0, 0.0, daylightSaving, zoneCorrectionHours, integerDay, gDateOfNewMoonMonth, gDateOfNewMoonYear); + + var utMaxEclipse = PAMacros.UTMaxSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); + var utFirstContact = PAMacros.UTFirstContactSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); + var utLastContact = PAMacros.UTLastContactSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); + var magnitude = PAMacros.MagSolarEclipse(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongitudeDeg, geogLatitudeDeg); + + var solarEclipseCertainDateDay = localCivilDateDay; + var solarEclipseCertainDateMonth = localCivilDateMonth; + var solarEclipseCertainDateYear = localCivilDateYear; + + var utFirstContactHour = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utFirstContact + 0.008333); + var utFirstContactMinutes = (utFirstContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utFirstContact + 0.008333); + + var utMidEclipseHour = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utMaxEclipse + 0.008333); + var utMidEclipseMinutes = (utMaxEclipse == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utMaxEclipse + 0.008333); + + var utLastContactHour = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursHour(utLastContact + 0.008333); + var utLastContactMinutes = (utLastContact == -99.0) ? -99.0 : PAMacros.DecimalHoursMinute(utLastContact + 0.008333); + + var eclipseMagnitude = (magnitude == -99.0) ? -99.0 : Math.Round(magnitude, 3); + + return (solarEclipseCertainDateDay, solarEclipseCertainDateMonth, solarEclipseCertainDateYear, utFirstContactHour, utFirstContactMinutes, utMidEclipseHour, utMidEclipseMinutes, utLastContactHour, utLastContactMinutes, eclipseMagnitude); } -} \ No newline at end of file +} diff --git a/PALib/PAMacros.cs b/PALib/PAMacros.cs index 76f480c..094635a 100644 --- a/PALib/PAMacros.cs +++ b/PALib/PAMacros.cs @@ -4,5739 +4,5738 @@ using PALib.Data; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Miscellaneous macro functions supporting the other classes. +/// +public static class PAMacros { /// - /// Miscellaneous macro functions supporting the other classes. + /// Convert a Civil Time (hours,minutes,seconds) to Decimal Hours /// - public static class PAMacros + /// + /// Original macro name: HMSDH + /// + public static double HMStoDH(double hours, double minutes, double seconds) { - /// - /// Convert a Civil Time (hours,minutes,seconds) to Decimal Hours - /// - /// - /// Original macro name: HMSDH - /// - public static double HMStoDH(double hours, double minutes, double seconds) - { - double fHours = hours; - double fMinutes = minutes; - double fSeconds = seconds; + double fHours = hours; + double fMinutes = minutes; + double fSeconds = seconds; - var a = Math.Abs(fSeconds) / 60; - var b = (Math.Abs(fMinutes) + a) / 60; - var c = Math.Abs(fHours) + b; + var a = Math.Abs(fSeconds) / 60; + var b = (Math.Abs(fMinutes) + a) / 60; + var c = Math.Abs(fHours) + b; - return (fHours < 0 || fMinutes < 0 || fSeconds < 0) ? -c : c; - } + return (fHours < 0 || fMinutes < 0 || fSeconds < 0) ? -c : c; + } - /// - /// Return the hour part of a Decimal Hours - /// - /// - /// Original macro name: DHHour - /// - public static int DecimalHoursHour(double decimalHours) - { - var a = Math.Abs(decimalHours); - var b = a * 3600; - var c = Math.Round(b - 60 * (b / 60).Floor(), 2); - var e = (c == 60) ? b + 60 : b; + /// + /// Return the hour part of a Decimal Hours + /// + /// + /// Original macro name: DHHour + /// + public static int DecimalHoursHour(double decimalHours) + { + var a = Math.Abs(decimalHours); + var b = a * 3600; + var c = Math.Round(b - 60 * (b / 60).Floor(), 2); + var e = (c == 60) ? b + 60 : b; - return (decimalHours < 0) ? (int)-((e / 3600).Floor()) : (int)(e / 3600).Floor(); - } + return (decimalHours < 0) ? (int)-((e / 3600).Floor()) : (int)(e / 3600).Floor(); + } - /// - /// Return the minutes part of a Decimal Hours - /// - /// - /// Original macro name: DHMin - /// - public static int DecimalHoursMinute(double decimalHours) - { - var a = Math.Abs(decimalHours); - var b = a * 3600; - var c = Math.Round(b - 60 * (b / 60).Floor(), 2); - var e = (c == 60) ? b + 60 : b; + /// + /// Return the minutes part of a Decimal Hours + /// + /// + /// Original macro name: DHMin + /// + public static int DecimalHoursMinute(double decimalHours) + { + var a = Math.Abs(decimalHours); + var b = a * 3600; + var c = Math.Round(b - 60 * (b / 60).Floor(), 2); + var e = (c == 60) ? b + 60 : b; - return (int)(e / 60).Floor() % 60; - } + return (int)(e / 60).Floor() % 60; + } - /// - /// Return the seconds part of a Decimal Hours - /// - /// - /// Original macro name: DHSec - /// - public static double DecimalHoursSecond(double decimalHours) - { - var a = Math.Abs(decimalHours); - var b = a * 3600; - var c = Math.Round(b - 60 * (b / 60).Floor(), 2); - var d = (c == 60) ? 0 : c; + /// + /// Return the seconds part of a Decimal Hours + /// + /// + /// Original macro name: DHSec + /// + public static double DecimalHoursSecond(double decimalHours) + { + var a = Math.Abs(decimalHours); + var b = a * 3600; + var c = Math.Round(b - 60 * (b / 60).Floor(), 2); + var d = (c == 60) ? 0 : c; - return d; - } + return d; + } - /// - /// Convert a Greenwich Date/Civil Date (day,month,year) to Julian Date - /// - /// - /// Original macro name: CDJD - /// - public static double CivilDateToJulianDate(double day, double month, double year) - { - var fDay = (double)day; - var fMonth = (double)month; - var fYear = (double)year; + /// + /// Convert a Greenwich Date/Civil Date (day,month,year) to Julian Date + /// + /// + /// Original macro name: CDJD + /// + public static double CivilDateToJulianDate(double day, double month, double year) + { + var fDay = (double)day; + var fMonth = (double)month; + var fYear = (double)year; - var y = (fMonth < 3) ? fYear - 1 : fYear; - var m = (fMonth < 3) ? fMonth + 12 : fMonth; + var y = (fMonth < 3) ? fYear - 1 : fYear; + var m = (fMonth < 3) ? fMonth + 12 : fMonth; - double b; + double b; - if (fYear > 1582) + if (fYear > 1582) + { + var a = (y / 100).Floor(); + b = 2 - a + (a / 4).Floor(); + } + else + { + if (fYear == 1582 && fMonth > 10) { var a = (y / 100).Floor(); b = 2 - a + (a / 4).Floor(); } else { - if (fYear == 1582 && fMonth > 10) + if (fYear == 1582 && fMonth == 10 && fDay >= 15) { var a = (y / 100).Floor(); b = 2 - a + (a / 4).Floor(); } else - { - if (fYear == 1582 && fMonth == 10 && fDay >= 15) - { - var a = (y / 100).Floor(); - b = 2 - a + (a / 4).Floor(); - } - else - b = 0; - } + b = 0; } - - var c = (y < 0) ? (((365.25 * y) - 0.75)).Floor() : (365.25 * y).Floor(); - var d = (30.6001 * (m + 1.0)).Floor(); - - return b + c + d + fDay + 1720994.5; - } - - /// - /// Returns the day part of a Julian Date - /// - /// - /// Original macro name: JDCDay - /// - public static double JulianDateDay(double julianDate) - { - var i = (julianDate + 0.5).Floor(); - var f = julianDate + 0.5 - i; - var a = ((i - 1867216.25) / 36524.25).Floor(); - var b = (i > 2299160) ? i + 1 + a - (a / 4).Floor() : i; - var c = b + 1524; - var d = ((c - 122.1) / 365.25).Floor(); - var e = (365.25 * d).Floor(); - var g = ((c - e) / 30.6001).Floor(); - - return c - e + f - (30.6001 * g).Floor(); } - /// - /// Returns the month part of a Julian Date - /// - /// - /// Original macro name: JDCMonth - /// - public static int JulianDateMonth(double julianDate) - { - var i = (julianDate + 0.5).Floor(); - var a = ((i - 1867216.25) / 36524.25).Floor(); - var b = (i > 2299160) ? i + 1 + a - (a / 4).Floor() : i; - var c = b + 1524; - var d = ((c - 122.1) / 365.25).Floor(); - var e = (365.25 * d).Floor(); - var g = ((c - e) / 30.6001).Floor(); - - var returnValue = (g < 13.5) ? g - 1 : g - 13; - - return (int)returnValue; - } + var c = (y < 0) ? (((365.25 * y) - 0.75)).Floor() : (365.25 * y).Floor(); + var d = (30.6001 * (m + 1.0)).Floor(); - /// - /// Returns the year part of a Julian Date - /// - /// - /// Original macro name: JDCYear - /// - public static int JulianDateYear(double julianDate) - { - var i = (julianDate + 0.5).Floor(); - var a = ((i - 1867216.25) / 36524.25).Floor(); - var b = (i > 2299160) ? i + 1.0 + a - (a / 4.0).Floor() : i; - var c = b + 1524; - var d = ((c - 122.1) / 365.25).Floor(); - var e = (365.25 * d).Floor(); - var g = ((c - e) / 30.6001).Floor(); - var h = (g < 13.5) ? g - 1 : g - 13; - - var returnValue = (h > 2.5) ? d - 4716 : d - 4715; - - return (int)returnValue; - } + return b + c + d + fDay + 1720994.5; + } - /// - /// Convert Right Ascension to Hour Angle - /// - /// - /// Original macro name: RAHA - /// - public static double RightAscensionToHourAngle(double raHours, double raMinutes, double raSeconds, double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) - { - var a = LocalCivilTimeToUniversalTime(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var b = LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var c = LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var d = LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var e = UniversalTimeToGreenwichSiderealTime(a, 0, 0, b, c, d); - var f = GreenwichSiderealTimeToLocalSiderealTime(e, 0, 0, geographicalLongitude); - var g = HMStoDH(raHours, raMinutes, raSeconds); - var h = f - g; - - return (h < 0) ? 24 + h : h; - } + /// + /// Returns the day part of a Julian Date + /// + /// + /// Original macro name: JDCDay + /// + public static double JulianDateDay(double julianDate) + { + var i = (julianDate + 0.5).Floor(); + var f = julianDate + 0.5 - i; + var a = ((i - 1867216.25) / 36524.25).Floor(); + var b = (i > 2299160) ? i + 1 + a - (a / 4).Floor() : i; + var c = b + 1524; + var d = ((c - 122.1) / 365.25).Floor(); + var e = (365.25 * d).Floor(); + var g = ((c - e) / 30.6001).Floor(); + + return c - e + f - (30.6001 * g).Floor(); + } - /// - /// Convert Hour Angle to Right Ascension - /// - /// - /// Original macro name: HARA - /// - public static double HourAngleToRightAscension(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) - { - var a = LocalCivilTimeToUniversalTime(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var b = LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var c = LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var d = LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var e = UniversalTimeToGreenwichSiderealTime(a, 0, 0, b, c, d); - var f = GreenwichSiderealTimeToLocalSiderealTime(e, 0, 00, geographicalLongitude); - var g = HMStoDH(hourAngleHours, hourAngleMinutes, hourAngleSeconds); - var h = f - g; - - return (h < 0) ? 24 + h : h; - } + /// + /// Returns the month part of a Julian Date + /// + /// + /// Original macro name: JDCMonth + /// + public static int JulianDateMonth(double julianDate) + { + var i = (julianDate + 0.5).Floor(); + var a = ((i - 1867216.25) / 36524.25).Floor(); + var b = (i > 2299160) ? i + 1 + a - (a / 4).Floor() : i; + var c = b + 1524; + var d = ((c - 122.1) / 365.25).Floor(); + var e = (365.25 * d).Floor(); + var g = ((c - e) / 30.6001).Floor(); - /// - /// Convert Local Civil Time to Universal Time - /// - /// - /// Original macro name: LctUT - /// - public static double LocalCivilTimeToUniversalTime(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) - { - var a = HMStoDH(lctHours, lctMinutes, lctSeconds); - var b = a - daylightSaving - zoneCorrection; - var c = localDay + (b / 24); - var d = CivilDateToJulianDate(c, localMonth, localYear); - var e = JulianDateDay(d); - var e1 = e.Floor(); - - return 24 * (e - e1); - } + var returnValue = (g < 13.5) ? g - 1 : g - 13; - /// - /// Convert Universal Time to Local Civil Time - /// - /// - /// Original macro name: UTLct - /// - public static double UniversalTimeToLocalCivilTime(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) - { - var a = HMStoDH(uHours, uMinutes, uSeconds); - var b = a + zoneCorrection; - var c = b + daylightSaving; - var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24); - var e = JulianDateDay(d); - var e1 = e.Floor(); - - return 24 * (e - e1); - } + return (int)returnValue; + } - /// - /// Get Local Civil Day for Universal Time - /// - /// - /// Original macro name: UTLcDay - /// - public static double UniversalTime_LocalCivilDay(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) - { - var a = HMStoDH(uHours, uMinutes, uSeconds); - var b = a + zoneCorrection; - var c = b + daylightSaving; - var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24.0); - var e = JulianDateDay(d); - var e1 = e.Floor(); - - return e1; - } + /// + /// Returns the year part of a Julian Date + /// + /// + /// Original macro name: JDCYear + /// + public static int JulianDateYear(double julianDate) + { + var i = (julianDate + 0.5).Floor(); + var a = ((i - 1867216.25) / 36524.25).Floor(); + var b = (i > 2299160) ? i + 1.0 + a - (a / 4.0).Floor() : i; + var c = b + 1524; + var d = ((c - 122.1) / 365.25).Floor(); + var e = (365.25 * d).Floor(); + var g = ((c - e) / 30.6001).Floor(); + var h = (g < 13.5) ? g - 1 : g - 13; + + var returnValue = (h > 2.5) ? d - 4716 : d - 4715; + + return (int)returnValue; + } - /// - /// Get Local Civil Month for Universal Time - /// - /// - /// Original macro name: UTLcMonth - /// - public static int UniversalTime_LocalCivilMonth(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) - { - var a = HMStoDH(uHours, uMinutes, uSeconds); - var b = a + zoneCorrection; - var c = b + daylightSaving; - var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24.0); + /// + /// Convert Right Ascension to Hour Angle + /// + /// + /// Original macro name: RAHA + /// + public static double RightAscensionToHourAngle(double raHours, double raMinutes, double raSeconds, double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) + { + var a = LocalCivilTimeToUniversalTime(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var b = LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var c = LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var d = LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var e = UniversalTimeToGreenwichSiderealTime(a, 0, 0, b, c, d); + var f = GreenwichSiderealTimeToLocalSiderealTime(e, 0, 0, geographicalLongitude); + var g = HMStoDH(raHours, raMinutes, raSeconds); + var h = f - g; + + return (h < 0) ? 24 + h : h; + } - return JulianDateMonth(d); - } + /// + /// Convert Hour Angle to Right Ascension + /// + /// + /// Original macro name: HARA + /// + public static double HourAngleToRightAscension(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear, double geographicalLongitude) + { + var a = LocalCivilTimeToUniversalTime(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var b = LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var c = LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var d = LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var e = UniversalTimeToGreenwichSiderealTime(a, 0, 0, b, c, d); + var f = GreenwichSiderealTimeToLocalSiderealTime(e, 0, 00, geographicalLongitude); + var g = HMStoDH(hourAngleHours, hourAngleMinutes, hourAngleSeconds); + var h = f - g; + + return (h < 0) ? 24 + h : h; + } - /// - /// Get Local Civil Year for Universal Time - /// - /// - /// Original macro name: UTLcYear - /// - public static int UniversalTime_LocalCivilYear(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) - { - var a = HMStoDH(uHours, uMinutes, uSeconds); - var b = a + zoneCorrection; - var c = b + daylightSaving; - var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24.0); + /// + /// Convert Local Civil Time to Universal Time + /// + /// + /// Original macro name: LctUT + /// + public static double LocalCivilTimeToUniversalTime(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) + { + var a = HMStoDH(lctHours, lctMinutes, lctSeconds); + var b = a - daylightSaving - zoneCorrection; + var c = localDay + (b / 24); + var d = CivilDateToJulianDate(c, localMonth, localYear); + var e = JulianDateDay(d); + var e1 = e.Floor(); + + return 24 * (e - e1); + } - return JulianDateYear(d); - } + /// + /// Convert Universal Time to Local Civil Time + /// + /// + /// Original macro name: UTLct + /// + public static double UniversalTimeToLocalCivilTime(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) + { + var a = HMStoDH(uHours, uMinutes, uSeconds); + var b = a + zoneCorrection; + var c = b + daylightSaving; + var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24); + var e = JulianDateDay(d); + var e1 = e.Floor(); + + return 24 * (e - e1); + } - /// - /// Determine Greenwich Day for Local Time - /// - /// - /// Original macro name: LctGDay - /// - public static double LocalCivilTimeGreenwichDay(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) - { - var a = HMStoDH(lctHours, lctMinutes, lctSeconds); - var b = a - daylightSaving - zoneCorrection; - var c = localDay + (b / 24); - var d = CivilDateToJulianDate(c, localMonth, localYear); - var e = JulianDateDay(d); + /// + /// Get Local Civil Day for Universal Time + /// + /// + /// Original macro name: UTLcDay + /// + public static double UniversalTime_LocalCivilDay(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) + { + var a = HMStoDH(uHours, uMinutes, uSeconds); + var b = a + zoneCorrection; + var c = b + daylightSaving; + var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24.0); + var e = JulianDateDay(d); + var e1 = e.Floor(); + + return e1; + } - return e.Floor(); - } + /// + /// Get Local Civil Month for Universal Time + /// + /// + /// Original macro name: UTLcMonth + /// + public static int UniversalTime_LocalCivilMonth(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) + { + var a = HMStoDH(uHours, uMinutes, uSeconds); + var b = a + zoneCorrection; + var c = b + daylightSaving; + var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24.0); - /// - /// Determine Greenwich Month for Local Time - /// - /// - /// Original macro name: LctGMonth - /// - public static int LocalCivilTimeGreenwichMonth(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) - { - var a = HMStoDH(lctHours, lctMinutes, lctSeconds); - var b = a - daylightSaving - zoneCorrection; - var c = localDay + (b / 24); - var d = CivilDateToJulianDate(c, localMonth, localYear); + return JulianDateMonth(d); + } - return JulianDateMonth(d); - } + /// + /// Get Local Civil Year for Universal Time + /// + /// + /// Original macro name: UTLcYear + /// + public static int UniversalTime_LocalCivilYear(double uHours, double uMinutes, double uSeconds, int daylightSaving, int zoneCorrection, double greenwichDay, int greenwichMonth, int greenwichYear) + { + var a = HMStoDH(uHours, uMinutes, uSeconds); + var b = a + zoneCorrection; + var c = b + daylightSaving; + var d = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) + (c / 24.0); - /// - /// Determine Greenwich Year for Local Time - /// - /// - /// Original macro name: LctGYear - /// - public static int LocalCivilTimeGreenwichYear(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) - { - var a = HMStoDH(lctHours, lctMinutes, lctSeconds); - var b = a - daylightSaving - zoneCorrection; - var c = localDay + (b / 24); - var d = CivilDateToJulianDate(c, localMonth, localYear); + return JulianDateYear(d); + } - return JulianDateYear(d); - } + /// + /// Determine Greenwich Day for Local Time + /// + /// + /// Original macro name: LctGDay + /// + public static double LocalCivilTimeGreenwichDay(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) + { + var a = HMStoDH(lctHours, lctMinutes, lctSeconds); + var b = a - daylightSaving - zoneCorrection; + var c = localDay + (b / 24); + var d = CivilDateToJulianDate(c, localMonth, localYear); + var e = JulianDateDay(d); - /// - /// Convert Universal Time to Greenwich Sidereal Time - /// - /// - /// Original macro name: UTGST - /// - public static double UniversalTimeToGreenwichSiderealTime(double uHours, double uMinutes, double uSeconds, double greenwichDay, int greenwichMonth, int greenwichYear) - { - var a = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); - var b = a - 2451545; - var c = b / 36525; - var d = 6.697374558 + (2400.051336 * c) + (0.000025862 * c * c); - var e = d - (24 * (d / 24).Floor()); - var f = HMStoDH(uHours, uMinutes, uSeconds); - var g = f * 1.002737909; - var h = e + g; - - return h - (24 * (h / 24).Floor()); - } + return e.Floor(); + } - /// - /// Convert Greenwich Sidereal Time to Local Sidereal Time - /// - /// - /// Original macro name: GSTLST - /// - public static double GreenwichSiderealTimeToLocalSiderealTime(double greenwichHours, double greenwichMinutes, double greenwichSeconds, double geographicalLongitude) - { - var a = HMStoDH(greenwichHours, greenwichMinutes, greenwichSeconds); - var b = geographicalLongitude / 15; - var c = a + b; + /// + /// Determine Greenwich Month for Local Time + /// + /// + /// Original macro name: LctGMonth + /// + public static int LocalCivilTimeGreenwichMonth(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) + { + var a = HMStoDH(lctHours, lctMinutes, lctSeconds); + var b = a - daylightSaving - zoneCorrection; + var c = localDay + (b / 24); + var d = CivilDateToJulianDate(c, localMonth, localYear); - return c - (24 * (c / 24).Floor()); - } + return JulianDateMonth(d); + } - /// - /// Convert Equatorial Coordinates to Azimuth (in decimal degrees) - /// - /// - /// Original macro name: EQAz - /// - public static double EquatorialCoordinatesToAzimuth(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double declinationDegrees, double declinationMinutes, double declinationSeconds, double geographicalLatitude) - { - var a = HMStoDH(hourAngleHours, hourAngleMinutes, hourAngleSeconds); - var b = a * 15; - var c = b.ToRadians(); - var d = DegreesMinutesSecondsToDecimalDegrees(declinationDegrees, declinationMinutes, declinationSeconds); - var e = d.ToRadians(); - var f = geographicalLatitude.ToRadians(); - var g = e.Sine() * f.Sine() + e.Cosine() * f.Cosine() * c.Cosine(); - var h = -e.Cosine() * f.Cosine() * c.Sine(); - var i = e.Sine() - (f.Sine() * g); - var j = Degrees(h.AngleTangent2(i)); - - return j - 360.0 * (j / 360).Floor(); - } + /// + /// Determine Greenwich Year for Local Time + /// + /// + /// Original macro name: LctGYear + /// + public static int LocalCivilTimeGreenwichYear(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear) + { + var a = HMStoDH(lctHours, lctMinutes, lctSeconds); + var b = a - daylightSaving - zoneCorrection; + var c = localDay + (b / 24); + var d = CivilDateToJulianDate(c, localMonth, localYear); - /// - /// Convert Equatorial Coordinates to Altitude (in decimal degrees) - /// - /// - /// Original macro name: EQAlt - /// - public static double EquatorialCoordinatesToAltitude(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double declinationDegrees, double declinationMinutes, double declinationSeconds, double geographicalLatitude) - { - var a = HMStoDH(hourAngleHours, hourAngleMinutes, hourAngleSeconds); - var b = a * 15; - var c = b.ToRadians(); - var d = DegreesMinutesSecondsToDecimalDegrees(declinationDegrees, declinationMinutes, declinationSeconds); - var e = d.ToRadians(); - var f = geographicalLatitude.ToRadians(); - var g = e.Sine() * f.Sine() + e.Cosine() * f.Cosine() * c.Cosine(); - - return Degrees(g.ASine()); - } + return JulianDateYear(d); + } - /// - /// Convert Degrees Minutes Seconds to Decimal Degrees - /// - /// - /// Original macro name: DMSDD - /// - public static double DegreesMinutesSecondsToDecimalDegrees(double degrees, double minutes, double seconds) - { - var a = Math.Abs(seconds) / 60; - var b = (Math.Abs(minutes) + a) / 60; - var c = Math.Abs(degrees) + b; + /// + /// Convert Universal Time to Greenwich Sidereal Time + /// + /// + /// Original macro name: UTGST + /// + public static double UniversalTimeToGreenwichSiderealTime(double uHours, double uMinutes, double uSeconds, double greenwichDay, int greenwichMonth, int greenwichYear) + { + var a = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); + var b = a - 2451545; + var c = b / 36525; + var d = 6.697374558 + (2400.051336 * c) + (0.000025862 * c * c); + var e = d - (24 * (d / 24).Floor()); + var f = HMStoDH(uHours, uMinutes, uSeconds); + var g = f * 1.002737909; + var h = e + g; + + return h - (24 * (h / 24).Floor()); + } - return (degrees < 0 || minutes < 0 || seconds < 0) ? -c : c; - } + /// + /// Convert Greenwich Sidereal Time to Local Sidereal Time + /// + /// + /// Original macro name: GSTLST + /// + public static double GreenwichSiderealTimeToLocalSiderealTime(double greenwichHours, double greenwichMinutes, double greenwichSeconds, double geographicalLongitude) + { + var a = HMStoDH(greenwichHours, greenwichMinutes, greenwichSeconds); + var b = geographicalLongitude / 15; + var c = a + b; - /// - /// Convert W to Degrees - /// - /// - /// Original macro name: Degrees - /// - public static double Degrees(double w) - { - return w * 57.29577951; - } + return c - (24 * (c / 24).Floor()); + } - /// - /// Return Degrees part of Decimal Degrees - /// - /// - /// Original macro name: DDDeg - /// - public static double DecimalDegreesDegrees(double decimalDegrees) - { - var a = Math.Abs(decimalDegrees); - var b = a * 3600; - var c = Math.Round(b - 60 * (b / 60).Floor(), 2); - var e = (c == 60) ? 60 : b; + /// + /// Convert Equatorial Coordinates to Azimuth (in decimal degrees) + /// + /// + /// Original macro name: EQAz + /// + public static double EquatorialCoordinatesToAzimuth(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double declinationDegrees, double declinationMinutes, double declinationSeconds, double geographicalLatitude) + { + var a = HMStoDH(hourAngleHours, hourAngleMinutes, hourAngleSeconds); + var b = a * 15; + var c = b.ToRadians(); + var d = DegreesMinutesSecondsToDecimalDegrees(declinationDegrees, declinationMinutes, declinationSeconds); + var e = d.ToRadians(); + var f = geographicalLatitude.ToRadians(); + var g = e.Sine() * f.Sine() + e.Cosine() * f.Cosine() * c.Cosine(); + var h = -e.Cosine() * f.Cosine() * c.Sine(); + var i = e.Sine() - (f.Sine() * g); + var j = Degrees(h.AngleTangent2(i)); + + return j - 360.0 * (j / 360).Floor(); + } - return (decimalDegrees < 0) ? -((e / 3600).Floor()) : (e / 3600).Floor(); - } + /// + /// Convert Equatorial Coordinates to Altitude (in decimal degrees) + /// + /// + /// Original macro name: EQAlt + /// + public static double EquatorialCoordinatesToAltitude(double hourAngleHours, double hourAngleMinutes, double hourAngleSeconds, double declinationDegrees, double declinationMinutes, double declinationSeconds, double geographicalLatitude) + { + var a = HMStoDH(hourAngleHours, hourAngleMinutes, hourAngleSeconds); + var b = a * 15; + var c = b.ToRadians(); + var d = DegreesMinutesSecondsToDecimalDegrees(declinationDegrees, declinationMinutes, declinationSeconds); + var e = d.ToRadians(); + var f = geographicalLatitude.ToRadians(); + var g = e.Sine() * f.Sine() + e.Cosine() * f.Cosine() * c.Cosine(); + + return Degrees(g.ASine()); + } - /// - /// Return Minutes part of Decimal Degrees - /// - /// - /// Original macro name: DDMin - /// - public static double DecimalDegreesMinutes(double decimalDegrees) - { - var a = Math.Abs(decimalDegrees); - var b = a * 3600; - var c = Math.Round(b - 60 * (b / 60).Floor(), 2); - var e = (c == 60) ? b + 60 : b; + /// + /// Convert Degrees Minutes Seconds to Decimal Degrees + /// + /// + /// Original macro name: DMSDD + /// + public static double DegreesMinutesSecondsToDecimalDegrees(double degrees, double minutes, double seconds) + { + var a = Math.Abs(seconds) / 60; + var b = (Math.Abs(minutes) + a) / 60; + var c = Math.Abs(degrees) + b; - return (e / 60).Floor() % 60; - } + return (degrees < 0 || minutes < 0 || seconds < 0) ? -c : c; + } - /// - /// Return Seconds part of Decimal Degrees - /// - /// - /// Original macro name: DDSec - /// - public static double DecimalDegreesSeconds(double decimalDegrees) - { - var a = Math.Abs(decimalDegrees); - var b = a * 3600; - var c = Math.Round(b - 60 * (b / 60).Floor(), 2); - var d = (c == 60) ? 0 : c; + /// + /// Convert W to Degrees + /// + /// + /// Original macro name: Degrees + /// + public static double Degrees(double w) + { + return w * 57.29577951; + } - return d; - } + /// + /// Return Degrees part of Decimal Degrees + /// + /// + /// Original macro name: DDDeg + /// + public static double DecimalDegreesDegrees(double decimalDegrees) + { + var a = Math.Abs(decimalDegrees); + var b = a * 3600; + var c = Math.Round(b - 60 * (b / 60).Floor(), 2); + var e = (c == 60) ? 60 : b; - /// - /// Convert Decimal Degrees to Degree-Hours - /// - /// - /// Original macro name: DDDH - /// - public static double DecimalDegreesToDegreeHours(double decimalDegrees) - { - return decimalDegrees / 15; - } + return (decimalDegrees < 0) ? -((e / 3600).Floor()) : (e / 3600).Floor(); + } - /// - /// Convert Degree-Hours to Decimal Degrees - /// - /// - /// Original macro name: DHDD - /// - public static double DegreeHoursToDecimalDegrees(double degreeHours) - { - return degreeHours * 15; - } + /// + /// Return Minutes part of Decimal Degrees + /// + /// + /// Original macro name: DDMin + /// + public static double DecimalDegreesMinutes(double decimalDegrees) + { + var a = Math.Abs(decimalDegrees); + var b = a * 3600; + var c = Math.Round(b - 60 * (b / 60).Floor(), 2); + var e = (c == 60) ? b + 60 : b; - /// - /// Convert Horizon Coordinates to Declination (in decimal degrees) - /// - /// - /// Original macro name: HORDec - /// - public static double HorizonCoordinatesToDeclination(double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds, double geographicalLatitude) - { - var a = DegreesMinutesSecondsToDecimalDegrees(azimuthDegrees, azimuthMinutes, azimuthSeconds); - var b = DegreesMinutesSecondsToDecimalDegrees(altitudeDegrees, altitudeMinutes, altitudeSeconds); - var c = a.ToRadians(); - var d = b.ToRadians(); - var e = geographicalLatitude.ToRadians(); - var f = d.Sine() * e.Sine() + d.Cosine() * e.Cosine() * c.Cosine(); - - return Degrees(f.ASine()); - } + return (e / 60).Floor() % 60; + } - /// - /// Convert Horizon Coordinates to Hour Angle (in decimal degrees) - /// - /// - /// Original macro name: HORHa - /// - public static double HorizonCoordinatesToHourAngle(double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds, double geographicalLatitude) - { - var a = DegreesMinutesSecondsToDecimalDegrees(azimuthDegrees, azimuthMinutes, azimuthSeconds); - var b = DegreesMinutesSecondsToDecimalDegrees(altitudeDegrees, altitudeMinutes, altitudeSeconds); - var c = a.ToRadians(); - var d = b.ToRadians(); - var e = geographicalLatitude.ToRadians(); - var f = d.Sine() * e.Sine() + d.Cosine() * e.Cosine() * c.Cosine(); - var g = -d.Cosine() * e.Cosine() * c.Sine(); - var h = d.Sine() - e.Sine() * f; - var i = DecimalDegreesToDegreeHours(Degrees(g.AngleTangent2(h))); - - return i - 24 * (i / 24).Floor(); - } + /// + /// Return Seconds part of Decimal Degrees + /// + /// + /// Original macro name: DDSec + /// + public static double DecimalDegreesSeconds(double decimalDegrees) + { + var a = Math.Abs(decimalDegrees); + var b = a * 3600; + var c = Math.Round(b - 60 * (b / 60).Floor(), 2); + var d = (c == 60) ? 0 : c; - /// - /// Obliquity of the Ecliptic for a Greenwich Date - /// - /// - /// Original macro name: Obliq - /// - public static double Obliq(double greenwichDay, int greenwichMonth, int greenwichYear) - { - var a = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); - var b = a - 2415020; - var c = (b / 36525) - 1; - var d = c * (46.815 + c * (0.0006 - (c * 0.00181))); - var e = d / 3600; + return d; + } - return 23.43929167 - e + NutatObl(greenwichDay, greenwichMonth, greenwichYear); - } + /// + /// Convert Decimal Degrees to Degree-Hours + /// + /// + /// Original macro name: DDDH + /// + public static double DecimalDegreesToDegreeHours(double decimalDegrees) + { + return decimalDegrees / 15; + } - /// - /// Nutation amount to be added in ecliptic longitude, in degrees. - /// - /// - /// Original macro name: NutatLong - /// - public static double NutatLong(double gd, int gm, int gy) - { - var dj = CivilDateToJulianDate(gd, gm, gy) - 2415020; - var t = dj / 36525; - var t2 = t * t; + /// + /// Convert Degree-Hours to Decimal Degrees + /// + /// + /// Original macro name: DHDD + /// + public static double DegreeHoursToDecimalDegrees(double degreeHours) + { + return degreeHours * 15; + } - var a = 100.0021358 * t; - var b = 360 * (a - a.Floor()); + /// + /// Convert Horizon Coordinates to Declination (in decimal degrees) + /// + /// + /// Original macro name: HORDec + /// + public static double HorizonCoordinatesToDeclination(double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds, double geographicalLatitude) + { + var a = DegreesMinutesSecondsToDecimalDegrees(azimuthDegrees, azimuthMinutes, azimuthSeconds); + var b = DegreesMinutesSecondsToDecimalDegrees(altitudeDegrees, altitudeMinutes, altitudeSeconds); + var c = a.ToRadians(); + var d = b.ToRadians(); + var e = geographicalLatitude.ToRadians(); + var f = d.Sine() * e.Sine() + d.Cosine() * e.Cosine() * c.Cosine(); + + return Degrees(f.ASine()); + } - var l1 = 279.6967 + 0.000303 * t2 + b; - var l2 = 2 * l1.ToRadians(); + /// + /// Convert Horizon Coordinates to Hour Angle (in decimal degrees) + /// + /// + /// Original macro name: HORHa + /// + public static double HorizonCoordinatesToHourAngle(double azimuthDegrees, double azimuthMinutes, double azimuthSeconds, double altitudeDegrees, double altitudeMinutes, double altitudeSeconds, double geographicalLatitude) + { + var a = DegreesMinutesSecondsToDecimalDegrees(azimuthDegrees, azimuthMinutes, azimuthSeconds); + var b = DegreesMinutesSecondsToDecimalDegrees(altitudeDegrees, altitudeMinutes, altitudeSeconds); + var c = a.ToRadians(); + var d = b.ToRadians(); + var e = geographicalLatitude.ToRadians(); + var f = d.Sine() * e.Sine() + d.Cosine() * e.Cosine() * c.Cosine(); + var g = -d.Cosine() * e.Cosine() * c.Sine(); + var h = d.Sine() - e.Sine() * f; + var i = DecimalDegreesToDegreeHours(Degrees(g.AngleTangent2(h))); + + return i - 24 * (i / 24).Floor(); + } - a = 1336.855231 * t; - b = 360 * (a - a.Floor()); + /// + /// Obliquity of the Ecliptic for a Greenwich Date + /// + /// + /// Original macro name: Obliq + /// + public static double Obliq(double greenwichDay, int greenwichMonth, int greenwichYear) + { + var a = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); + var b = a - 2415020; + var c = (b / 36525) - 1; + var d = c * (46.815 + c * (0.0006 - (c * 0.00181))); + var e = d / 3600; - var d1 = 270.4342 - 0.001133 * t2 + b; - var d2 = 2 * d1.ToRadians(); + return 23.43929167 - e + NutatObl(greenwichDay, greenwichMonth, greenwichYear); + } - a = 99.99736056 * t; - b = 360 * (a - a.Floor()); + /// + /// Nutation amount to be added in ecliptic longitude, in degrees. + /// + /// + /// Original macro name: NutatLong + /// + public static double NutatLong(double gd, int gm, int gy) + { + var dj = CivilDateToJulianDate(gd, gm, gy) - 2415020; + var t = dj / 36525; + var t2 = t * t; - var m1 = 358.4758 - 0.00015 * t2 + b; - m1 = m1.ToRadians(); + var a = 100.0021358 * t; + var b = 360 * (a - a.Floor()); - a = 1325.552359 * t; - b = 360 * (a - a.Floor()); + var l1 = 279.6967 + 0.000303 * t2 + b; + var l2 = 2 * l1.ToRadians(); - var m2 = 296.1046 + 0.009192 * t2 + b; - m2 = m2.ToRadians(); + a = 1336.855231 * t; + b = 360 * (a - a.Floor()); - a = 5.372616667 * t; - b = 360 * (a - a.Floor()); + var d1 = 270.4342 - 0.001133 * t2 + b; + var d2 = 2 * d1.ToRadians(); - var n1 = 259.1833 + 0.002078 * t2 - b; - n1 = n1.ToRadians(); + a = 99.99736056 * t; + b = 360 * (a - a.Floor()); - var n2 = 2.0 * n1; + var m1 = 358.4758 - 0.00015 * t2 + b; + m1 = m1.ToRadians(); - var dp = (-17.2327 - 0.01737 * t) * n1.Sine(); - dp = dp + (-1.2729 - 0.00013 * t) * (l2).Sine() + 0.2088 * (n2).Sine(); - dp = dp - 0.2037 * (d2).Sine() + (0.1261 - 0.00031 * t) * (m1).Sine(); - dp = dp + 0.0675 * (m2).Sine() - (0.0497 - 0.00012 * t) * (l2 + m1).Sine(); - dp = dp - 0.0342 * (d2 - n1).Sine() - 0.0261 * (d2 + m2).Sine(); - dp = dp + 0.0214 * (l2 - m1).Sine() - 0.0149 * (l2 - d2 + m2).Sine(); - dp = dp + 0.0124 * (l2 - n1).Sine() + 0.0114 * (d2 - m2).Sine(); + a = 1325.552359 * t; + b = 360 * (a - a.Floor()); - return dp / 3600; - } + var m2 = 296.1046 + 0.009192 * t2 + b; + m2 = m2.ToRadians(); - /// - /// Nutation of Obliquity - /// - /// - /// Original macro name: NutatObl - /// - public static double NutatObl(double greenwichDay, int greenwichMonth, int greenwichYear) - { - var dj = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) - 2415020; - var t = dj / 36525; - var t2 = t * t; + a = 5.372616667 * t; + b = 360 * (a - a.Floor()); - var a = 100.0021358 * t; - var b = 360 * (a - a.Floor()); + var n1 = 259.1833 + 0.002078 * t2 - b; + n1 = n1.ToRadians(); - var l1 = 279.6967 + 0.000303 * t2 + b; - var l2 = 2 * l1.ToRadians(); + var n2 = 2.0 * n1; - a = 1336.855231 * t; - b = 360 * (a - a.Floor()); + var dp = (-17.2327 - 0.01737 * t) * n1.Sine(); + dp = dp + (-1.2729 - 0.00013 * t) * (l2).Sine() + 0.2088 * (n2).Sine(); + dp = dp - 0.2037 * (d2).Sine() + (0.1261 - 0.00031 * t) * (m1).Sine(); + dp = dp + 0.0675 * (m2).Sine() - (0.0497 - 0.00012 * t) * (l2 + m1).Sine(); + dp = dp - 0.0342 * (d2 - n1).Sine() - 0.0261 * (d2 + m2).Sine(); + dp = dp + 0.0214 * (l2 - m1).Sine() - 0.0149 * (l2 - d2 + m2).Sine(); + dp = dp + 0.0124 * (l2 - n1).Sine() + 0.0114 * (d2 - m2).Sine(); - var d1 = 270.4342 - 0.001133 * t2 + b; - var d2 = 2 * d1.ToRadians(); + return dp / 3600; + } - a = 99.99736056 * t; - b = 360 * (a - a.Floor()); + /// + /// Nutation of Obliquity + /// + /// + /// Original macro name: NutatObl + /// + public static double NutatObl(double greenwichDay, int greenwichMonth, int greenwichYear) + { + var dj = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear) - 2415020; + var t = dj / 36525; + var t2 = t * t; - var m1 = (358.4758 - 0.00015 * t2 + b).ToRadians(); + var a = 100.0021358 * t; + var b = 360 * (a - a.Floor()); - a = 1325.552359 * t; - b = 360 * (a - a.Floor()); + var l1 = 279.6967 + 0.000303 * t2 + b; + var l2 = 2 * l1.ToRadians(); - var m2 = (296.1046 + 0.009192 * t2 + b).ToRadians(); + a = 1336.855231 * t; + b = 360 * (a - a.Floor()); - a = 5.372616667 * t; - b = 360 * (a - a.Floor()); + var d1 = 270.4342 - 0.001133 * t2 + b; + var d2 = 2 * d1.ToRadians(); - var n1 = (259.1833 + 0.002078 * t2 - b).ToRadians(); + a = 99.99736056 * t; + b = 360 * (a - a.Floor()); - var n2 = 2 * n1; + var m1 = (358.4758 - 0.00015 * t2 + b).ToRadians(); - var ddo = (9.21 + 0.00091 * t) * n1.Cosine(); - ddo = ddo + (0.5522 - 0.00029 * t) * l2.Cosine() - 0.0904 * n2.Cosine(); - ddo = ddo + 0.0884 * d2.Cosine() + 0.0216 * (l2 + m1).Cosine(); - ddo = ddo + 0.0183 * (d2 - n1).Cosine() + 0.0113 * (d2 + m2).Cosine(); - ddo = ddo - 0.0093 * (l2 - m1).Cosine() - 0.0066 * (l2 - n1).Cosine(); + a = 1325.552359 * t; + b = 360 * (a - a.Floor()); - return ddo / 3600; - } + var m2 = (296.1046 + 0.009192 * t2 + b).ToRadians(); - /// - /// Convert Local Sidereal Time to Greenwich Sidereal Time - /// - /// - /// Original macro name: LSTGST - /// - public static double LocalSiderealTimeToGreenwichSiderealTime(double localHours, double localMinutes, double localSeconds, double longitude) - { - var a = HMStoDH(localHours, localMinutes, localSeconds); - var b = longitude / 15; - var c = a - b; + a = 5.372616667 * t; + b = 360 * (a - a.Floor()); - return c - (24 * (c / 24).Floor()); - } + var n1 = (259.1833 + 0.002078 * t2 - b).ToRadians(); - /// - /// Convert Greenwich Sidereal Time to Universal Time - /// - /// - /// Original macro name: GSTUT - /// - public static double GreenwichSiderealTimeToUniversalTime(double greenwichSiderealHours, double greenwichSiderealMinutes, double greenwichSiderealSeconds, double greenwichDay, int greenwichMonth, int greenwichYear) - { - var a = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); - var b = a - 2451545; - var c = b / 36525; - var d = 6.697374558 + (2400.051336 * c) + (0.000025862 * c * c); - var e = d - (24 * (d / 24).Floor()); - var f = HMStoDH(greenwichSiderealHours, greenwichSiderealMinutes, greenwichSiderealSeconds); - var g = f - e; - var h = g - (24 * (g / 24).Floor()); - - return h * 0.9972695663; - } + var n2 = 2 * n1; - /// - /// Status of conversion of Greenwich Sidereal Time to Universal Time. - /// - /// - /// Original macro name: eGSTUT - /// - public static PAWarningFlag EGstUt(double gsh, double gsm, double gss, double gd, int gm, int gy) - { - var a = CivilDateToJulianDate(gd, gm, gy); - var b = a - 2451545; - var c = b / 36525; - var d = 6.697374558 + (2400.051336 * c) + (0.000025862 * c * c); - var e = d - (24 * (d / 24).Floor()); - var f = HMStoDH(gsh, gsm, gss); - var g = f - e; - var h = g - (24 * (g / 24).Floor()); - - return ((h * 0.9972695663) < (4.0 / 60.0)) ? PAWarningFlag.Warning : PAWarningFlag.OK; - } + var ddo = (9.21 + 0.00091 * t) * n1.Cosine(); + ddo = ddo + (0.5522 - 0.00029 * t) * l2.Cosine() - 0.0904 * n2.Cosine(); + ddo = ddo + 0.0884 * d2.Cosine() + 0.0216 * (l2 + m1).Cosine(); + ddo = ddo + 0.0183 * (d2 - n1).Cosine() + 0.0113 * (d2 + m2).Cosine(); + ddo = ddo - 0.0093 * (l2 - m1).Cosine() - 0.0066 * (l2 - n1).Cosine(); - /// - /// Calculate Sun's ecliptic longitude - /// - /// - /// Original macro name: SunLong - /// - public static double SunLong(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) - { - var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); - var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); - var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); - var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); - var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; - var t = (dj / 36525) + (ut / 876600); - var t2 = t * t; - var a = 100.0021359 * t; - var b = 360.0 * (a - a.Floor()); - - var l = 279.69668 + 0.0003025 * t2 + b; - a = 99.99736042 * t; - b = 360 * (a - a.Floor()); - - var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; - var ec = 0.01675104 - 0.0000418 * t - 0.000000126 * t2; - - var am = m1.ToRadians(); - var at = TrueAnomaly(am, ec); + return ddo / 3600; + } - a = 62.55209472 * t; - b = 360 * (a - a.Floor()); + /// + /// Convert Local Sidereal Time to Greenwich Sidereal Time + /// + /// + /// Original macro name: LSTGST + /// + public static double LocalSiderealTimeToGreenwichSiderealTime(double localHours, double localMinutes, double localSeconds, double longitude) + { + var a = HMStoDH(localHours, localMinutes, localSeconds); + var b = longitude / 15; + var c = a - b; - var a1 = (153.23 + b).ToRadians(); - a = 125.1041894 * t; - b = 360 * (a - a.Floor()); + return c - (24 * (c / 24).Floor()); + } - var b1 = (216.57 + b).ToRadians(); - a = 91.56766028 * t; - b = 360.0 * (a - a.Floor()); + /// + /// Convert Greenwich Sidereal Time to Universal Time + /// + /// + /// Original macro name: GSTUT + /// + public static double GreenwichSiderealTimeToUniversalTime(double greenwichSiderealHours, double greenwichSiderealMinutes, double greenwichSiderealSeconds, double greenwichDay, int greenwichMonth, int greenwichYear) + { + var a = CivilDateToJulianDate(greenwichDay, greenwichMonth, greenwichYear); + var b = a - 2451545; + var c = b / 36525; + var d = 6.697374558 + (2400.051336 * c) + (0.000025862 * c * c); + var e = d - (24 * (d / 24).Floor()); + var f = HMStoDH(greenwichSiderealHours, greenwichSiderealMinutes, greenwichSiderealSeconds); + var g = f - e; + var h = g - (24 * (g / 24).Floor()); + + return h * 0.9972695663; + } - var c1 = (312.69 + b).ToRadians(); - a = 1236.853095 * t; - b = 360.0 * (a - a.Floor()); + /// + /// Status of conversion of Greenwich Sidereal Time to Universal Time. + /// + /// + /// Original macro name: eGSTUT + /// + public static PAWarningFlag EGstUt(double gsh, double gsm, double gss, double gd, int gm, int gy) + { + var a = CivilDateToJulianDate(gd, gm, gy); + var b = a - 2451545; + var c = b / 36525; + var d = 6.697374558 + (2400.051336 * c) + (0.000025862 * c * c); + var e = d - (24 * (d / 24).Floor()); + var f = HMStoDH(gsh, gsm, gss); + var g = f - e; + var h = g - (24 * (g / 24).Floor()); + + return ((h * 0.9972695663) < (4.0 / 60.0)) ? PAWarningFlag.Warning : PAWarningFlag.OK; + } - var d1 = (350.74 - 0.00144 * t2 + b).ToRadians(); - var e1 = (231.19 + 20.2 * t).ToRadians(); - a = 183.1353208 * t; - b = 360.0 * (a - a.Floor()); - var h1 = (353.4 + b).ToRadians(); + /// + /// Calculate Sun's ecliptic longitude + /// + /// + /// Original macro name: SunLong + /// + public static double SunLong(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) + { + var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); + var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); + var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); + var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); + var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; + var t = (dj / 36525) + (ut / 876600); + var t2 = t * t; + var a = 100.0021359 * t; + var b = 360.0 * (a - a.Floor()); + + var l = 279.69668 + 0.0003025 * t2 + b; + a = 99.99736042 * t; + b = 360 * (a - a.Floor()); + + var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; + var ec = 0.01675104 - 0.0000418 * t - 0.000000126 * t2; + + var am = m1.ToRadians(); + var at = TrueAnomaly(am, ec); + + a = 62.55209472 * t; + b = 360 * (a - a.Floor()); + + var a1 = (153.23 + b).ToRadians(); + a = 125.1041894 * t; + b = 360 * (a - a.Floor()); + + var b1 = (216.57 + b).ToRadians(); + a = 91.56766028 * t; + b = 360.0 * (a - a.Floor()); + + var c1 = (312.69 + b).ToRadians(); + a = 1236.853095 * t; + b = 360.0 * (a - a.Floor()); + + var d1 = (350.74 - 0.00144 * t2 + b).ToRadians(); + var e1 = (231.19 + 20.2 * t).ToRadians(); + a = 183.1353208 * t; + b = 360.0 * (a - a.Floor()); + var h1 = (353.4 + b).ToRadians(); + + var d2 = 0.00134 * a1.Cosine() + 0.00154 * b1.Cosine() + 0.002 * c1.Cosine(); + d2 = d2 + 0.00179 * d1.Sine() + 0.00178 * e1.Sine(); + var d3 = 0.00000543 * a1.Sine() + 0.00001575 * b1.Sine(); + d3 = d3 + 0.00001627 * c1.Sine() + 0.00003076 * d1.Cosine(); + + var sr = at + (l - m1 + d2).ToRadians(); + var tp = 6.283185308; + + sr = sr - tp * (sr / tp).Floor(); + + return Degrees(sr); + } - var d2 = 0.00134 * a1.Cosine() + 0.00154 * b1.Cosine() + 0.002 * c1.Cosine(); - d2 = d2 + 0.00179 * d1.Sine() + 0.00178 * e1.Sine(); - var d3 = 0.00000543 * a1.Sine() + 0.00001575 * b1.Sine(); - d3 = d3 + 0.00001627 * c1.Sine() + 0.00003076 * d1.Cosine(); + /// + /// Solve Kepler's equation, and return value of the true anomaly in radians + /// + /// + /// Original macro name: TrueAnomaly + /// + public static double TrueAnomaly(double am, double ec) + { + var tp = 6.283185308; + var m = am - tp * (am / tp).Floor(); + var ae = m; - var sr = at + (l - m1 + d2).ToRadians(); - var tp = 6.283185308; + while (1 == 1) + { + var d = ae - (ec * (ae).Sine()) - m; + if (Math.Abs(d) < 0.000001) + { + break; + } + d = d / (1.0 - (ec * (ae).Cosine())); + ae = ae - d; + } + var a = ((1 + ec) / (1 - ec)).SquareRoot() * (ae / 2).Tangent(); + var at = 2.0 * a.AngleTangent(); - sr = sr - tp * (sr / tp).Floor(); + return at; + } - return Degrees(sr); - } + /// + /// Solve Kepler's equation, and return value of the eccentric anomaly in radians + /// + /// + /// Original macro name: EccentricAnomaly + /// + public static double EccentricAnomaly(double am, double ec) + { + var tp = 6.283185308; + var m = am - tp * (am / tp).Floor(); + var ae = m; - /// - /// Solve Kepler's equation, and return value of the true anomaly in radians - /// - /// - /// Original macro name: TrueAnomaly - /// - public static double TrueAnomaly(double am, double ec) + while (1 == 1) { - var tp = 6.283185308; - var m = am - tp * (am / tp).Floor(); - var ae = m; + var d = ae - (ec * (ae).Sine()) - m; - while (1 == 1) + if (Math.Abs(d) < 0.000001) { - var d = ae - (ec * (ae).Sine()) - m; - if (Math.Abs(d) < 0.000001) - { - break; - } - d = d / (1.0 - (ec * (ae).Cosine())); - ae = ae - d; + break; } - var a = ((1 + ec) / (1 - ec)).SquareRoot() * (ae / 2).Tangent(); - var at = 2.0 * a.AngleTangent(); - return at; + d = d / (1 - (ec * ae.Cosine())); + ae = ae - d; } - /// - /// Solve Kepler's equation, and return value of the eccentric anomaly in radians - /// - /// - /// Original macro name: EccentricAnomaly - /// - public static double EccentricAnomaly(double am, double ec) - { - var tp = 6.283185308; - var m = am - tp * (am / tp).Floor(); - var ae = m; - - while (1 == 1) - { - var d = ae - (ec * (ae).Sine()) - m; - - if (Math.Abs(d) < 0.000001) - { - break; - } + return ae; + } - d = d / (1 - (ec * ae.Cosine())); - ae = ae - d; - } + /// + /// Calculate effects of refraction + /// + /// + /// Original macro name: Refract + /// + public static double Refract(double y2, PACoordinateType sw, double pr, double tr) + { + var y = y2.ToRadians(); - return ae; - } + var d = (sw == PACoordinateType.True) ? -1.0 : 1.0; - /// - /// Calculate effects of refraction - /// - /// - /// Original macro name: Refract - /// - public static double Refract(double y2, PACoordinateType sw, double pr, double tr) + if (d == -1) { - var y = y2.ToRadians(); - - var d = (sw == PACoordinateType.True) ? -1.0 : 1.0; + var y3 = y; + var y1 = y; + var r1 = 0.0; - if (d == -1) + while (1 == 1) { - var y3 = y; - var y1 = y; - var r1 = 0.0; + var yNew = y1 + r1; + var rfNew = RefractL3035(pr, tr, yNew, d); - while (1 == 1) + if (y < -0.087) + return 0; + + var r2 = rfNew; + + if ((r2 == 0) || (Math.Abs(r2 - r1) < 0.000001)) { - var yNew = y1 + r1; - var rfNew = RefractL3035(pr, tr, yNew, d); + var qNew = y3; - if (y < -0.087) - return 0; + return Degrees(qNew + rfNew); + } - var r2 = rfNew; + r1 = r2; + } + } - if ((r2 == 0) || (Math.Abs(r2 - r1) < 0.000001)) - { - var qNew = y3; + var rf = RefractL3035(pr, tr, y, d); - return Degrees(qNew + rfNew); - } + if (y < -0.087) + return 0; - r1 = r2; - } - } + var q = y; - var rf = RefractL3035(pr, tr, y, d); + return Degrees(q + rf); + } + /// + /// Helper function for Refract + /// + public static double RefractL3035(double pr, double tr, double y, double d) + { + if (y < 0.2617994) + { if (y < -0.087) return 0; - var q = y; + var yd = Degrees(y); + var a = ((0.00002 * yd + 0.0196) * yd + 0.1594) * pr; + var b = (273.0 + tr) * ((0.0845 * yd + 0.505) * yd + 1); - return Degrees(q + rf); + return (-(a / b) * d).ToRadians(); } - /// - /// Helper function for Refract - /// - public static double RefractL3035(double pr, double tr, double y, double d) - { - if (y < 0.2617994) - { - if (y < -0.087) - return 0; + return -d * 0.00007888888 * pr / ((273.0 + tr) * (y).Tangent()); + } - var yd = Degrees(y); - var a = ((0.00002 * yd + 0.0196) * yd + 0.1594) * pr; - var b = (273.0 + tr) * ((0.0845 * yd + 0.505) * yd + 1); + /// + /// Calculate corrected hour angle in decimal hours + /// + /// + /// Original macro name: ParallaxHA + /// + public static double ParallaxHA(double hh, double hm, double hs, double dd, double dm, double ds, PACoordinateType sw, double gp, double ht, double hp) + { + var a = gp.ToRadians(); + var c1 = a.Cosine(); + var s1 = a.Sine(); - return (-(a / b) * d).ToRadians(); - } + var u = (0.996647 * s1 / c1).AngleTangent(); + var c2 = u.Cosine(); + var s2 = u.Sine(); + var b = ht / 6378160; - return -d * 0.00007888888 * pr / ((273.0 + tr) * (y).Tangent()); - } + var rs = (0.996647 * s2) + (b * s1); - /// - /// Calculate corrected hour angle in decimal hours - /// - /// - /// Original macro name: ParallaxHA - /// - public static double ParallaxHA(double hh, double hm, double hs, double dd, double dm, double ds, PACoordinateType sw, double gp, double ht, double hp) - { - var a = gp.ToRadians(); - var c1 = a.Cosine(); - var s1 = a.Sine(); + var rc = c2 + (b * c1); + var tp = 6.283185308; + + var rp = 1.0 / hp.ToRadians().Sine(); - var u = (0.996647 * s1 / c1).AngleTangent(); - var c2 = u.Cosine(); - var s2 = u.Sine(); - var b = ht / 6378160; + var x = (DegreeHoursToDecimalDegrees(HMStoDH(hh, hm, hs))).ToRadians(); + var x1 = x; + var y = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var y1 = y; - var rs = (0.996647 * s2) + (b * s1); + var d = (sw.Equals(PACoordinateType.True)) ? 1.0 : -1.0; - var rc = c2 + (b * c1); - var tp = 6.283185308; + if (d == 1) + { + var result = ParallaxHAL2870(x, y, rc, rp, rs, tp); + return DecimalDegreesToDegreeHours(Degrees(result.p)); + } - var rp = 1.0 / hp.ToRadians().Sine(); + var p1 = 0.0; + var q1 = 0.0; + var xLoop = x; + var yLoop = y; - var x = (DegreeHoursToDecimalDegrees(HMStoDH(hh, hm, hs))).ToRadians(); - var x1 = x; - var y = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var y1 = y; + while (1 == 1) + { + var result = ParallaxHAL2870(xLoop, yLoop, rc, rp, rs, tp); + var p2 = result.p - xLoop; + var q2 = result.q - yLoop; - var d = (sw.Equals(PACoordinateType.True)) ? 1.0 : -1.0; + var aa = Math.Abs(p2 - p1); + var bb = Math.Abs(q2 - q1); - if (d == 1) + if ((aa < 0.000001) && (bb < 0.000001)) { - var result = ParallaxHAL2870(x, y, rc, rp, rs, tp); - return DecimalDegreesToDegreeHours(Degrees(result.p)); + var p = x1 - p2; + + return DecimalDegreesToDegreeHours(Degrees(p)); } - var p1 = 0.0; - var q1 = 0.0; - var xLoop = x; - var yLoop = y; + xLoop = x1 - p2; + yLoop = y1 - q2; + p1 = p2; + q1 = q2; + } - while (1 == 1) - { - var result = ParallaxHAL2870(xLoop, yLoop, rc, rp, rs, tp); - var p2 = result.p - xLoop; - var q2 = result.q - yLoop; + // return DecimalDegreesToDegreeHours(Degrees(0)); + } - var aa = Math.Abs(p2 - p1); - var bb = Math.Abs(q2 - q1); + /// + /// Helper function for parallax_ha + /// + public static (double p, double q) ParallaxHAL2870(double x, double y, double rc, double rp, double rs, double tp) + { + var cx = x.Cosine(); + var sy = y.Sine(); + var cy = y.Cosine(); - if ((aa < 0.000001) && (bb < 0.000001)) - { - var p = x1 - p2; + var aa = (rc * x.Sine()) / ((rp * cy) - (rc * cx)); - return DecimalDegreesToDegreeHours(Degrees(p)); - } + var dx = aa.AngleTangent(); + var p = x + dx; + var cp = p.Cosine(); - xLoop = x1 - p2; - yLoop = y1 - q2; - p1 = p2; - q1 = q2; - } + p = p - tp * (p / tp).Floor(); + var q = (cp * (rp * sy - rs) / (rp * cy * cx - rc)).AngleTangent(); - // return DecimalDegreesToDegreeHours(Degrees(0)); - } + return (p, q); + } - /// - /// Helper function for parallax_ha - /// - public static (double p, double q) ParallaxHAL2870(double x, double y, double rc, double rp, double rs, double tp) - { - var cx = x.Cosine(); - var sy = y.Sine(); - var cy = y.Cosine(); + /// + /// Calculate corrected declination in decimal degrees + /// + /// + /// + /// Original macro name: ParallaxDec + /// + /// + /// HH,HM,HS,DD,DM,DS,SW,GP,HT,HP + /// + /// + public static double ParallaxDec(double hh, double hm, double hs, double dd, double dm, double ds, PACoordinateType sw, double gp, double ht, double hp) + { + var a = gp.ToRadians(); + var c1 = a.Cosine(); + var s1 = a.Sine(); - var aa = (rc * x.Sine()) / ((rp * cy) - (rc * cx)); + var u = (0.996647 * s1 / c1).AngleTangent(); - var dx = aa.AngleTangent(); - var p = x + dx; - var cp = p.Cosine(); + var c2 = u.Cosine(); + var s2 = u.Sine(); + var b = ht / 6378160; + var rs = (0.996647 * s2) + (b * s1); - p = p - tp * (p / tp).Floor(); - var q = (cp * (rp * sy - rs) / (rp * cy * cx - rc)).AngleTangent(); + var rc = c2 + (b * c1); + var tp = 6.283185308; - return (p, q); - } + var rp = 1.0 / hp.ToRadians().Sine(); - /// - /// Calculate corrected declination in decimal degrees - /// - /// - /// - /// Original macro name: ParallaxDec - /// - /// - /// HH,HM,HS,DD,DM,DS,SW,GP,HT,HP - /// - /// - public static double ParallaxDec(double hh, double hm, double hs, double dd, double dm, double ds, PACoordinateType sw, double gp, double ht, double hp) - { - var a = gp.ToRadians(); - var c1 = a.Cosine(); - var s1 = a.Sine(); + var x = (DegreeHoursToDecimalDegrees(HMStoDH(hh, hm, hs))).ToRadians(); + var x1 = x; - var u = (0.996647 * s1 / c1).AngleTangent(); + var y = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var y1 = y; - var c2 = u.Cosine(); - var s2 = u.Sine(); - var b = ht / 6378160; - var rs = (0.996647 * s2) + (b * s1); + var d = (sw.Equals(PACoordinateType.True)) ? 1.0 : -1.0; - var rc = c2 + (b * c1); - var tp = 6.283185308; + if (d == 1) + { + var result = ParallaxDecL2870(x, y, rc, rp, rs, tp); - var rp = 1.0 / hp.ToRadians().Sine(); + return Degrees(result.q); + } - var x = (DegreeHoursToDecimalDegrees(HMStoDH(hh, hm, hs))).ToRadians(); - var x1 = x; + var p1 = 0.0; + var q1 = 0.0; - var y = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var y1 = y; + var xLoop = x; + var yLoop = y; - var d = (sw.Equals(PACoordinateType.True)) ? 1.0 : -1.0; + while (1 == 1) + { + var result = ParallaxDecL2870(xLoop, yLoop, rc, rp, rs, tp); + var p2 = result.p - xLoop; + var q2 = result.q - yLoop; + var aa = Math.Abs(p2 - p1); - if (d == 1) + if ((aa < 0.000001) && (b < 0.000001)) { - var result = ParallaxDecL2870(x, y, rc, rp, rs, tp); + var q = y1 - q2; - return Degrees(result.q); + return Degrees(q); } + xLoop = x1 - p2; + yLoop = y1 - q2; + p1 = p2; + q1 = q2; + } - var p1 = 0.0; - var q1 = 0.0; - - var xLoop = x; - var yLoop = y; - - while (1 == 1) - { - var result = ParallaxDecL2870(xLoop, yLoop, rc, rp, rs, tp); - var p2 = result.p - xLoop; - var q2 = result.q - yLoop; - var aa = Math.Abs(p2 - p1); + // return Degrees(0.0); + } - if ((aa < 0.000001) && (b < 0.000001)) - { - var q = y1 - q2; + /// + /// Helper function for parallax_dec + /// + public static (double p, double q) ParallaxDecL2870(double x, double y, double rc, double rp, double rs, double tp) + { + var cx = x.Cosine(); + var sy = y.Sine(); + var cy = y.Cosine(); - return Degrees(q); - } - xLoop = x1 - p2; - yLoop = y1 - q2; - p1 = p2; - q1 = q2; - } + var aa = (rc * x.Sine()) / ((rp * cy) - (rc * cx)); + var dx = aa.AngleTangent(); + var p = x + dx; + var cp = p.Cosine(); - // return Degrees(0.0); - } + p = p - tp * (p / tp).Floor(); + var q = (cp * (rp * sy - rs) / (rp * cy * cx - rc)).AngleTangent(); - /// - /// Helper function for parallax_dec - /// - public static (double p, double q) ParallaxDecL2870(double x, double y, double rc, double rp, double rs, double tp) - { - var cx = x.Cosine(); - var sy = y.Sine(); - var cy = y.Cosine(); + return (p, q); + } - var aa = (rc * x.Sine()) / ((rp * cy) - (rc * cx)); - var dx = aa.AngleTangent(); - var p = x + dx; - var cp = p.Cosine(); + /// + /// Calculate Sun's angular diameter in decimal degrees + /// + /// + /// Original macro name: SunDia + /// + public static double SunDia(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) + { + var a = SunDist(lch, lcm, lcs, ds, zc, ld, lm, ly); - p = p - tp * (p / tp).Floor(); - var q = (cp * (rp * sy - rs) / (rp * cy * cx - rc)).AngleTangent(); + return 0.533128 / a; + } - return (p, q); - } + /// + /// Calculate Sun's distance from the Earth in astronomical units + /// + /// + /// Original macro name: SunDist + /// + public static double SunDist(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) + { + var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); + var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); + var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); + var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); + var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; + + var t = (dj / 36525) + (ut / 876600); + var t2 = t * t; + + var a = 100.0021359 * t; + var b = 360 * (a - a.Floor()); + a = 99.99736042 * t; + b = 360 * (a - a.Floor()); + var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; + var ec = 0.01675104 - 0.0000418 * t - 0.000000126 * t2; + + var am = m1.ToRadians(); + var ae = EccentricAnomaly(am, ec); + + a = 62.55209472 * t; + b = 360 * (a - a.Floor()); + var a1 = (153.23 + b).ToRadians(); + a = 125.1041894 * t; + b = 360 * (a - a.Floor()); + var b1 = (216.57 + b).ToRadians(); + a = 91.56766028 * t; + b = 360 * (a - a.Floor()); + var c1 = (312.69 + b).ToRadians(); + a = 1236.853095 * t; + b = 360 * (a - a.Floor()); + var d1 = (350.74 - 0.00144 * t2 + b).ToRadians(); + var e1 = (231.19 + 20.2 * t).ToRadians(); + a = 183.1353208 * t; + b = 360 * (a - a.Floor()); + var h1 = (353.4 + b).ToRadians(); + + var d3 = (0.00000543 * a1.Sine() + 0.00001575 * b1.Sine()) + (0.00001627 * c1.Sine() + 0.00003076 * d1.Cosine()) + (0.00000927 * h1.Sine()); + + return 1.0000002 * (1 - ec * ae.Cosine()) + d3; + } - /// - /// Calculate Sun's angular diameter in decimal degrees - /// - /// - /// Original macro name: SunDia - /// - public static double SunDia(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) - { - var a = SunDist(lch, lcm, lcs, ds, zc, ld, lm, ly); + /// + /// Calculate geocentric ecliptic longitude for the Moon + /// + /// + /// Original macro name: MoonLong + /// + public static double MoonLong(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); + var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); + var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); + var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); + var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525) + (ut / 876600); + var t2 = t * t; + + var m1 = 27.32158213; + var m2 = 365.2596407; + var m3 = 27.55455094; + var m4 = 29.53058868; + var m5 = 27.21222039; + var m6 = 6798.363307; + var q = CivilDateToJulianDate(gd, gm, gy) - 2415020 + (ut / 24); + m1 = q / m1; + m2 = q / m2; + m3 = q / m3; + m4 = q / m4; + m5 = q / m5; + m6 = q / m6; + m1 = 360 * (m1 - (m1).Floor()); + m2 = 360 * (m2 - (m2).Floor()); + m3 = 360 * (m3 - (m3).Floor()); + m4 = 360 * (m4 - (m4).Floor()); + m5 = 360 * (m5 - (m5).Floor()); + m6 = 360 * (m6 - (m6).Floor()); + + var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; + var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; + var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; + var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; + var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; + var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; + var a = (51.2 + 20.2 * t).ToRadians(); + var s1 = a.Sine(); + var s2 = ((na).ToRadians()).Sine(); + var b = 346.56 + (132.87 - 0.0091731 * t) * t; + var s3 = 0.003964 * ((b).ToRadians()).Sine(); + var c = (na + 275.05 - 2.3 * t).ToRadians(); + var s4 = c.Sine(); + ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; + ms = ms - 0.001778 * s1; + md = md + 0.000817 * s1 + s3 + 0.002541 * s2; + mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; + me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; + var e = 1.0 - (0.002495 + 0.00000752 * t) * t; + var e2 = e * e; + ml = (ml).ToRadians(); + ms = ms.ToRadians(); + me1 = me1.ToRadians(); + mf = mf.ToRadians(); + md = md.ToRadians(); + + var l = 6.28875 * (md).Sine() + 1.274018 * (2.0 * me1 - md).Sine(); + l = l + 0.658309 * (2.0 * me1).Sine() + 0.213616 * (2.0 * md).Sine(); + l = l - e * 0.185596 * (ms).Sine() - 0.114336 * (2.0 * mf).Sine(); + l = l + 0.058793 * (2.0 * (me1 - md)).Sine(); + l = l + 0.057212 * e * (2.0 * me1 - ms - md).Sine() + 0.05332 * (2.0 * me1 + md).Sine(); + l = l + 0.045874 * e * (2.0 * me1 - ms).Sine() + 0.041024 * e * (md - ms).Sine(); + l = l - 0.034718 * (me1).Sine() - e * 0.030465 * (ms + md).Sine(); + l = l + 0.015326 * (2.0 * (me1 - mf)).Sine() - 0.012528 * (2.0 * mf + md).Sine(); + l = l - 0.01098 * (2.0 * mf - md).Sine() + 0.010674 * (4.0 * me1 - md).Sine(); + l = l + 0.010034 * (3.0 * md).Sine() + 0.008548 * (4.0 * me1 - 2.0 * md).Sine(); + l = l - e * 0.00791 * (ms - md + 2.0 * me1).Sine() - e * 0.006783 * (2.0 * me1 + ms).Sine(); + l = l + 0.005162 * (md - me1).Sine() + e * 0.005 * (ms + me1).Sine(); + l = l + 0.003862 * (4.0 * me1).Sine() + e * 0.004049 * (md - ms + 2.0 * me1).Sine(); + l = l + 0.003996 * (2.0 * (md + me1)).Sine() + 0.003665 * (2.0 * me1 - 3.0 * md).Sine(); + l = l + e * 0.002695 * (2.0 * md - ms).Sine() + 0.002602 * (md - 2.0 * (mf + me1)).Sine(); + l = l + e * 0.002396 * (2.0 * (me1 - md) - ms).Sine() - 0.002349 * (md + me1).Sine(); + l = l + e2 * 0.002249 * (2.0 * (me1 - ms)).Sine() - e * 0.002125 * (2.0 * md + ms).Sine(); + l = l - e2 * 0.002079 * (2.0 * ms).Sine() + e2 * 0.002059 * (2.0 * (me1 - ms) - md).Sine(); + l = l - 0.001773 * (md + 2.0 * (me1 - mf)).Sine() - 0.001595 * (2.0 * (mf + me1)).Sine(); + l = l + e * 0.00122 * (4.0 * me1 - ms - md).Sine() - 0.00111 * (2.0 * (md + mf)).Sine(); + l = l + 0.000892 * (md - 3.0 * me1).Sine() - e * 0.000811 * (ms + md + 2.0 * me1).Sine(); + l = l + e * 0.000761 * (4.0 * me1 - ms - 2.0 * md).Sine(); + l = l + e2 * 0.000704 * (md - 2.0 * (ms + me1)).Sine(); + l = l + e * 0.000693 * (ms - 2.0 * (md - me1)).Sine(); + l = l + e * 0.000598 * (2.0 * (me1 - mf) - ms).Sine(); + l = l + 0.00055 * (md + 4.0 * me1).Sine() + 0.000538 * (4.0 * md).Sine(); + l = l + e * 0.000521 * (4.0 * me1 - ms).Sine() + 0.000486 * (2.0 * md - me1).Sine(); + l = l + e2 * 0.000717 * (md - 2.0 * ms).Sine(); + var mm = Unwind(ml + l.ToRadians()); + + return Degrees(mm); + } - return 0.533128 / a; - } + /// + /// Calculate geocentric ecliptic latitude for the Moon + /// + /// + /// Original macro name: MoonLat + /// + public static double MoonLat(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); + var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); + var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); + var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); + var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525) + (ut / 876600); + var t2 = t * t; + + var m1 = 27.32158213; + var m2 = 365.2596407; + var m3 = 27.55455094; + var m4 = 29.53058868; + var m5 = 27.21222039; + var m6 = 6798.363307; + var q = CivilDateToJulianDate(gd, gm, gy) - 2415020 + (ut / 24); + m1 = q / m1; + m2 = q / m2; + m3 = q / m3; + m4 = q / m4; + m5 = q / m5; + m6 = q / m6; + m1 = 360 * (m1 - (m1).Floor()); + m2 = 360 * (m2 - (m2).Floor()); + m3 = 360 * (m3 - (m3).Floor()); + m4 = 360 * (m4 - (m4).Floor()); + m5 = 360 * (m5 - (m5).Floor()); + m6 = 360 * (m6 - (m6).Floor()); + + var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; + var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; + var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; + var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; + var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; + var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; + var a = (51.2 + 20.2 * t).ToRadians(); + var s1 = (a).Sine(); + var s2 = na.ToRadians().Sine(); + var b = 346.56 + (132.87 - 0.0091731 * t) * t; + var s3 = 0.003964 * b.ToRadians().Sine(); + var c = (na + 275.05 - 2.3 * t).ToRadians(); + var s4 = (c).Sine(); + ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; + ms = ms - 0.001778 * s1; + md = md + 0.000817 * s1 + s3 + 0.002541 * s2; + mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; + me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; + var e = 1.0 - (0.002495 + 0.00000752 * t) * t; + var e2 = e * e; + ms = (ms).ToRadians(); + na = (na).ToRadians(); + me1 = (me1).ToRadians(); + mf = (mf).ToRadians(); + md = (md).ToRadians(); + + var g = 5.128189 * (mf).Sine() + 0.280606 * (md + mf).Sine(); + g = g + 0.277693 * (md - mf).Sine() + 0.173238 * (2.0 * me1 - mf).Sine(); + g = g + 0.055413 * (2.0 * me1 + mf - md).Sine() + 0.046272 * (2.0 * me1 - mf - md).Sine(); + g = g + 0.032573 * (2.0 * me1 + mf).Sine() + 0.017198 * (2.0 * md + mf).Sine(); + g = g + 0.009267 * (2.0 * me1 + md - mf).Sine() + 0.008823 * (2.0 * md - mf).Sine(); + g = g + e * 0.008247 * (2.0 * me1 - ms - mf).Sine() + 0.004323 * (2.0 * (me1 - md) - mf).Sine(); + g = g + 0.0042 * (2.0 * me1 + mf + md).Sine() + e * 0.003372 * (mf - ms - 2.0 * me1).Sine(); + g = g + e * 0.002472 * (2.0 * me1 + mf - ms - md).Sine(); + g = g + e * 0.002222 * (2.0 * me1 + mf - ms).Sine(); + g = g + e * 0.002072 * (2.0 * me1 - mf - ms - md).Sine(); + g = g + e * 0.001877 * (mf - ms + md).Sine() + 0.001828 * (4.0 * me1 - mf - md).Sine(); + g = g - e * 0.001803 * (mf + ms).Sine() - 0.00175 * (3.0 * mf).Sine(); + g = g + e * 0.00157 * (md - ms - mf).Sine() - 0.001487 * (mf + me1).Sine(); + g = g - e * 0.001481 * (mf + ms + md).Sine() + e * 0.001417 * (mf - ms - md).Sine(); + g = g + e * 0.00135 * (mf - ms).Sine() + 0.00133 * (mf - me1).Sine(); + g = g + 0.001106 * (mf + 3.0 * md).Sine() + 0.00102 * (4.0 * me1 - mf).Sine(); + g = g + 0.000833 * (mf + 4.0 * me1 - md).Sine() + 0.000781 * (md - 3.0 * mf).Sine(); + g = g + 0.00067 * (mf + 4.0 * me1 - 2.0 * md).Sine() + 0.000606 * (2.0 * me1 - 3.0 * mf).Sine(); + g = g + 0.000597 * (2.0 * (me1 + md) - mf).Sine(); + g = g + e * 0.000492 * (2.0 * me1 + md - ms - mf).Sine() + 0.00045 * (2.0 * (md - me1) - mf).Sine(); + g = g + 0.000439 * (3.0 * md - mf).Sine() + 0.000423 * (mf + 2.0 * (me1 + md)).Sine(); + g = g + 0.000422 * (2.0 * me1 - mf - 3.0 * md).Sine() - e * 0.000367 * (ms + mf + 2.0 * me1 - md).Sine(); + g = g - e * 0.000353 * (ms + mf + 2.0 * me1).Sine() + 0.000331 * (mf + 4.0 * me1).Sine(); + g = g + e * 0.000317 * (2.0 * me1 + mf - ms + md).Sine(); + g = g + e2 * 0.000306 * (2.0 * (me1 - ms) - mf).Sine() - 0.000283 * (md + 3.0 * mf).Sine(); + var w1 = 0.0004664 * (na).Cosine(); + var w2 = 0.0000754 * (c).Cosine(); + var bm = (g).ToRadians() * (1.0 - w1 - w2); + + return Degrees(bm); + } - /// - /// Calculate Sun's distance from the Earth in astronomical units - /// - /// - /// Original macro name: SunDist - /// - public static double SunDist(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) - { - var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); - var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); - var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); - var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); - var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; - - var t = (dj / 36525) + (ut / 876600); - var t2 = t * t; - - var a = 100.0021359 * t; - var b = 360 * (a - a.Floor()); - a = 99.99736042 * t; - b = 360 * (a - a.Floor()); - var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; - var ec = 0.01675104 - 0.0000418 * t - 0.000000126 * t2; - - var am = m1.ToRadians(); - var ae = EccentricAnomaly(am, ec); - - a = 62.55209472 * t; - b = 360 * (a - a.Floor()); - var a1 = (153.23 + b).ToRadians(); - a = 125.1041894 * t; - b = 360 * (a - a.Floor()); - var b1 = (216.57 + b).ToRadians(); - a = 91.56766028 * t; - b = 360 * (a - a.Floor()); - var c1 = (312.69 + b).ToRadians(); - a = 1236.853095 * t; - b = 360 * (a - a.Floor()); - var d1 = (350.74 - 0.00144 * t2 + b).ToRadians(); - var e1 = (231.19 + 20.2 * t).ToRadians(); - a = 183.1353208 * t; - b = 360 * (a - a.Floor()); - var h1 = (353.4 + b).ToRadians(); - - var d3 = (0.00000543 * a1.Sine() + 0.00001575 * b1.Sine()) + (0.00001627 * c1.Sine() + 0.00003076 * d1.Cosine()) + (0.00000927 * h1.Sine()); - - return 1.0000002 * (1 - ec * ae.Cosine()) + d3; - } + /// + /// Calculate horizontal parallax for the Moon + /// + /// + /// Original macro name: MoonHP + /// + public static double MoonHP(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); + var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); + var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); + var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); + var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525) + (ut / 876600); + var t2 = t * t; + + var m1 = 27.32158213; + var m2 = 365.2596407; + var m3 = 27.55455094; + var m4 = 29.53058868; + var m5 = 27.21222039; + var m6 = 6798.363307; + var q = CivilDateToJulianDate(gd, gm, gy) - 2415020 + (ut / 24); + m1 = q / m1; + m2 = q / m2; + m3 = q / m3; + m4 = q / m4; + m5 = q / m5; + m6 = q / m6; + m1 = 360 * (m1 - (m1).Floor()); + m2 = 360 * (m2 - (m2).Floor()); + m3 = 360 * (m3 - (m3).Floor()); + m4 = 360 * (m4 - (m4).Floor()); + m5 = 360 * (m5 - (m5).Floor()); + m6 = 360 * (m6 - (m6).Floor()); + + var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; + var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; + var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; + var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; + var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; + var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; + var a = (51.2 + 20.2 * t).ToRadians(); + var s1 = a.Sine(); + var s2 = na.ToRadians().Sine(); + var b = 346.56 + (132.87 - 0.0091731 * t) * t; + var s3 = 0.003964 * b.ToRadians().Sine(); + var c = (na + 275.05 - 2.3 * t).ToRadians(); + var s4 = c.Sine(); + ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; + ms = ms - 0.001778 * s1; + md = md + 0.000817 * s1 + s3 + 0.002541 * s2; + mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; + me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; + var e = 1.0 - (0.002495 + 0.00000752 * t) * t; + var e2 = e * e; + ms = (ms).ToRadians(); + me1 = (me1).ToRadians(); + mf = (mf).ToRadians(); + md = (md).ToRadians(); + + var pm = 0.950724 + 0.051818 * (md).Cosine() + 0.009531 * (2.0 * me1 - md).Cosine(); + pm = pm + 0.007843 * (2.0 * me1).Cosine() + 0.002824 * (2.0 * md).Cosine(); + pm = pm + 0.000857 * (2.0 * me1 + md).Cosine() + e * 0.000533 * (2.0 * me1 - ms).Cosine(); + pm = pm + e * 0.000401 * (2.0 * me1 - md - ms).Cosine(); + pm = pm + e * 0.00032 * (md - ms).Cosine() - 0.000271 * (me1).Cosine(); + pm = pm - e * 0.000264 * (ms + md).Cosine() - 0.000198 * (2.0 * mf - md).Cosine(); + pm = pm + 0.000173 * (3.0 * md).Cosine() + 0.000167 * (4.0 * me1 - md).Cosine(); + pm = pm - e * 0.000111 * (ms).Cosine() + 0.000103 * (4.0 * me1 - 2.0 * md).Cosine(); + pm = pm - 0.000084 * (2.0 * md - 2.0 * me1).Cosine() - e * 0.000083 * (2.0 * me1 + ms).Cosine(); + pm = pm + 0.000079 * (2.0 * me1 + 2.0 * md).Cosine() + 0.000072 * (4.0 * me1).Cosine(); + pm = pm + e * 0.000064 * (2.0 * me1 - ms + md).Cosine() - e * 0.000063 * (2.0 * me1 + ms - md).Cosine(); + pm = pm + e * 0.000041 * (ms + me1).Cosine() + e * 0.000035 * (2.0 * md - ms).Cosine(); + pm = pm - 0.000033 * (3.0 * md - 2.0 * me1).Cosine() - 0.00003 * (md + me1).Cosine(); + pm = pm - 0.000029 * (2.0 * (mf - me1)).Cosine() - e * 0.000029 * (2.0 * md + ms).Cosine(); + pm = pm + e2 * 0.000026 * (2.0 * (me1 - ms)).Cosine() - 0.000023 * (2.0 * (mf - me1) + md).Cosine(); + pm = pm + e * 0.000019 * (4.0 * me1 - ms - md).Cosine(); + + return pm; + } - /// - /// Calculate geocentric ecliptic longitude for the Moon - /// - /// - /// Original macro name: MoonLong - /// - public static double MoonLong(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); - var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); - var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); - var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); - var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525) + (ut / 876600); - var t2 = t * t; - - var m1 = 27.32158213; - var m2 = 365.2596407; - var m3 = 27.55455094; - var m4 = 29.53058868; - var m5 = 27.21222039; - var m6 = 6798.363307; - var q = CivilDateToJulianDate(gd, gm, gy) - 2415020 + (ut / 24); - m1 = q / m1; - m2 = q / m2; - m3 = q / m3; - m4 = q / m4; - m5 = q / m5; - m6 = q / m6; - m1 = 360 * (m1 - (m1).Floor()); - m2 = 360 * (m2 - (m2).Floor()); - m3 = 360 * (m3 - (m3).Floor()); - m4 = 360 * (m4 - (m4).Floor()); - m5 = 360 * (m5 - (m5).Floor()); - m6 = 360 * (m6 - (m6).Floor()); - - var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; - var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; - var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; - var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; - var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; - var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; - var a = (51.2 + 20.2 * t).ToRadians(); - var s1 = a.Sine(); - var s2 = ((na).ToRadians()).Sine(); - var b = 346.56 + (132.87 - 0.0091731 * t) * t; - var s3 = 0.003964 * ((b).ToRadians()).Sine(); - var c = (na + 275.05 - 2.3 * t).ToRadians(); - var s4 = c.Sine(); - ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; - ms = ms - 0.001778 * s1; - md = md + 0.000817 * s1 + s3 + 0.002541 * s2; - mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; - me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; - var e = 1.0 - (0.002495 + 0.00000752 * t) * t; - var e2 = e * e; - ml = (ml).ToRadians(); - ms = ms.ToRadians(); - me1 = me1.ToRadians(); - mf = mf.ToRadians(); - md = md.ToRadians(); - - var l = 6.28875 * (md).Sine() + 1.274018 * (2.0 * me1 - md).Sine(); - l = l + 0.658309 * (2.0 * me1).Sine() + 0.213616 * (2.0 * md).Sine(); - l = l - e * 0.185596 * (ms).Sine() - 0.114336 * (2.0 * mf).Sine(); - l = l + 0.058793 * (2.0 * (me1 - md)).Sine(); - l = l + 0.057212 * e * (2.0 * me1 - ms - md).Sine() + 0.05332 * (2.0 * me1 + md).Sine(); - l = l + 0.045874 * e * (2.0 * me1 - ms).Sine() + 0.041024 * e * (md - ms).Sine(); - l = l - 0.034718 * (me1).Sine() - e * 0.030465 * (ms + md).Sine(); - l = l + 0.015326 * (2.0 * (me1 - mf)).Sine() - 0.012528 * (2.0 * mf + md).Sine(); - l = l - 0.01098 * (2.0 * mf - md).Sine() + 0.010674 * (4.0 * me1 - md).Sine(); - l = l + 0.010034 * (3.0 * md).Sine() + 0.008548 * (4.0 * me1 - 2.0 * md).Sine(); - l = l - e * 0.00791 * (ms - md + 2.0 * me1).Sine() - e * 0.006783 * (2.0 * me1 + ms).Sine(); - l = l + 0.005162 * (md - me1).Sine() + e * 0.005 * (ms + me1).Sine(); - l = l + 0.003862 * (4.0 * me1).Sine() + e * 0.004049 * (md - ms + 2.0 * me1).Sine(); - l = l + 0.003996 * (2.0 * (md + me1)).Sine() + 0.003665 * (2.0 * me1 - 3.0 * md).Sine(); - l = l + e * 0.002695 * (2.0 * md - ms).Sine() + 0.002602 * (md - 2.0 * (mf + me1)).Sine(); - l = l + e * 0.002396 * (2.0 * (me1 - md) - ms).Sine() - 0.002349 * (md + me1).Sine(); - l = l + e2 * 0.002249 * (2.0 * (me1 - ms)).Sine() - e * 0.002125 * (2.0 * md + ms).Sine(); - l = l - e2 * 0.002079 * (2.0 * ms).Sine() + e2 * 0.002059 * (2.0 * (me1 - ms) - md).Sine(); - l = l - 0.001773 * (md + 2.0 * (me1 - mf)).Sine() - 0.001595 * (2.0 * (mf + me1)).Sine(); - l = l + e * 0.00122 * (4.0 * me1 - ms - md).Sine() - 0.00111 * (2.0 * (md + mf)).Sine(); - l = l + 0.000892 * (md - 3.0 * me1).Sine() - e * 0.000811 * (ms + md + 2.0 * me1).Sine(); - l = l + e * 0.000761 * (4.0 * me1 - ms - 2.0 * md).Sine(); - l = l + e2 * 0.000704 * (md - 2.0 * (ms + me1)).Sine(); - l = l + e * 0.000693 * (ms - 2.0 * (md - me1)).Sine(); - l = l + e * 0.000598 * (2.0 * (me1 - mf) - ms).Sine(); - l = l + 0.00055 * (md + 4.0 * me1).Sine() + 0.000538 * (4.0 * md).Sine(); - l = l + e * 0.000521 * (4.0 * me1 - ms).Sine() + 0.000486 * (2.0 * md - me1).Sine(); - l = l + e2 * 0.000717 * (md - 2.0 * ms).Sine(); - var mm = Unwind(ml + l.ToRadians()); - - return Degrees(mm); - } + /// + /// Calculate distance from the Earth to the Moon (km) + /// + /// + /// Original macro name: MoonDist + /// + public static double MoonDist(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var hp = (MoonHP(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians(); + var r = 6378.14 / hp.Sine(); - /// - /// Calculate geocentric ecliptic latitude for the Moon - /// - /// - /// Original macro name: MoonLat - /// - public static double MoonLat(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); - var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); - var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); - var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); - var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525) + (ut / 876600); - var t2 = t * t; - - var m1 = 27.32158213; - var m2 = 365.2596407; - var m3 = 27.55455094; - var m4 = 29.53058868; - var m5 = 27.21222039; - var m6 = 6798.363307; - var q = CivilDateToJulianDate(gd, gm, gy) - 2415020 + (ut / 24); - m1 = q / m1; - m2 = q / m2; - m3 = q / m3; - m4 = q / m4; - m5 = q / m5; - m6 = q / m6; - m1 = 360 * (m1 - (m1).Floor()); - m2 = 360 * (m2 - (m2).Floor()); - m3 = 360 * (m3 - (m3).Floor()); - m4 = 360 * (m4 - (m4).Floor()); - m5 = 360 * (m5 - (m5).Floor()); - m6 = 360 * (m6 - (m6).Floor()); - - var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; - var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; - var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; - var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; - var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; - var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; - var a = (51.2 + 20.2 * t).ToRadians(); - var s1 = (a).Sine(); - var s2 = na.ToRadians().Sine(); - var b = 346.56 + (132.87 - 0.0091731 * t) * t; - var s3 = 0.003964 * b.ToRadians().Sine(); - var c = (na + 275.05 - 2.3 * t).ToRadians(); - var s4 = (c).Sine(); - ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; - ms = ms - 0.001778 * s1; - md = md + 0.000817 * s1 + s3 + 0.002541 * s2; - mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; - me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; - var e = 1.0 - (0.002495 + 0.00000752 * t) * t; - var e2 = e * e; - ms = (ms).ToRadians(); - na = (na).ToRadians(); - me1 = (me1).ToRadians(); - mf = (mf).ToRadians(); - md = (md).ToRadians(); - - var g = 5.128189 * (mf).Sine() + 0.280606 * (md + mf).Sine(); - g = g + 0.277693 * (md - mf).Sine() + 0.173238 * (2.0 * me1 - mf).Sine(); - g = g + 0.055413 * (2.0 * me1 + mf - md).Sine() + 0.046272 * (2.0 * me1 - mf - md).Sine(); - g = g + 0.032573 * (2.0 * me1 + mf).Sine() + 0.017198 * (2.0 * md + mf).Sine(); - g = g + 0.009267 * (2.0 * me1 + md - mf).Sine() + 0.008823 * (2.0 * md - mf).Sine(); - g = g + e * 0.008247 * (2.0 * me1 - ms - mf).Sine() + 0.004323 * (2.0 * (me1 - md) - mf).Sine(); - g = g + 0.0042 * (2.0 * me1 + mf + md).Sine() + e * 0.003372 * (mf - ms - 2.0 * me1).Sine(); - g = g + e * 0.002472 * (2.0 * me1 + mf - ms - md).Sine(); - g = g + e * 0.002222 * (2.0 * me1 + mf - ms).Sine(); - g = g + e * 0.002072 * (2.0 * me1 - mf - ms - md).Sine(); - g = g + e * 0.001877 * (mf - ms + md).Sine() + 0.001828 * (4.0 * me1 - mf - md).Sine(); - g = g - e * 0.001803 * (mf + ms).Sine() - 0.00175 * (3.0 * mf).Sine(); - g = g + e * 0.00157 * (md - ms - mf).Sine() - 0.001487 * (mf + me1).Sine(); - g = g - e * 0.001481 * (mf + ms + md).Sine() + e * 0.001417 * (mf - ms - md).Sine(); - g = g + e * 0.00135 * (mf - ms).Sine() + 0.00133 * (mf - me1).Sine(); - g = g + 0.001106 * (mf + 3.0 * md).Sine() + 0.00102 * (4.0 * me1 - mf).Sine(); - g = g + 0.000833 * (mf + 4.0 * me1 - md).Sine() + 0.000781 * (md - 3.0 * mf).Sine(); - g = g + 0.00067 * (mf + 4.0 * me1 - 2.0 * md).Sine() + 0.000606 * (2.0 * me1 - 3.0 * mf).Sine(); - g = g + 0.000597 * (2.0 * (me1 + md) - mf).Sine(); - g = g + e * 0.000492 * (2.0 * me1 + md - ms - mf).Sine() + 0.00045 * (2.0 * (md - me1) - mf).Sine(); - g = g + 0.000439 * (3.0 * md - mf).Sine() + 0.000423 * (mf + 2.0 * (me1 + md)).Sine(); - g = g + 0.000422 * (2.0 * me1 - mf - 3.0 * md).Sine() - e * 0.000367 * (ms + mf + 2.0 * me1 - md).Sine(); - g = g - e * 0.000353 * (ms + mf + 2.0 * me1).Sine() + 0.000331 * (mf + 4.0 * me1).Sine(); - g = g + e * 0.000317 * (2.0 * me1 + mf - ms + md).Sine(); - g = g + e2 * 0.000306 * (2.0 * (me1 - ms) - mf).Sine() - 0.000283 * (md + 3.0 * mf).Sine(); - var w1 = 0.0004664 * (na).Cosine(); - var w2 = 0.0000754 * (c).Cosine(); - var bm = (g).ToRadians() * (1.0 - w1 - w2); - - return Degrees(bm); - } + return r; + } - /// - /// Calculate horizontal parallax for the Moon - /// - /// - /// Original macro name: MoonHP - /// - public static double MoonHP(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); - var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); - var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); - var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); - var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525) + (ut / 876600); - var t2 = t * t; - - var m1 = 27.32158213; - var m2 = 365.2596407; - var m3 = 27.55455094; - var m4 = 29.53058868; - var m5 = 27.21222039; - var m6 = 6798.363307; - var q = CivilDateToJulianDate(gd, gm, gy) - 2415020 + (ut / 24); - m1 = q / m1; - m2 = q / m2; - m3 = q / m3; - m4 = q / m4; - m5 = q / m5; - m6 = q / m6; - m1 = 360 * (m1 - (m1).Floor()); - m2 = 360 * (m2 - (m2).Floor()); - m3 = 360 * (m3 - (m3).Floor()); - m4 = 360 * (m4 - (m4).Floor()); - m5 = 360 * (m5 - (m5).Floor()); - m6 = 360 * (m6 - (m6).Floor()); - - var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; - var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; - var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; - var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; - var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; - var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; - var a = (51.2 + 20.2 * t).ToRadians(); - var s1 = a.Sine(); - var s2 = na.ToRadians().Sine(); - var b = 346.56 + (132.87 - 0.0091731 * t) * t; - var s3 = 0.003964 * b.ToRadians().Sine(); - var c = (na + 275.05 - 2.3 * t).ToRadians(); - var s4 = c.Sine(); - ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; - ms = ms - 0.001778 * s1; - md = md + 0.000817 * s1 + s3 + 0.002541 * s2; - mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; - me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; - var e = 1.0 - (0.002495 + 0.00000752 * t) * t; - var e2 = e * e; - ms = (ms).ToRadians(); - me1 = (me1).ToRadians(); - mf = (mf).ToRadians(); - md = (md).ToRadians(); - - var pm = 0.950724 + 0.051818 * (md).Cosine() + 0.009531 * (2.0 * me1 - md).Cosine(); - pm = pm + 0.007843 * (2.0 * me1).Cosine() + 0.002824 * (2.0 * md).Cosine(); - pm = pm + 0.000857 * (2.0 * me1 + md).Cosine() + e * 0.000533 * (2.0 * me1 - ms).Cosine(); - pm = pm + e * 0.000401 * (2.0 * me1 - md - ms).Cosine(); - pm = pm + e * 0.00032 * (md - ms).Cosine() - 0.000271 * (me1).Cosine(); - pm = pm - e * 0.000264 * (ms + md).Cosine() - 0.000198 * (2.0 * mf - md).Cosine(); - pm = pm + 0.000173 * (3.0 * md).Cosine() + 0.000167 * (4.0 * me1 - md).Cosine(); - pm = pm - e * 0.000111 * (ms).Cosine() + 0.000103 * (4.0 * me1 - 2.0 * md).Cosine(); - pm = pm - 0.000084 * (2.0 * md - 2.0 * me1).Cosine() - e * 0.000083 * (2.0 * me1 + ms).Cosine(); - pm = pm + 0.000079 * (2.0 * me1 + 2.0 * md).Cosine() + 0.000072 * (4.0 * me1).Cosine(); - pm = pm + e * 0.000064 * (2.0 * me1 - ms + md).Cosine() - e * 0.000063 * (2.0 * me1 + ms - md).Cosine(); - pm = pm + e * 0.000041 * (ms + me1).Cosine() + e * 0.000035 * (2.0 * md - ms).Cosine(); - pm = pm - 0.000033 * (3.0 * md - 2.0 * me1).Cosine() - 0.00003 * (md + me1).Cosine(); - pm = pm - 0.000029 * (2.0 * (mf - me1)).Cosine() - e * 0.000029 * (2.0 * md + ms).Cosine(); - pm = pm + e2 * 0.000026 * (2.0 * (me1 - ms)).Cosine() - 0.000023 * (2.0 * (mf - me1) + md).Cosine(); - pm = pm + e * 0.000019 * (4.0 * me1 - ms - md).Cosine(); - - return pm; - } + /// + /// Calculate the Moon's angular diameter (degrees) + /// + /// + /// Original macro name: MoonSize + /// + public static double MoonSize(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var hp = (MoonHP(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians(); + var r = 6378.14 / hp.Sine(); + var th = 384401.0 * 0.5181 / r; - /// - /// Calculate distance from the Earth to the Moon (km) - /// - /// - /// Original macro name: MoonDist - /// - public static double MoonDist(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var hp = (MoonHP(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians(); - var r = 6378.14 / hp.Sine(); + return th; + } - return r; - } + /// + /// Convert angle in radians to equivalent angle in degrees. + /// + /// + /// Original macro name: Unwind + /// + public static double Unwind(double w) + { + return w - 6.283185308 * (w / 6.283185308).Floor(); + } - /// - /// Calculate the Moon's angular diameter (degrees) - /// - /// - /// Original macro name: MoonSize - /// - public static double MoonSize(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var hp = (MoonHP(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians(); - var r = 6378.14 / hp.Sine(); - var th = 384401.0 * 0.5181 / r; + /// + /// Convert angle in degrees to equivalent angle in the range 0 to 360 degrees. + /// + /// + /// Original macro name: UnwindDeg + /// + public static double UnwindDeg(double w) + { + return w - 360 * (w / 360).Floor(); + } - return th; - } + /// + /// Mean ecliptic longitude of the Sun at the epoch + /// + /// + /// Original macro name: SunElong + /// + public static double SunELong(double gd, int gm, int gy) + { + var t = (CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525; + var t2 = t * t; + var x = 279.6966778 + 36000.76892 * t + 0.0003025 * t2; - /// - /// Convert angle in radians to equivalent angle in degrees. - /// - /// - /// Original macro name: Unwind - /// - public static double Unwind(double w) - { - return w - 6.283185308 * (w / 6.283185308).Floor(); - } + return x - 360 * (x / 360).Floor(); + } - /// - /// Convert angle in degrees to equivalent angle in the range 0 to 360 degrees. - /// - /// - /// Original macro name: UnwindDeg - /// - public static double UnwindDeg(double w) - { - return w - 360 * (w / 360).Floor(); - } + /// + /// Longitude of the Sun at perigee + /// + /// + /// Original macro name: SunPeri + /// + public static double SunPeri(double gd, int gm, int gy) + { + var t = (CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525; + var t2 = t * t; + var x = 281.2208444 + 1.719175 * t + 0.000452778 * t2; - /// - /// Mean ecliptic longitude of the Sun at the epoch - /// - /// - /// Original macro name: SunElong - /// - public static double SunELong(double gd, int gm, int gy) - { - var t = (CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525; - var t2 = t * t; - var x = 279.6966778 + 36000.76892 * t + 0.0003025 * t2; + return x - 360 * (x / 360).Floor(); + } - return x - 360 * (x / 360).Floor(); - } + /// + /// Eccentricity of the Sun-Earth orbit + /// + /// + /// Original macro name: SunEcc + /// + public static double SunEcc(double gd, int gm, int gy) + { + var t = (CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525; + var t2 = t * t; - /// - /// Longitude of the Sun at perigee - /// - /// - /// Original macro name: SunPeri - /// - public static double SunPeri(double gd, int gm, int gy) - { - var t = (CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525; - var t2 = t * t; - var x = 281.2208444 + 1.719175 * t + 0.000452778 * t2; + return 0.01675104 - 0.0000418 * t - 0.000000126 * t2; + } - return x - 360 * (x / 360).Floor(); - } + /// + /// Ecliptic - Declination (degrees) + /// + /// + /// Original macro name: ECDec + /// + public static double EcDec(double eld, double elm, double els, double bd, double bm, double bs, double gd, int gm, int gy) + { + var a = (DegreesMinutesSecondsToDecimalDegrees(eld, elm, els)).ToRadians(); + var b = (DegreesMinutesSecondsToDecimalDegrees(bd, bm, bs)).ToRadians(); + var c = (Obliq(gd, gm, gy)).ToRadians(); + var d = b.Sine() * c.Cosine() + b.Cosine() * c.Sine() * a.Sine(); - /// - /// Eccentricity of the Sun-Earth orbit - /// - /// - /// Original macro name: SunEcc - /// - public static double SunEcc(double gd, int gm, int gy) - { - var t = (CivilDateToJulianDate(gd, gm, gy) - 2415020) / 36525; - var t2 = t * t; + return Degrees(d.ASine()); + } - return 0.01675104 - 0.0000418 * t - 0.000000126 * t2; - } + /// + /// Ecliptic - Right Ascension (degrees) + /// + /// + /// Original macro name: ECRA + /// + public static double EcRA(double eld, double elm, double els, double bd, double bm, double bs, double gd, int gm, int gy) + { + var a = (DegreesMinutesSecondsToDecimalDegrees(eld, elm, els)).ToRadians(); + var b = (DegreesMinutesSecondsToDecimalDegrees(bd, bm, bs)).ToRadians(); + var c = (Obliq(gd, gm, gy)).ToRadians(); + var d = a.Sine() * c.Cosine() - b.Tangent() * c.Sine(); + var e = a.Cosine(); + var f = Degrees(d.AngleTangent2(e)); + + return f - 360 * (f / 360).Floor(); + } - /// - /// Ecliptic - Declination (degrees) - /// - /// - /// Original macro name: ECDec - /// - public static double EcDec(double eld, double elm, double els, double bd, double bm, double bs, double gd, int gm, int gy) - { - var a = (DegreesMinutesSecondsToDecimalDegrees(eld, elm, els)).ToRadians(); - var b = (DegreesMinutesSecondsToDecimalDegrees(bd, bm, bs)).ToRadians(); - var c = (Obliq(gd, gm, gy)).ToRadians(); - var d = b.Sine() * c.Cosine() + b.Cosine() * c.Sine() * a.Sine(); + /// + /// Calculate Sun's true anomaly, i.e., how much its orbit deviates from a true circle to an ellipse. + /// + /// + /// Original macro name: SunTrueAnomaly + /// + public static double SunTrueAnomaly(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) + { + var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); + var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); + var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); + var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); + var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; - return Degrees(d.ASine()); - } + var t = (dj / 36525) + (ut / 876600); + var t2 = t * t; - /// - /// Ecliptic - Right Ascension (degrees) - /// - /// - /// Original macro name: ECRA - /// - public static double EcRA(double eld, double elm, double els, double bd, double bm, double bs, double gd, int gm, int gy) - { - var a = (DegreesMinutesSecondsToDecimalDegrees(eld, elm, els)).ToRadians(); - var b = (DegreesMinutesSecondsToDecimalDegrees(bd, bm, bs)).ToRadians(); - var c = (Obliq(gd, gm, gy)).ToRadians(); - var d = a.Sine() * c.Cosine() - b.Tangent() * c.Sine(); - var e = a.Cosine(); - var f = Degrees(d.AngleTangent2(e)); - - return f - 360 * (f / 360).Floor(); - } + var a = 99.99736042 * t; + var b = 360 * (a - a.Floor()); - /// - /// Calculate Sun's true anomaly, i.e., how much its orbit deviates from a true circle to an ellipse. - /// - /// - /// Original macro name: SunTrueAnomaly - /// - public static double SunTrueAnomaly(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) - { - var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); - var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); - var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); - var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); - var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; + var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; + var ec = 0.01675104 - 0.0000418 * t - 0.000000126 * t2; - var t = (dj / 36525) + (ut / 876600); - var t2 = t * t; + var am = m1.ToRadians(); - var a = 99.99736042 * t; - var b = 360 * (a - a.Floor()); + return Degrees(TrueAnomaly(am, ec)); + } - var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; - var ec = 0.01675104 - 0.0000418 * t - 0.000000126 * t2; + /// + /// Calculate the Sun's mean anomaly. + /// + /// + /// Original macro name: SunMeanAnomaly + /// + public static double SunMeanAnomaly(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) + { + var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); + var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); + var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); + var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); + var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; + var t = (dj / 36525) + (ut / 876600); + var t2 = t * t; + var a = 100.0021359 * t; + var b = 360 * (a - a.Floor()); + var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; + var am = Unwind((m1).ToRadians()); + + return am; + } - var am = m1.ToRadians(); + /// + /// Calculate local civil time of sunrise. + /// + /// + /// Original macro name: SunriseLCT + /// + public static double SunriseLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp) + { + var di = 0.8333333; + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - return Degrees(TrueAnomaly(am, ec)); - } + var result1 = SunriseLCTL3710(gd, gm, gy, sr, di, gp); - /// - /// Calculate the Sun's mean anomaly. - /// - /// - /// Original macro name: SunMeanAnomaly - /// - public static double SunMeanAnomaly(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly) + double xx; + if (!result1.s.Equals("OK")) { - var aa = LocalCivilTimeGreenwichDay(lch, lcm, lcs, ds, zc, ld, lm, ly); - var bb = LocalCivilTimeGreenwichMonth(lch, lcm, lcs, ds, zc, ld, lm, ly); - var cc = LocalCivilTimeGreenwichYear(lch, lcm, lcs, ds, zc, ld, lm, ly); - var ut = LocalCivilTimeToUniversalTime(lch, lcm, lcs, ds, zc, ld, lm, ly); - var dj = CivilDateToJulianDate(aa, bb, cc) - 2415020; - var t = (dj / 36525) + (ut / 876600); - var t2 = t * t; - var a = 100.0021359 * t; - var b = 360 * (a - a.Floor()); - var m1 = 358.47583 - (0.00015 + 0.0000033 * t) * t2 + b; - var am = Unwind((m1).ToRadians()); - - return am; + xx = -99.0; } - - /// - /// Calculate local civil time of sunrise. - /// - /// - /// Original macro name: SunriseLCT - /// - public static double SunriseLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp) + else { - var di = 0.8333333; - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - - var result1 = SunriseLCTL3710(gd, gm, gy, sr, di, gp); + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - double xx; - if (!result1.s.Equals("OK")) + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) { xx = -99.0; } else { - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + var result2 = SunriseLCTL3710(gd, gm, gy, sr, di, gp); - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + if (!result2.s.Equals("OK")) { xx = -99.0; } else { - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - var result2 = SunriseLCTL3710(gd, gm, gy, sr, di, gp); - - if (!result2.s.Equals("OK")) - { - xx = -99.0; - } - else - { - x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); - ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - xx = UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); - } + x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); + ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + xx = UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); } } - - return xx; } - /// - /// Helper function for sunrise_lct() - /// - public static (double a, double x, double y, double la, string s) SunriseLCTL3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); - var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0.0, 0.0, y, 0.0, 0.0, di, gp); + return xx; + } - return (a, x, y, la, s); - } + /// + /// Helper function for sunrise_lct() + /// + public static (double a, double x, double y, double la, string s) SunriseLCTL3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); + var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0.0, 0.0, y, 0.0, 0.0, di, gp); - /// Calculate local civil time of sunset. - /// - /// Original macro name: SunsetLCT - public static double SunsetLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp) - { - var di = 0.8333333; - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); + return (a, x, y, la, s); + } + + /// Calculate local civil time of sunset. + /// + /// Original macro name: SunsetLCT + public static double SunsetLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp) + { + var di = 0.8333333; + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); + + var result1 = SunsetLCTL3710(gd, gm, gy, sr, di, gp); - var result1 = SunsetLCTL3710(gd, gm, gy, sr, di, gp); + double xx; + if (!result1.s.Equals("OK")) + { + xx = -99.0; + } + else + { + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - double xx; - if (!result1.s.Equals("OK")) + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) { xx = -99.0; } else { - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + var result2 = SunsetLCTL3710(gd, gm, gy, sr, di, gp); - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + if (!result2.s.Equals("OK")) { - xx = -99.0; + xx = -99; } else { - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - var result2 = SunsetLCTL3710(gd, gm, gy, sr, di, gp); - - if (!result2.s.Equals("OK")) - { - xx = -99; - } - else - { - x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); - ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - xx = UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); - } + x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); + ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + xx = UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); } } - return xx; } + return xx; + } - /// - /// Helper function for sunset_lct(). - /// - public static (double a, double x, double y, double la, string s) SunsetLCTL3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0.0, 0.0, 0.0, 0.0, 0.0, gd, gm, gy); - var y = EcDec(a, 0.0, 0.0, 0.0, 0.0, 0.0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeSet(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + /// + /// Helper function for sunset_lct(). + /// + public static (double a, double x, double y, double la, string s) SunsetLCTL3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0.0, 0.0, 0.0, 0.0, 0.0, gd, gm, gy); + var y = EcDec(a, 0.0, 0.0, 0.0, 0.0, 0.0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeSet(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - return (a, x, y, la, s); - } + return (a, x, y, la, s); + } - /// - /// Local sidereal time of rise, in hours. - /// - /// - /// Original macro name: RSLSTR - /// - public static double RiseSetLocalSiderealTimeRise(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) - { - var a = HMStoDH(rah, ram, ras); - var b = (DegreeHoursToDecimalDegrees(a)).ToRadians(); - var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var d = (vd).ToRadians(); - var e = (g).ToRadians(); - var f = -((d).Sine() + (e).Sine() * (c).Sine()) / ((e).Cosine() * (c).Cosine()); - var h = (Math.Abs(f) < 1) ? f.ACosine() : 0; - var i = DecimalDegreesToDegreeHours(Degrees(b - h)); - - return i - 24 * (i / 24).Floor(); - } + /// + /// Local sidereal time of rise, in hours. + /// + /// + /// Original macro name: RSLSTR + /// + public static double RiseSetLocalSiderealTimeRise(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) + { + var a = HMStoDH(rah, ram, ras); + var b = (DegreeHoursToDecimalDegrees(a)).ToRadians(); + var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var d = (vd).ToRadians(); + var e = (g).ToRadians(); + var f = -((d).Sine() + (e).Sine() * (c).Sine()) / ((e).Cosine() * (c).Cosine()); + var h = (Math.Abs(f) < 1) ? f.ACosine() : 0; + var i = DecimalDegreesToDegreeHours(Degrees(b - h)); + + return i - 24 * (i / 24).Floor(); + } - /// - /// Local sidereal time of setting, in hours. - /// - /// - /// Original macro name: RSLSTS - /// - public static double RiseSetLocalSiderealTimeSet(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) - { - var a = HMStoDH(rah, ram, ras); - var b = (DegreeHoursToDecimalDegrees(a)).ToRadians(); - var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var d = vd.ToRadians(); - var e = g.ToRadians(); - var f = -(d.Sine() + e.Sine() * c.Sine()) / (e.Cosine() * c.Cosine()); - var h = (Math.Abs(f) < 1) ? f.ACosine() : 0; - var i = DecimalDegreesToDegreeHours(Degrees(b + h)); - - return i - 24 * (i / 24).Floor(); - } + /// + /// Local sidereal time of setting, in hours. + /// + /// + /// Original macro name: RSLSTS + /// + public static double RiseSetLocalSiderealTimeSet(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) + { + var a = HMStoDH(rah, ram, ras); + var b = (DegreeHoursToDecimalDegrees(a)).ToRadians(); + var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var d = vd.ToRadians(); + var e = g.ToRadians(); + var f = -(d.Sine() + e.Sine() * c.Sine()) / (e.Cosine() * c.Cosine()); + var h = (Math.Abs(f) < 1) ? f.ACosine() : 0; + var i = DecimalDegreesToDegreeHours(Degrees(b + h)); + + return i - 24 * (i / 24).Floor(); + } - /// - /// Azimuth of rising, in degrees. - /// - /// - /// Original macro name: RSAZR - /// - public static double RiseSetAzimuthRise(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) - { - var a = HMStoDH(rah, ram, ras); - var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var d = vd.ToRadians(); - var e = g.ToRadians(); - var f = (c.Sine() + d.Sine() * e.Sine()) / (d.Cosine() * e.Cosine()); - var h = (ERS(rah, ram, ras, dd, dm, ds, vd, g).Equals("OK")) ? f.ACosine() : 0; - var i = Degrees(h); - - return i - 360 * (i / 360).Floor(); - } + /// + /// Azimuth of rising, in degrees. + /// + /// + /// Original macro name: RSAZR + /// + public static double RiseSetAzimuthRise(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) + { + var a = HMStoDH(rah, ram, ras); + var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var d = vd.ToRadians(); + var e = g.ToRadians(); + var f = (c.Sine() + d.Sine() * e.Sine()) / (d.Cosine() * e.Cosine()); + var h = (ERS(rah, ram, ras, dd, dm, ds, vd, g).Equals("OK")) ? f.ACosine() : 0; + var i = Degrees(h); + + return i - 360 * (i / 360).Floor(); + } - /// - /// Azimuth of setting, in degrees. - /// - /// - /// Original macro name: RSAZS - /// - public static double RiseSetAzimuthSet(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) - { - var a = HMStoDH(rah, ram, ras); - var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var d = vd.ToRadians(); - var e = g.ToRadians(); - var f = (c.Sine() + d.Sine() * e.Sine()) / (d.Cosine() * e.Cosine()); - var h = (ERS(rah, ram, ras, dd, dm, ds, vd, g).Equals("OK")) ? f.ACosine() : 0; - var i = 360 - Degrees(h); - - return i - 360 * (i / 360).Floor(); - } + /// + /// Azimuth of setting, in degrees. + /// + /// + /// Original macro name: RSAZS + /// + public static double RiseSetAzimuthSet(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) + { + var a = HMStoDH(rah, ram, ras); + var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var d = vd.ToRadians(); + var e = g.ToRadians(); + var f = (c.Sine() + d.Sine() * e.Sine()) / (d.Cosine() * e.Cosine()); + var h = (ERS(rah, ram, ras, dd, dm, ds, vd, g).Equals("OK")) ? f.ACosine() : 0; + var i = 360 - Degrees(h); + + return i - 360 * (i / 360).Floor(); + } - /// - /// Rise/Set status - /// - /// - /// Possible values: "OK", "** never rises", "** circumpolar" - /// Original macro name: eRS - /// - public static string ERS(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) - { - var a = HMStoDH(rah, ram, ras); - var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var d = vd.ToRadians(); - var e = g.ToRadians(); - var f = -(d.Sine() + e.Sine() * c.Sine()) / (e.Cosine() * c.Cosine()); - - var returnValue = "OK"; - if (f >= 1) - returnValue = "** never rises"; - if (f <= -1) - returnValue = "** circumpolar"; - - return returnValue; - } + /// + /// Rise/Set status + /// + /// + /// Possible values: "OK", "** never rises", "** circumpolar" + /// Original macro name: eRS + /// + public static string ERS(double rah, double ram, double ras, double dd, double dm, double ds, double vd, double g) + { + var a = HMStoDH(rah, ram, ras); + var c = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var d = vd.ToRadians(); + var e = g.ToRadians(); + var f = -(d.Sine() + e.Sine() * c.Sine()) / (e.Cosine() * c.Cosine()); + + var returnValue = "OK"; + if (f >= 1) + returnValue = "** never rises"; + if (f <= -1) + returnValue = "** circumpolar"; + + return returnValue; + } - /// Sunrise/Sunset calculation status. - /// - /// Original macro name: eSunRS - public static string ESunRS(double ld, int lm, int ly, int ds, int zc, double gl, double gp) - { - var di = 0.8333333; - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); + /// Sunrise/Sunset calculation status. + /// + /// Original macro name: eSunRS + public static string ESunRS(double ld, int lm, int ly, int ds, int zc, double gl, double gp) + { + var di = 0.8333333; + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - var result1 = ESunRS_L3710(gd, gm, gy, sr, di, gp); + var result1 = ESunRS_L3710(gd, gm, gy, sr, di, gp); - if (!result1.s.Equals("OK")) + if (!result1.s.Equals("OK")) + { + return result1.s; + } + else + { + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + var result2 = ESunRS_L3710(gd, gm, gy, sr, di, gp); + if (!result2.s.Equals("OK")) { - return result1.s; + return result2.s; } else { - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - var result2 = ESunRS_L3710(gd, gm, gy, sr, di, gp); - if (!result2.s.Equals("OK")) - { - return result2.s; - } - else - { - x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); - - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) - { - var s = result2.s + " GST to UT conversion warning"; + x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); - return s; - } + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + { + var s = result2.s + " GST to UT conversion warning"; - return result2.s; + return s; } - } - } - - /// - /// Helper function for e_sun_rs() - /// - public static (double a, double x, double y, double la, string s) ESunRS_L3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); - var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - return (a, x, y, la, s); + return result2.s; + } } + } - /// Calculate azimuth of sunrise. - /// - /// Original macro name: SunriseAz - public static double SunriseAZ(double ld, int lm, int ly, int ds, int zc, double gl, double gp) - { - var di = 0.8333333; - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - - var result1 = SunriseAZ_L3710(gd, gm, gy, sr, di, gp); + /// + /// Helper function for e_sun_rs() + /// + public static (double a, double x, double y, double la, string s) ESunRS_L3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); + var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - if (!result1.s.Equals("OK")) - { - return -99.0; - } + return (a, x, y, la, s); + } - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + /// Calculate azimuth of sunrise. + /// + /// Original macro name: SunriseAz + public static double SunriseAZ(double ld, int lm, int ly, int ds, int zc, double gl, double gp) + { + var di = 0.8333333; + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) - { - return -99.0; - } + var result1 = SunriseAZ_L3710(gd, gm, gy, sr, di, gp); - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - var result2 = SunriseAZ_L3710(gd, gm, gy, sr, di, gp); + if (!result1.s.Equals("OK")) + { + return -99.0; + } - if (!result2.s.Equals("OK")) - { - return -99.0; - } + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - return RiseSetAzimuthRise(DecimalDegreesToDegreeHours(x), 0, 0, result2.y, 0.0, 0.0, di, gp); + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + { + return -99.0; } - /// - /// Helper function for sunrise_az() - /// - public static (double a, double x, double y, double la, string s) SunriseAZ_L3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); - var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + var result2 = SunriseAZ_L3710(gd, gm, gy, sr, di, gp); - return (a, x, y, la, s); + if (!result2.s.Equals("OK")) + { + return -99.0; } - /// - /// Calculate azimuth of sunset. - /// - /// - /// Original macro name: SunsetAz - /// - public static double SunsetAZ(double ld, int lm, int ly, int ds, int zc, double gl, double gp) - { - var di = 0.8333333; - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); + return RiseSetAzimuthRise(DecimalDegreesToDegreeHours(x), 0, 0, result2.y, 0.0, 0.0, di, gp); + } - var result1 = SunsetAZ_L3710(gd, gm, gy, sr, di, gp); + /// + /// Helper function for sunrise_az() + /// + public static (double a, double x, double y, double la, string s) SunriseAZ_L3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); + var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - if (!result1.s.Equals("OK")) - { - return -99.0; - } + return (a, x, y, la, s); + } - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + /// + /// Calculate azimuth of sunset. + /// + /// + /// Original macro name: SunsetAz + /// + public static double SunsetAZ(double ld, int lm, int ly, int ds, int zc, double gl, double gp) + { + var di = 0.8333333; + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) - { - return -99.0; - } + var result1 = SunsetAZ_L3710(gd, gm, gy, sr, di, gp); - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + if (!result1.s.Equals("OK")) + { + return -99.0; + } - var result2 = SunsetAZ_L3710(gd, gm, gy, sr, di, gp); + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - if (!result2.s.Equals("OK")) - { - return -99.0; - } - return RiseSetAzimuthSet(DecimalDegreesToDegreeHours(x), 0, 0, result2.y, 0, 0, di, gp); + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + { + return -99.0; } - /// - /// Helper function for sunset_az() - /// - public static (double a, double x, double y, double la, string s) SunsetAZ_L3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); - var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeSet(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - return (a, x, y, la, s); - } + var result2 = SunsetAZ_L3710(gd, gm, gy, sr, di, gp); - /// - /// Calculate morning twilight start, in local time. - /// - /// - /// Twilight type (TT) can be one of "C" (civil), "N" (nautical), or "A" (astronomical) - /// Original macro name: TwilightAMLCT - /// - public static double TwilightAMLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp, PATwilightType tt) + if (!result2.s.Equals("OK")) { - var di = (double)tt; + return -99.0; + } + return RiseSetAzimuthSet(DecimalDegreesToDegreeHours(x), 0, 0, result2.y, 0, 0, di, gp); + } + + /// + /// Helper function for sunset_az() + /// + public static (double a, double x, double y, double la, string s) SunsetAZ_L3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); + var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeSet(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + + return (a, x, y, la, s); + } - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); + /// + /// Calculate morning twilight start, in local time. + /// + /// + /// Twilight type (TT) can be one of "C" (civil), "N" (nautical), or "A" (astronomical) + /// Original macro name: TwilightAMLCT + /// + public static double TwilightAMLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp, PATwilightType tt) + { + var di = (double)tt; - var result1 = TwilightAMLCT_L3710(gd, gm, gy, sr, di, gp); + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - if (!result1.s.Equals("OK")) - return -99.0; + var result1 = TwilightAMLCT_L3710(gd, gm, gy, sr, di, gp); - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + if (!result1.s.Equals("OK")) + return -99.0; - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) - return -99.0; + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + return -99.0; - var result2 = TwilightAMLCT_L3710(gd, gm, gy, sr, di, gp); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - if (!result2.s.Equals("OK")) - return -99.0; + var result2 = TwilightAMLCT_L3710(gd, gm, gy, sr, di, gp); - x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); - ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + if (!result2.s.Equals("OK")) + return -99.0; - var xx = UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); + x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); + ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - return xx; - } + var xx = UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); - /// - /// Helper function for twilight_am_lct() - /// - public static (double a, double x, double y, double la, string s) TwilightAMLCT_L3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); - var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + return xx; + } - return (a, x, y, la, s); - } + /// + /// Helper function for twilight_am_lct() + /// + public static (double a, double x, double y, double la, string s) TwilightAMLCT_L3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); + var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - /// - /// Calculate evening twilight end, in local time. - /// - /// - /// Twilight type can be one of "C" (civil), "N" (nautical), or "A" (astronomical) - /// Original macro name: TwilightPMLCT - /// - public static double TwilightPMLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp, PATwilightType tt) - { - var di = (double)tt; + return (a, x, y, la, s); + } - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); + /// + /// Calculate evening twilight end, in local time. + /// + /// + /// Twilight type can be one of "C" (civil), "N" (nautical), or "A" (astronomical) + /// Original macro name: TwilightPMLCT + /// + public static double TwilightPMLCT(double ld, int lm, int ly, int ds, int zc, double gl, double gp, PATwilightType tt) + { + var di = (double)tt; - var result1 = TwilightPMLCT_L3710(gd, gm, gy, sr, di, gp); + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - if (!result1.s.Equals("OK")) - return 0.0; + var result1 = TwilightPMLCT_L3710(gd, gm, gy, sr, di, gp); - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + if (!result1.s.Equals("OK")) + return 0.0; - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) - return 0.0; + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + return 0.0; - var result2 = TwilightPMLCT_L3710(gd, gm, gy, sr, di, gp); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - if (!result2.s.Equals("OK")) - return 0.0; + var result2 = TwilightPMLCT_L3710(gd, gm, gy, sr, di, gp); - x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); - ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + if (!result2.s.Equals("OK")) + return 0.0; - return UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); - } + x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); + ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - /// - /// Helper function for twilight_pm_lct() - /// - public static (double a, double x, double y, double la, string s) TwilightPMLCT_L3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); - var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeSet(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + return UniversalTimeToLocalCivilTime(ut, 0, 0, ds, zc, gd, gm, gy); + } - return (a, x, y, la, s); - } + /// + /// Helper function for twilight_pm_lct() + /// + public static (double a, double x, double y, double la, string s) TwilightPMLCT_L3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); + var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeSet(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - /// Twilight calculation status. - /// - /// Twilight type can be one of "C" (civil), "N" (nautical), or "A" (astronomical) - /// - /// Original macro name: eTwilight - /// - /// ## Returns - /// One of: "OK", "** lasts all night", or "** Sun too far below horizon" - public static string ETwilight(double ld, int lm, int ly, int ds, int zc, double gl, double gp, PATwilightType tt) - { - var di = (double)tt; + return (a, x, y, la, s); + } - var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); - var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); - var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); - var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); + /// Twilight calculation status. + /// + /// Twilight type can be one of "C" (civil), "N" (nautical), or "A" (astronomical) + /// + /// Original macro name: eTwilight + /// + /// ## Returns + /// One of: "OK", "** lasts all night", or "** Sun too far below horizon" + public static string ETwilight(double ld, int lm, int ly, int ds, int zc, double gl, double gp, PATwilightType tt) + { + var di = (double)tt; - var result1 = ETwilight_L3710(gd, gm, gy, sr, di, gp); + var gd = LocalCivilTimeGreenwichDay(12, 0, 0, ds, zc, ld, lm, ly); + var gm = LocalCivilTimeGreenwichMonth(12, 0, 0, ds, zc, ld, lm, ly); + var gy = LocalCivilTimeGreenwichYear(12, 0, 0, ds, zc, ld, lm, ly); + var sr = SunLong(12, 0, 0, ds, zc, ld, lm, ly); - if (!result1.s.Equals("OK")) - { - return result1.s; - } + var result1 = ETwilight_L3710(gd, gm, gy, sr, di, gp); - var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); - var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); - sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); + if (!result1.s.Equals("OK")) + { + return result1.s; + } - var result2 = ETwilight_L3710(gd, gm, gy, sr, di, gp); + var x = LocalSiderealTimeToGreenwichSiderealTime(result1.la, 0, 0, gl); + var ut = GreenwichSiderealTimeToUniversalTime(x, 0, 0, gd, gm, gy); + sr = SunLong(ut, 0, 0, 0, 0, gd, gm, gy); - if (!result2.s.Equals("OK")) - { - return result2.s; - } + var result2 = ETwilight_L3710(gd, gm, gy, sr, di, gp); - x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); + if (!result2.s.Equals("OK")) + { + return result2.s; + } - if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) - { - result2.s = $"{result2.s} GST to UT conversion warning"; + x = LocalSiderealTimeToGreenwichSiderealTime(result2.la, 0, 0, gl); - return result2.s; - } + if (!EGstUt(x, 0, 0, gd, gm, gy).Equals(PAWarningFlag.OK)) + { + result2.s = $"{result2.s} GST to UT conversion warning"; return result2.s; } - /// - /// Helper function for e_twilight() - /// - public static (double a, double x, double y, double la, string s) ETwilight_L3710(double gd, int gm, int gy, double sr, double di, double gp) - { - var a = sr + NutatLong(gd, gm, gy) - 0.005694; - var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); - var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); - var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); - var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + return result2.s; + } - if (s.Length > 2) + /// + /// Helper function for e_twilight() + /// + public static (double a, double x, double y, double la, string s) ETwilight_L3710(double gd, int gm, int gy, double sr, double di, double gp) + { + var a = sr + NutatLong(gd, gm, gy) - 0.005694; + var x = EcRA(a, 0, 0, 0, 0, 0, gd, gm, gy); + var y = EcDec(a, 0, 0, 0, 0, 0, gd, gm, gy); + var la = RiseSetLocalSiderealTimeRise(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + var s = ERS(DecimalDegreesToDegreeHours(x), 0, 0, y, 0, 0, di, gp); + + if (s.Length > 2) + { + if (s.Substring(0, 3).Equals("** c")) { - if (s.Substring(0, 3).Equals("** c")) - { - s = "** lasts all night"; - } - else + s = "** lasts all night"; + } + else + { + if (s.Substring(0, 3).Equals("** n")) { - if (s.Substring(0, 3).Equals("** n")) - { - s = "** Sun too far below horizon"; - } + s = "** Sun too far below horizon"; } } - - return (a, x, y, la, s); } - /// - /// Calculate the angle between two celestial objects - /// - /// - /// Original macro name: Angle - /// - public static double Angle(double xx1, double xm1, double xs1, double dd1, double dm1, double ds1, double xx2, double xm2, double xs2, double dd2, double dm2, double ds2, PAAngleMeasure s - ) - { - var a = (s.Equals(PAAngleMeasure.Hours)) ? DegreeHoursToDecimalDegrees(HMStoDH(xx1, xm1, xs1)) : DegreesMinutesSecondsToDecimalDegrees(xx1, xm1, xs1); - var b = a.ToRadians(); - var c = DegreesMinutesSecondsToDecimalDegrees(dd1, dm1, ds1); - var d = c.ToRadians(); - var e = (s.Equals(PAAngleMeasure.Hours)) ? DegreeHoursToDecimalDegrees(HMStoDH(xx2, xm2, xs2)) : DegreesMinutesSecondsToDecimalDegrees(xx2, xm2, xs2); - var f = e.ToRadians(); - var g = DegreesMinutesSecondsToDecimalDegrees(dd2, dm2, ds2); - var h = g.ToRadians(); - var i = (d.Sine() * h.Sine() + d.Cosine() * h.Cosine() * (b - f).Cosine()).ACosine(); - - return Degrees(i); - } + return (a, x, y, la, s); + } - /// - /// Calculate several planetary properties. - /// - /// - /// Original macro names: PlanetLong, PlanetLat, PlanetDist, PlanetHLong1, PlanetHLong2, PlanetHLat, PlanetRVect - /// - /// Local civil time, hour part. - /// Local civil time, minutes part. - /// Local civil time, seconds part. - /// Daylight Savings offset. - /// Time zone correction, in hours. - /// Local date, day part. - /// Local date, month part. - /// Local date, year part. - /// Planet name. - /// - /// planetLongitude -- Ecliptic longitude, in degrees. - /// planetLatitude -- Ecliptic latitude, in degrees. - /// planetDistanceAU -- Earth-planet distance, in AU. - /// planetHLong1 -- Heliocentric orbital longitude, in degrees. - /// planetHLong2 -- NOT USED - /// planetHLat -- NOT USED - /// planetRVect -- Sun-planet distance (length of radius vector), in AU. - /// - public static (double planetLongitude, double planetLatitude, double planetDistanceAU, double planetHLong1, double planetHLong2, double planetHLat, double planetRVect) PlanetCoordinates(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr, string s) - { - var a11 = 178.179078; - var a12 = 415.2057519; - var a13 = 0.0003011; - var a14 = 0.0; - var a21 = 75.899697; - var a22 = 1.5554889; - var a23 = 0.0002947; - var a24 = 0.0; - var a31 = 0.20561421; - var a32 = 0.00002046; - var a33 = -0.00000003; - var a34 = 0.0; - var a41 = 7.002881; - var a42 = 0.0018608; - var a43 = -0.0000183; - var a44 = 0.0; - var a51 = 47.145944; - var a52 = 1.1852083; - var a53 = 0.0001739; - var a54 = 0.0; - var a61 = 0.3870986; - var a62 = 6.74; - var a63 = -0.42; - - var b11 = 342.767053; - var b12 = 162.5533664; - var b13 = 0.0003097; - var b14 = 0.0; - var b21 = 130.163833; - var b22 = 1.4080361; - var b23 = -0.0009764; - var b24 = 0.0; - var b31 = 0.00682069; - var b32 = -0.00004774; - var b33 = 0.000000091; - var b34 = 0.0; - var b41 = 3.393631; - var b42 = 0.0010058; - var b43 = -0.000001; - var b44 = 0.0; - var b51 = 75.779647; - var b52 = 0.89985; - var b53 = 0.00041; - var b54 = 0.0; - var b61 = 0.7233316; - var b62 = 16.92; - var b63 = -4.4; - - var c11 = 293.737334; - var c12 = 53.17137642; - var c13 = 0.0003107; - var c14 = 0.0; - var c21 = 334.218203; - var c22 = 1.8407584; - var c23 = 0.0001299; - var c24 = -0.00000119; - var c31 = 0.0933129; - var c32 = 0.000092064; - var c33 = -0.000000077; - var c34 = 0.0; - var c41 = 1.850333; - var c42 = -0.000675; - var c43 = 0.0000126; - var c44 = 0.0; - var c51 = 48.786442; - var c52 = 0.7709917; - var c53 = -0.0000014; - var c54 = -0.00000533; - var c61 = 1.5236883; - var c62 = 9.36; - var c63 = -1.52; - - var d11 = 238.049257; - var d12 = 8.434172183; - var d13 = 0.0003347; - var d14 = -0.00000165; - var d21 = 12.720972; - var d22 = 1.6099617; - var d23 = 0.00105627; - var d24 = -0.00000343; - var d31 = 0.04833475; - var d32 = 0.00016418; - var d33 = -0.0000004676; - var d34 = -0.0000000017; - var d41 = 1.308736; - var d42 = -0.0056961; - var d43 = 0.0000039; - var d44 = 0.0; - var d51 = 99.443414; - var d52 = 1.01053; - var d53 = 0.00035222; - var d54 = -0.00000851; - var d61 = 5.202561; - var d62 = 196.74; - var d63 = -9.4; - - var e11 = 266.564377; - var e12 = 3.398638567; - var e13 = 0.0003245; - var e14 = -0.0000058; - var e21 = 91.098214; - var e22 = 1.9584158; - var e23 = 0.00082636; - var e24 = 0.00000461; - var e31 = 0.05589232; - var e32 = -0.0003455; - var e33 = -0.000000728; - var e34 = 0.00000000074; - var e41 = 2.492519; - var e42 = -0.0039189; - var e43 = -0.00001549; - var e44 = 0.00000004; - var e51 = 112.790414; - var e52 = 0.8731951; - var e53 = -0.00015218; - var e54 = -0.00000531; - var e61 = 9.554747; - var e62 = 165.6; - var e63 = -8.88; - - var f11 = 244.19747; - var f12 = 1.194065406; - var f13 = 0.000316; - var f14 = -0.0000006; - var f21 = 171.548692; - var f22 = 1.4844328; - var f23 = 0.0002372; - var f24 = -0.00000061; - var f31 = 0.0463444; - var f32a = -0.00002658; - var f33 = 0.000000077; - var f34 = 0.0; - var f41 = 0.772464; - var f42 = 0.0006253; - var f43 = 0.0000395; - var f44 = 0.0; - var f51 = 73.477111; - var f52 = 0.4986678; - var f53 = 0.0013117; - var f54 = 0.0; - var f61 = 19.21814; - var f62 = 65.8; - var f63 = -7.19; - - var g11 = 84.457994; - var g12 = 0.6107942056; - var g13 = 0.0003205; - var g14 = -0.0000006; - var g21 = 46.727364; - var g22 = 1.4245744; - var g23 = 0.00039082; - var g24 = -0.000000605; - var g31 = 0.00899704; - var g32 = 0.00000633; - var g33 = -0.000000002; - var g34 = 0.0; - var g41 = 1.779242; - var g42 = -0.0095436; - var g43 = -0.0000091; - var g44 = 0.0; - var g51 = 130.681389; - var g52 = 1.098935; - var g53 = 0.00024987; - var g54 = -0.000004718; - var g61 = 30.10957; - var g62 = 62.2; - var g63 = -6.87; - - var pl = new List(); - - pl.Add(new PlanetDataPrecise() { Name = "", Value1 = 0, Value2 = 0, Value3 = 0, Value4 = 0, Value5 = 0, Value6 = 0, Value7 = 0, Value8 = 0, Value9 = 0 }); - - var ip = 0; - var b = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); - var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); - var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); - var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); - var a = CivilDateToJulianDate(gd, gm, gy); - var t = ((a - 2415020.0) / 36525.0) + (b / 876600.0); - - var a0 = a11; - var a1 = a12; - var a2 = a13; - var a3 = a14; - var b0 = a21; - var b1 = a22; - var b2 = a23; - var b3 = a24; - var c0 = a31; - var c1 = a32; - var c2 = a33; - var c3 = a34; - var d0 = a41; - var d1 = a42; - var d2 = a43; - var d3 = a44; - var e0 = a51; - var e1 = a52; - var e2 = a53; - var e3 = a54; - var f = a61; - var g = a62; - var h = a63; - var aa = a1 * t; - b = 360.0 * (aa - aa.Floor()); - var c = a0 + b + (a3 * t + a2) * t * t; - - pl.Add(new PlanetDataPrecise() - { - Name = "Mercury", - Value1 = c - 360.0 * (c / 360.0).Floor(), - Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, - Value3 = ((b3 * t + b2) * t + b1) * t + b0, - Value4 = ((c3 * t + c2) * t + c1) * t + c0, - Value5 = ((d3 * t + d2) * t + d1) * t + d0, - Value6 = ((e3 * t + e2) * t + e1) * t + e0, - Value7 = f, - Value8 = g, - Value9 = h - }); - - a0 = b11; - a1 = b12; - a2 = b13; - a3 = b14; - b0 = b21; - b1 = b22; - b2 = b23; - b3 = b24; - c0 = b31; - c1 = b32; - c2 = b33; - c3 = b34; - d0 = b41; - d1 = b42; - d2 = b43; - d3 = b44; - e0 = b51; - e1 = b52; - e2 = b53; - e3 = b54; - f = b61; - g = b62; - h = b63; - aa = a1 * t; - b = 360.0 * (aa - (aa).Floor()); - c = a0 + b + (a3 * t + a2) * t * t; - - pl.Add(new PlanetDataPrecise() - { - Name = "Venus", - Value1 = c - 360.0 * (c / 360.0).Floor(), - Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, - Value3 = ((b3 * t + b2) * t + b1) * t + b0, - Value4 = ((c3 * t + c2) * t + c1) * t + c0, - Value5 = ((d3 * t + d2) * t + d1) * t + d0, - Value6 = ((e3 * t + e2) * t + e1) * t + e0, - Value7 = f, - Value8 = g, - Value9 = h - }); - - a0 = c11; - a1 = c12; - a2 = c13; - a3 = c14; - b0 = c21; - b1 = c22; - b2 = c23; - b3 = c24; - c0 = c31; - c1 = c32; - c2 = c33; - c3 = c34; - d0 = c41; - d1 = c42; - d2 = c43; - d3 = c44; - e0 = c51; - e1 = c52; - e2 = c53; - e3 = c54; - f = c61; - g = c62; - h = c63; - - aa = a1 * t; - b = 360.0 * (aa - (aa).Floor()); - c = a0 + b + (a3 * t + a2) * t * t; - - pl.Add(new PlanetDataPrecise() - { - Name = "Mars", - Value1 = c - 360.0 * (c / 360.0).Floor(), - Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, - Value3 = ((b3 * t + b2) * t + b1) * t + b0, - Value4 = ((c3 * t + c2) * t + c1) * t + c0, - Value5 = ((d3 * t + d2) * t + d1) * t + d0, - Value6 = ((e3 * t + e2) * t + e1) * t + e0, - Value7 = f, - Value8 = g, - Value9 = h - }); - - a0 = d11; - a1 = d12; - a2 = d13; - a3 = d14; - b0 = d21; - b1 = d22; - b2 = d23; - b3 = d24; - c0 = d31; - c1 = d32; - c2 = d33; - c3 = d34; - d0 = d41; - d1 = d42; - d2 = d43; - d3 = d44; - e0 = d51; - e1 = d52; - e2 = d53; - e3 = d54; - f = d61; - g = d62; - h = d63; - - aa = a1 * t; - b = 360.0 * (aa - (aa).Floor()); - c = a0 + b + (a3 * t + a2) * t * t; - - pl.Add(new PlanetDataPrecise() - { - Name = "Jupiter", - Value1 = c - 360.0 * (c / 360.0).Floor(), - Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, - Value3 = ((b3 * t + b2) * t + b1) * t + b0, - Value4 = ((c3 * t + c2) * t + c1) * t + c0, - Value5 = ((d3 * t + d2) * t + d1) * t + d0, - Value6 = ((e3 * t + e2) * t + e1) * t + e0, - Value7 = f, - Value8 = g, - Value9 = h - }); - - a0 = e11; - a1 = e12; - a2 = e13; - a3 = e14; - b0 = e21; - b1 = e22; - b2 = e23; - b3 = e24; - c0 = e31; - c1 = e32; - c2 = e33; - c3 = e34; - d0 = e41; - d1 = e42; - d2 = e43; - d3 = e44; - e0 = e51; - e1 = e52; - e2 = e53; - e3 = e54; - f = e61; - g = e62; - h = e63; - - aa = a1 * t; - b = 360.0 * (aa - (aa).Floor()); - c = a0 + b + (a3 * t + a2) * t * t; - - pl.Add(new PlanetDataPrecise() - { - Name = "Saturn", - Value1 = c - 360.0 * (c / 360.0).Floor(), - Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, - Value3 = ((b3 * t + b2) * t + b1) * t + b0, - Value4 = ((c3 * t + c2) * t + c1) * t + c0, - Value5 = ((d3 * t + d2) * t + d1) * t + d0, - Value6 = ((e3 * t + e2) * t + e1) * t + e0, - Value7 = f, - Value8 = g, - Value9 = h - }); - - a0 = f11; - a1 = f12; - a2 = f13; - a3 = f14; - b0 = f21; - b1 = f22; - b2 = f23; - b3 = f24; - c0 = f31; - c1 = f32a; - c2 = f33; - c3 = f34; - d0 = f41; - d1 = f42; - d2 = f43; - d3 = f44; - e0 = f51; - e1 = f52; - e2 = f53; - e3 = f54; - f = f61; - g = f62; - h = f63; - - aa = a1 * t; - b = 360.0 * (aa - (aa).Floor()); - c = a0 + b + (a3 * t + a2) * t * t; - - pl.Add(new PlanetDataPrecise() - { - Name = "Uranus", - Value1 = c - 360.0 * (c / 360.0).Floor(), - Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, - Value3 = ((b3 * t + b2) * t + b1) * t + b0, - Value4 = ((c3 * t + c2) * t + c1) * t + c0, - Value5 = ((d3 * t + d2) * t + d1) * t + d0, - Value6 = ((e3 * t + e2) * t + e1) * t + e0, - Value7 = f, - Value8 = g, - Value9 = h - }); - - a0 = g11; - a1 = g12; - a2 = g13; - a3 = g14; - b0 = g21; - b1 = g22; - b2 = g23; - b3 = g24; - c0 = g31; - c1 = g32; - c2 = g33; - c3 = g34; - d0 = g41; - d1 = g42; - d2 = g43; - d3 = g44; - e0 = g51; - e1 = g52; - e2 = g53; - e3 = g54; - f = g61; - g = g62; - h = g63; - - aa = a1 * t; - b = 360.0 * (aa - (aa).Floor()); - c = a0 + b + (a3 * t + a2) * t * t; - - pl.Add(new PlanetDataPrecise() - { - Name = "Neptune", - Value1 = c - 360.0 * (c / 360.0).Floor(), - Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, - Value3 = ((b3 * t + b2) * t + b1) * t + b0, - Value4 = ((c3 * t + c2) * t + c1) * t + c0, - Value5 = ((d3 * t + d2) * t + d1) * t + d0, - Value6 = ((e3 * t + e2) * t + e1) * t + e0, - Value7 = f, - Value8 = g, - Value9 = h - }); - - var checkPlanet = pl.Where(x => x.Name.ToLower() == s.ToLower()).Select(x => x).FirstOrDefault(); - if (checkPlanet == null) - return (Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0))); - - var li = 0.0; - var ms = SunMeanAnomaly(lh, lm, ls, ds, zc, dy, mn, yr); - var sr = (SunLong(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians(); - var re = SunDist(lh, lm, ls, ds, zc, dy, mn, yr); - var lg = sr + Math.PI; - - var l0 = 0.0; - var s0 = 0.0; - var p0 = 0.0; - var vo = 0.0; - var lp1 = 0.0; - var ll = 0.0; - var rd = 0.0; - var pd = 0.0; - var sp = 0.0; - var ci = 0.0; - - for (int k = 1; k <= 3; k++) - { - foreach (var planet in pl) - planet.APValue = (planet.Value1 - planet.Value3 - li * planet.Value2).ToRadians(); + /// + /// Calculate the angle between two celestial objects + /// + /// + /// Original macro name: Angle + /// + public static double Angle(double xx1, double xm1, double xs1, double dd1, double dm1, double ds1, double xx2, double xm2, double xs2, double dd2, double dm2, double ds2, PAAngleMeasure s + ) + { + var a = (s.Equals(PAAngleMeasure.Hours)) ? DegreeHoursToDecimalDegrees(HMStoDH(xx1, xm1, xs1)) : DegreesMinutesSecondsToDecimalDegrees(xx1, xm1, xs1); + var b = a.ToRadians(); + var c = DegreesMinutesSecondsToDecimalDegrees(dd1, dm1, ds1); + var d = c.ToRadians(); + var e = (s.Equals(PAAngleMeasure.Hours)) ? DegreeHoursToDecimalDegrees(HMStoDH(xx2, xm2, xs2)) : DegreesMinutesSecondsToDecimalDegrees(xx2, xm2, xs2); + var f = e.ToRadians(); + var g = DegreesMinutesSecondsToDecimalDegrees(dd2, dm2, ds2); + var h = g.ToRadians(); + var i = (d.Sine() * h.Sine() + d.Cosine() * h.Cosine() * (b - f).Cosine()).ACosine(); + + return Degrees(i); + } - var qa = 0.0; - var qb = 0.0; - var qc = 0.0; - var qd = 0.0; - var qe = 0.0; - var qf = 0.0; - var qg = 0.0; + /// + /// Calculate several planetary properties. + /// + /// + /// Original macro names: PlanetLong, PlanetLat, PlanetDist, PlanetHLong1, PlanetHLong2, PlanetHLat, PlanetRVect + /// + /// Local civil time, hour part. + /// Local civil time, minutes part. + /// Local civil time, seconds part. + /// Daylight Savings offset. + /// Time zone correction, in hours. + /// Local date, day part. + /// Local date, month part. + /// Local date, year part. + /// Planet name. + /// + /// planetLongitude -- Ecliptic longitude, in degrees. + /// planetLatitude -- Ecliptic latitude, in degrees. + /// planetDistanceAU -- Earth-planet distance, in AU. + /// planetHLong1 -- Heliocentric orbital longitude, in degrees. + /// planetHLong2 -- NOT USED + /// planetHLat -- NOT USED + /// planetRVect -- Sun-planet distance (length of radius vector), in AU. + /// + public static (double planetLongitude, double planetLatitude, double planetDistanceAU, double planetHLong1, double planetHLong2, double planetHLat, double planetRVect) PlanetCoordinates(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr, string s) + { + var a11 = 178.179078; + var a12 = 415.2057519; + var a13 = 0.0003011; + var a14 = 0.0; + var a21 = 75.899697; + var a22 = 1.5554889; + var a23 = 0.0002947; + var a24 = 0.0; + var a31 = 0.20561421; + var a32 = 0.00002046; + var a33 = -0.00000003; + var a34 = 0.0; + var a41 = 7.002881; + var a42 = 0.0018608; + var a43 = -0.0000183; + var a44 = 0.0; + var a51 = 47.145944; + var a52 = 1.1852083; + var a53 = 0.0001739; + var a54 = 0.0; + var a61 = 0.3870986; + var a62 = 6.74; + var a63 = -0.42; + + var b11 = 342.767053; + var b12 = 162.5533664; + var b13 = 0.0003097; + var b14 = 0.0; + var b21 = 130.163833; + var b22 = 1.4080361; + var b23 = -0.0009764; + var b24 = 0.0; + var b31 = 0.00682069; + var b32 = -0.00004774; + var b33 = 0.000000091; + var b34 = 0.0; + var b41 = 3.393631; + var b42 = 0.0010058; + var b43 = -0.000001; + var b44 = 0.0; + var b51 = 75.779647; + var b52 = 0.89985; + var b53 = 0.00041; + var b54 = 0.0; + var b61 = 0.7233316; + var b62 = 16.92; + var b63 = -4.4; + + var c11 = 293.737334; + var c12 = 53.17137642; + var c13 = 0.0003107; + var c14 = 0.0; + var c21 = 334.218203; + var c22 = 1.8407584; + var c23 = 0.0001299; + var c24 = -0.00000119; + var c31 = 0.0933129; + var c32 = 0.000092064; + var c33 = -0.000000077; + var c34 = 0.0; + var c41 = 1.850333; + var c42 = -0.000675; + var c43 = 0.0000126; + var c44 = 0.0; + var c51 = 48.786442; + var c52 = 0.7709917; + var c53 = -0.0000014; + var c54 = -0.00000533; + var c61 = 1.5236883; + var c62 = 9.36; + var c63 = -1.52; + + var d11 = 238.049257; + var d12 = 8.434172183; + var d13 = 0.0003347; + var d14 = -0.00000165; + var d21 = 12.720972; + var d22 = 1.6099617; + var d23 = 0.00105627; + var d24 = -0.00000343; + var d31 = 0.04833475; + var d32 = 0.00016418; + var d33 = -0.0000004676; + var d34 = -0.0000000017; + var d41 = 1.308736; + var d42 = -0.0056961; + var d43 = 0.0000039; + var d44 = 0.0; + var d51 = 99.443414; + var d52 = 1.01053; + var d53 = 0.00035222; + var d54 = -0.00000851; + var d61 = 5.202561; + var d62 = 196.74; + var d63 = -9.4; + + var e11 = 266.564377; + var e12 = 3.398638567; + var e13 = 0.0003245; + var e14 = -0.0000058; + var e21 = 91.098214; + var e22 = 1.9584158; + var e23 = 0.00082636; + var e24 = 0.00000461; + var e31 = 0.05589232; + var e32 = -0.0003455; + var e33 = -0.000000728; + var e34 = 0.00000000074; + var e41 = 2.492519; + var e42 = -0.0039189; + var e43 = -0.00001549; + var e44 = 0.00000004; + var e51 = 112.790414; + var e52 = 0.8731951; + var e53 = -0.00015218; + var e54 = -0.00000531; + var e61 = 9.554747; + var e62 = 165.6; + var e63 = -8.88; + + var f11 = 244.19747; + var f12 = 1.194065406; + var f13 = 0.000316; + var f14 = -0.0000006; + var f21 = 171.548692; + var f22 = 1.4844328; + var f23 = 0.0002372; + var f24 = -0.00000061; + var f31 = 0.0463444; + var f32a = -0.00002658; + var f33 = 0.000000077; + var f34 = 0.0; + var f41 = 0.772464; + var f42 = 0.0006253; + var f43 = 0.0000395; + var f44 = 0.0; + var f51 = 73.477111; + var f52 = 0.4986678; + var f53 = 0.0013117; + var f54 = 0.0; + var f61 = 19.21814; + var f62 = 65.8; + var f63 = -7.19; + + var g11 = 84.457994; + var g12 = 0.6107942056; + var g13 = 0.0003205; + var g14 = -0.0000006; + var g21 = 46.727364; + var g22 = 1.4245744; + var g23 = 0.00039082; + var g24 = -0.000000605; + var g31 = 0.00899704; + var g32 = 0.00000633; + var g33 = -0.000000002; + var g34 = 0.0; + var g41 = 1.779242; + var g42 = -0.0095436; + var g43 = -0.0000091; + var g44 = 0.0; + var g51 = 130.681389; + var g52 = 1.098935; + var g53 = 0.00024987; + var g54 = -0.000004718; + var g61 = 30.10957; + var g62 = 62.2; + var g63 = -6.87; + + var pl = new List(); + + pl.Add(new PlanetDataPrecise() { Name = "", Value1 = 0, Value2 = 0, Value3 = 0, Value4 = 0, Value5 = 0, Value6 = 0, Value7 = 0, Value8 = 0, Value9 = 0 }); + + var ip = 0; + var b = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); + var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); + var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); + var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); + var a = CivilDateToJulianDate(gd, gm, gy); + var t = ((a - 2415020.0) / 36525.0) + (b / 876600.0); + + var a0 = a11; + var a1 = a12; + var a2 = a13; + var a3 = a14; + var b0 = a21; + var b1 = a22; + var b2 = a23; + var b3 = a24; + var c0 = a31; + var c1 = a32; + var c2 = a33; + var c3 = a34; + var d0 = a41; + var d1 = a42; + var d2 = a43; + var d3 = a44; + var e0 = a51; + var e1 = a52; + var e2 = a53; + var e3 = a54; + var f = a61; + var g = a62; + var h = a63; + var aa = a1 * t; + b = 360.0 * (aa - aa.Floor()); + var c = a0 + b + (a3 * t + a2) * t * t; + + pl.Add(new PlanetDataPrecise() + { + Name = "Mercury", + Value1 = c - 360.0 * (c / 360.0).Floor(), + Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, + Value3 = ((b3 * t + b2) * t + b1) * t + b0, + Value4 = ((c3 * t + c2) * t + c1) * t + c0, + Value5 = ((d3 * t + d2) * t + d1) * t + d0, + Value6 = ((e3 * t + e2) * t + e1) * t + e0, + Value7 = f, + Value8 = g, + Value9 = h + }); + + a0 = b11; + a1 = b12; + a2 = b13; + a3 = b14; + b0 = b21; + b1 = b22; + b2 = b23; + b3 = b24; + c0 = b31; + c1 = b32; + c2 = b33; + c3 = b34; + d0 = b41; + d1 = b42; + d2 = b43; + d3 = b44; + e0 = b51; + e1 = b52; + e2 = b53; + e3 = b54; + f = b61; + g = b62; + h = b63; + aa = a1 * t; + b = 360.0 * (aa - (aa).Floor()); + c = a0 + b + (a3 * t + a2) * t * t; + + pl.Add(new PlanetDataPrecise() + { + Name = "Venus", + Value1 = c - 360.0 * (c / 360.0).Floor(), + Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, + Value3 = ((b3 * t + b2) * t + b1) * t + b0, + Value4 = ((c3 * t + c2) * t + c1) * t + c0, + Value5 = ((d3 * t + d2) * t + d1) * t + d0, + Value6 = ((e3 * t + e2) * t + e1) * t + e0, + Value7 = f, + Value8 = g, + Value9 = h + }); + + a0 = c11; + a1 = c12; + a2 = c13; + a3 = c14; + b0 = c21; + b1 = c22; + b2 = c23; + b3 = c24; + c0 = c31; + c1 = c32; + c2 = c33; + c3 = c34; + d0 = c41; + d1 = c42; + d2 = c43; + d3 = c44; + e0 = c51; + e1 = c52; + e2 = c53; + e3 = c54; + f = c61; + g = c62; + h = c63; + + aa = a1 * t; + b = 360.0 * (aa - (aa).Floor()); + c = a0 + b + (a3 * t + a2) * t * t; + + pl.Add(new PlanetDataPrecise() + { + Name = "Mars", + Value1 = c - 360.0 * (c / 360.0).Floor(), + Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, + Value3 = ((b3 * t + b2) * t + b1) * t + b0, + Value4 = ((c3 * t + c2) * t + c1) * t + c0, + Value5 = ((d3 * t + d2) * t + d1) * t + d0, + Value6 = ((e3 * t + e2) * t + e1) * t + e0, + Value7 = f, + Value8 = g, + Value9 = h + }); + + a0 = d11; + a1 = d12; + a2 = d13; + a3 = d14; + b0 = d21; + b1 = d22; + b2 = d23; + b3 = d24; + c0 = d31; + c1 = d32; + c2 = d33; + c3 = d34; + d0 = d41; + d1 = d42; + d2 = d43; + d3 = d44; + e0 = d51; + e1 = d52; + e2 = d53; + e3 = d54; + f = d61; + g = d62; + h = d63; + + aa = a1 * t; + b = 360.0 * (aa - (aa).Floor()); + c = a0 + b + (a3 * t + a2) * t * t; + + pl.Add(new PlanetDataPrecise() + { + Name = "Jupiter", + Value1 = c - 360.0 * (c / 360.0).Floor(), + Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, + Value3 = ((b3 * t + b2) * t + b1) * t + b0, + Value4 = ((c3 * t + c2) * t + c1) * t + c0, + Value5 = ((d3 * t + d2) * t + d1) * t + d0, + Value6 = ((e3 * t + e2) * t + e1) * t + e0, + Value7 = f, + Value8 = g, + Value9 = h + }); + + a0 = e11; + a1 = e12; + a2 = e13; + a3 = e14; + b0 = e21; + b1 = e22; + b2 = e23; + b3 = e24; + c0 = e31; + c1 = e32; + c2 = e33; + c3 = e34; + d0 = e41; + d1 = e42; + d2 = e43; + d3 = e44; + e0 = e51; + e1 = e52; + e2 = e53; + e3 = e54; + f = e61; + g = e62; + h = e63; + + aa = a1 * t; + b = 360.0 * (aa - (aa).Floor()); + c = a0 + b + (a3 * t + a2) * t * t; + + pl.Add(new PlanetDataPrecise() + { + Name = "Saturn", + Value1 = c - 360.0 * (c / 360.0).Floor(), + Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, + Value3 = ((b3 * t + b2) * t + b1) * t + b0, + Value4 = ((c3 * t + c2) * t + c1) * t + c0, + Value5 = ((d3 * t + d2) * t + d1) * t + d0, + Value6 = ((e3 * t + e2) * t + e1) * t + e0, + Value7 = f, + Value8 = g, + Value9 = h + }); + + a0 = f11; + a1 = f12; + a2 = f13; + a3 = f14; + b0 = f21; + b1 = f22; + b2 = f23; + b3 = f24; + c0 = f31; + c1 = f32a; + c2 = f33; + c3 = f34; + d0 = f41; + d1 = f42; + d2 = f43; + d3 = f44; + e0 = f51; + e1 = f52; + e2 = f53; + e3 = f54; + f = f61; + g = f62; + h = f63; + + aa = a1 * t; + b = 360.0 * (aa - (aa).Floor()); + c = a0 + b + (a3 * t + a2) * t * t; + + pl.Add(new PlanetDataPrecise() + { + Name = "Uranus", + Value1 = c - 360.0 * (c / 360.0).Floor(), + Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, + Value3 = ((b3 * t + b2) * t + b1) * t + b0, + Value4 = ((c3 * t + c2) * t + c1) * t + c0, + Value5 = ((d3 * t + d2) * t + d1) * t + d0, + Value6 = ((e3 * t + e2) * t + e1) * t + e0, + Value7 = f, + Value8 = g, + Value9 = h + }); + + a0 = g11; + a1 = g12; + a2 = g13; + a3 = g14; + b0 = g21; + b1 = g22; + b2 = g23; + b3 = g24; + c0 = g31; + c1 = g32; + c2 = g33; + c3 = g34; + d0 = g41; + d1 = g42; + d2 = g43; + d3 = g44; + e0 = g51; + e1 = g52; + e2 = g53; + e3 = g54; + f = g61; + g = g62; + h = g63; + + aa = a1 * t; + b = 360.0 * (aa - (aa).Floor()); + c = a0 + b + (a3 * t + a2) * t * t; + + pl.Add(new PlanetDataPrecise() + { + Name = "Neptune", + Value1 = c - 360.0 * (c / 360.0).Floor(), + Value2 = (a1 * 0.009856263) + (a2 + a3) / 36525.0, + Value3 = ((b3 * t + b2) * t + b1) * t + b0, + Value4 = ((c3 * t + c2) * t + c1) * t + c0, + Value5 = ((d3 * t + d2) * t + d1) * t + d0, + Value6 = ((e3 * t + e2) * t + e1) * t + e0, + Value7 = f, + Value8 = g, + Value9 = h + }); + + var checkPlanet = pl.Where(x => x.Name.ToLower() == s.ToLower()).Select(x => x).FirstOrDefault(); + if (checkPlanet == null) + return (Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0)), Degrees(Unwind(0))); + + var li = 0.0; + var ms = SunMeanAnomaly(lh, lm, ls, ds, zc, dy, mn, yr); + var sr = (SunLong(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians(); + var re = SunDist(lh, lm, ls, ds, zc, dy, mn, yr); + var lg = sr + Math.PI; + + var l0 = 0.0; + var s0 = 0.0; + var p0 = 0.0; + var vo = 0.0; + var lp1 = 0.0; + var ll = 0.0; + var rd = 0.0; + var pd = 0.0; + var sp = 0.0; + var ci = 0.0; + + for (int k = 1; k <= 3; k++) + { + foreach (var planet in pl) + planet.APValue = (planet.Value1 - planet.Value3 - li * planet.Value2).ToRadians(); - if (s == "Mercury") - (qa, qb) = PlanetLong_L4685(pl); + var qa = 0.0; + var qb = 0.0; + var qc = 0.0; + var qd = 0.0; + var qe = 0.0; + var qf = 0.0; + var qg = 0.0; - if (s == "Venus") - (qa, qb, qc, qe) = PlanetLong_L4735(pl, ms, t); + if (s == "Mercury") + (qa, qb) = PlanetLong_L4685(pl); - if (s == "Mars") - { - var returnValue = PlanetLong_L4810(pl, ms); + if (s == "Venus") + (qa, qb, qc, qe) = PlanetLong_L4735(pl, ms, t); - qc = returnValue.qc; - qe = returnValue.qe; - qa = returnValue.qa; - qb = returnValue.qb; - } + if (s == "Mars") + { + var returnValue = PlanetLong_L4810(pl, ms); - var matchPlanet = pl.Where(x => x.Name.ToLower() == s.ToLower()).Select(x => x).FirstOrDefault(); - - if (new string[] { "Jupiter", "Saturn", "Uranus", "Neptune" }.Contains(s)) - (qa, qb, qc, qd, qe, qf, qg) = PlanetLong_L4945(t, matchPlanet); - - var ec = matchPlanet.Value4 + qd; - var am = matchPlanet.APValue + qe; - var at = TrueAnomaly(am, ec); - var pvv = (matchPlanet.Value7 + qf) * (1.0 - ec * ec) / (1.0 + ec * (at).Cosine()); - var lp = Degrees(at) + matchPlanet.Value3 + Degrees(qc - qe); - lp = lp.ToRadians(); - var om = matchPlanet.Value6.ToRadians(); - var lo = lp - om; - var so = lo.Sine(); - var co = lo.Cosine(); - var inn = matchPlanet.Value5.ToRadians(); - pvv = pvv + qb; - sp = so * inn.Sine(); - var y = so * inn.Cosine(); - var ps = sp.ASine() + qg; - sp = ps.Sine(); - pd = y.AngleTangent2(co) + om + (qa).ToRadians(); - pd = Unwind(pd); - ci = ps.Cosine(); - rd = pvv * ci; - ll = pd - lg; - var rh = re * re + pvv * pvv - 2.0 * re * pvv * ci * ll.Cosine(); - rh = rh.SquareRoot(); - li = rh * 0.005775518; - - if (k == 1) - { - l0 = pd; - s0 = ps; - p0 = pvv; - vo = rh; - lp1 = lp; - } + qc = returnValue.qc; + qe = returnValue.qe; + qa = returnValue.qa; + qb = returnValue.qb; } - var l1 = ll.Sine(); - var l2 = ll.Cosine(); + var matchPlanet = pl.Where(x => x.Name.ToLower() == s.ToLower()).Select(x => x).FirstOrDefault(); - var ep = (ip < 3) ? (-1.0 * rd * l1 / (re - rd * l2)).AngleTangent() + lg + Math.PI : (re * l1 / (rd - re * l2)).AngleTangent() + pd; - ep = Unwind(ep); + if (new string[] { "Jupiter", "Saturn", "Uranus", "Neptune" }.Contains(s)) + (qa, qb, qc, qd, qe, qf, qg) = PlanetLong_L4945(t, matchPlanet); - var bp = (rd * sp * (ep - pd).Sine() / (ci * re * l1)).AngleTangent(); + var ec = matchPlanet.Value4 + qd; + var am = matchPlanet.APValue + qe; + var at = TrueAnomaly(am, ec); + var pvv = (matchPlanet.Value7 + qf) * (1.0 - ec * ec) / (1.0 + ec * (at).Cosine()); + var lp = Degrees(at) + matchPlanet.Value3 + Degrees(qc - qe); + lp = lp.ToRadians(); + var om = matchPlanet.Value6.ToRadians(); + var lo = lp - om; + var so = lo.Sine(); + var co = lo.Cosine(); + var inn = matchPlanet.Value5.ToRadians(); + pvv = pvv + qb; + sp = so * inn.Sine(); + var y = so * inn.Cosine(); + var ps = sp.ASine() + qg; + sp = ps.Sine(); + pd = y.AngleTangent2(co) + om + (qa).ToRadians(); + pd = Unwind(pd); + ci = ps.Cosine(); + rd = pvv * ci; + ll = pd - lg; + var rh = re * re + pvv * pvv - 2.0 * re * pvv * ci * ll.Cosine(); + rh = rh.SquareRoot(); + li = rh * 0.005775518; + + if (k == 1) + { + l0 = pd; + s0 = ps; + p0 = pvv; + vo = rh; + lp1 = lp; + } + } - var planetLongitude = Degrees(Unwind(ep)); - var planetLatitude = Degrees(Unwind(bp)); - var planetDistanceAU = vo; - var planetHLong1 = Degrees(lp1); - var planetHLong2 = Degrees(l0); - var planetHLat = Degrees(s0); - var planetRVect = p0; + var l1 = ll.Sine(); + var l2 = ll.Cosine(); - return (planetLongitude, planetLatitude, planetDistanceAU, planetHLong1, planetHLong2, planetHLat, planetRVect); - } + var ep = (ip < 3) ? (-1.0 * rd * l1 / (re - rd * l2)).AngleTangent() + lg + Math.PI : (re * l1 / (rd - re * l2)).AngleTangent() + pd; + ep = Unwind(ep); - /// - /// Helper function for planet_long_lat() - /// - public static (double qa, double qb) PlanetLong_L4685(List pl) - { - var qa = 0.00204 * (5.0 * pl[2].APValue - 2.0 * pl[1].APValue + 0.21328).Cosine(); - qa = qa + 0.00103 * (2.0 * pl[2].APValue - pl[1].APValue - 2.8046).Cosine(); - qa = qa + 0.00091 * (2.0 * pl[4].APValue - pl[1].APValue - 0.64582).Cosine(); - qa = qa + 0.00078 * (5.0 * pl[2].APValue - 3.0 * pl[1].APValue + 0.17692).Cosine(); + var bp = (rd * sp * (ep - pd).Sine() / (ci * re * l1)).AngleTangent(); - var qb = 0.000007525 * (2.0 * pl[4].APValue - pl[1].APValue + 0.925251).Cosine(); - qb = qb + 0.000006802 * (5.0 * pl[2].APValue - 3.0 * pl[1].APValue - 4.53642).Cosine(); - qb = qb + 0.000005457 * (2.0 * pl[2].APValue - 2.0 * pl[1].APValue - 1.24246).Cosine(); - qb = qb + 0.000003569 * (5.0 * pl[2].APValue - pl[1].APValue - 1.35699).Cosine(); + var planetLongitude = Degrees(Unwind(ep)); + var planetLatitude = Degrees(Unwind(bp)); + var planetDistanceAU = vo; + var planetHLong1 = Degrees(lp1); + var planetHLong2 = Degrees(l0); + var planetHLat = Degrees(s0); + var planetRVect = p0; - return (qa, qb); - } + return (planetLongitude, planetLatitude, planetDistanceAU, planetHLong1, planetHLong2, planetHLat, planetRVect); + } - /// - /// Helper function for planet_long_lat() - /// - public static (double qa, double qb, double qc, double qe) PlanetLong_L4735(List pl, double ms, double t) - { - var qc = 0.00077 * (4.1406 + t * 2.6227).Sine(); - qc = qc.ToRadians(); - var qe = qc; - - var qa = 0.00313 * (2.0 * ms - 2.0 * pl[2].APValue - 2.587).Cosine(); - qa = qa + 0.00198 * (3.0 * ms - 3.0 * pl[2].APValue + 0.044768).Cosine(); - qa = qa + 0.00136 * (ms - pl[2].APValue - 2.0788).Cosine(); - qa = qa + 0.00096 * (3.0 * ms - 2.0 * pl[2].APValue - 2.3721).Cosine(); - qa = qa + 0.00082 * (pl[4].APValue - pl[2].APValue - 3.6318).Cosine(); - - var qb = 0.000022501 * (2.0 * ms - 2.0 * pl[2].APValue - 1.01592).Cosine(); - qb = qb + 0.000019045 * (3.0 * ms - 3.0 * pl[2].APValue + 1.61577).Cosine(); - qb = qb + 0.000006887 * (pl[4].APValue - pl[2].APValue - 2.06106).Cosine(); - qb = qb + 0.000005172 * (ms - pl[2].APValue - 0.508065).Cosine(); - qb = qb + 0.00000362 * (5.0 * ms - 4.0 * pl[2].APValue - 1.81877).Cosine(); - qb = qb + 0.000003283 * (4.0 * ms - 4.0 * pl[2].APValue + 1.10851).Cosine(); - qb = qb + 0.000003074 * (2.0 * pl[4].APValue - 2.0 * pl[2].APValue - 0.962846).Cosine(); - - return (qa, qb, qc, qe); - } + /// + /// Helper function for planet_long_lat() + /// + public static (double qa, double qb) PlanetLong_L4685(List pl) + { + var qa = 0.00204 * (5.0 * pl[2].APValue - 2.0 * pl[1].APValue + 0.21328).Cosine(); + qa = qa + 0.00103 * (2.0 * pl[2].APValue - pl[1].APValue - 2.8046).Cosine(); + qa = qa + 0.00091 * (2.0 * pl[4].APValue - pl[1].APValue - 0.64582).Cosine(); + qa = qa + 0.00078 * (5.0 * pl[2].APValue - 3.0 * pl[1].APValue + 0.17692).Cosine(); - /// - /// Helper function for planet_long_lat() - /// - public static (double a, double sa, double ca, double qc, double qe, double qa, double qb) PlanetLong_L4810(List pl, double ms) - { - var a = 3.0 * pl[4].APValue - 8.0 * pl[3].APValue + 4.0 * ms; - var sa = a.Sine(); - var ca = a.Cosine(); - var qc = -(0.01133 * sa + 0.00933 * ca); - qc = qc.ToRadians(); - var qe = qc; - - var qa = 0.00705 * (pl[4].APValue - pl[3].APValue - 0.85448).Cosine(); - qa = qa + 0.00607 * (2.0 * pl[4].APValue - pl[3].APValue - 3.2873).Cosine(); - qa = qa + 0.00445 * (2.0 * pl[4].APValue - 2.0 * pl[3].APValue - 3.3492).Cosine(); - qa = qa + 0.00388 * (ms - 2.0 * pl[3].APValue + 0.35771).Cosine(); - qa = qa + 0.00238 * (ms - pl[3].APValue + 0.61256).Cosine(); - qa = qa + 0.00204 * (2.0 * ms - 3.0 * pl[3].APValue + 2.7688).Cosine(); - qa = qa + 0.00177 * (3.0 * pl[3].APValue - pl[2].APValue - 1.0053).Cosine(); - qa = qa + 0.00136 * (2.0 * ms - 4.0 * pl[3].APValue + 2.6894).Cosine(); - qa = qa + 0.00104 * (pl[4].APValue + 0.30749).Cosine(); - - var qb = 0.000053227 * (pl[4].APValue - pl[3].APValue + 0.717864).Cosine(); - qb = qb + 0.000050989 * (2.0 * pl[4].APValue - 2.0 * pl[3].APValue - 1.77997).Cosine(); - qb = qb + 0.000038278 * (2.0 * pl[4].APValue - pl[3].APValue - 1.71617).Cosine(); - qb = qb + 0.000015996 * (ms - pl[3].APValue - 0.969618).Cosine(); - qb = qb + 0.000014764 * (2.0 * ms - 3.0 * pl[3].APValue + 1.19768).Cosine(); - qb = qb + 0.000008966 * (pl[4].APValue - 2.0 * pl[3].APValue + 0.761225).Cosine(); - qb = qb + 0.000007914 * (3.0 * pl[4].APValue - 2.0 * pl[3].APValue - 2.43887).Cosine(); - qb = qb + 0.000007004 * (2.0 * pl[4].APValue - 3.0 * pl[3].APValue - 1.79573).Cosine(); - qb = qb + 0.00000662 * (ms - 2.0 * pl[3].APValue + 1.97575).Cosine(); - qb = qb + 0.00000493 * (3.0 * pl[4].APValue - 3.0 * pl[3].APValue - 1.33069).Cosine(); - qb = qb + 0.000004693 * (3.0 * ms - 5.0 * pl[3].APValue + 3.32665).Cosine(); - qb = qb + 0.000004571 * (2.0 * ms - 4.0 * pl[3].APValue + 4.27086).Cosine(); - qb = qb + 0.000004409 * (3.0 * pl[4].APValue - pl[3].APValue - 2.02158).Cosine(); - - return (a, sa, ca, qc, qe, qa, qb); - } + var qb = 0.000007525 * (2.0 * pl[4].APValue - pl[1].APValue + 0.925251).Cosine(); + qb = qb + 0.000006802 * (5.0 * pl[2].APValue - 3.0 * pl[1].APValue - 4.53642).Cosine(); + qb = qb + 0.000005457 * (2.0 * pl[2].APValue - 2.0 * pl[1].APValue - 1.24246).Cosine(); + qb = qb + 0.000003569 * (5.0 * pl[2].APValue - pl[1].APValue - 1.35699).Cosine(); - /// - /// Helper function for planet_long_lat() - /// - public static (double qa, double qb, double qc, double qd, double qe, double qf, double qg) PlanetLong_L4945(double t, PlanetDataPrecise planet) - { - var qa = 0.0; - var qb = 0.0; - var qc = 0.0; - var qd = 0.0; - var qe = 0.0; - var qf = 0.0; - var qg = 0.0; - var vk = 0.0; - var ja = 0.0; - var jb = 0.0; - var jc = 0.0; - - var j1 = t / 5.0 + 0.1; - var j2 = Unwind(4.14473 + 52.9691 * t); - var j3 = Unwind(4.641118 + 21.32991 * t); - var j4 = Unwind(4.250177 + 7.478172 * t); - var j5 = 5.0 * j3 - 2.0 * j2; - var j6 = 2.0 * j2 - 6.0 * j3 + 3.0 * j4; - - if (new string[] { "Mercury", "Venus", "Mars" }.Contains(planet.Name)) - return (qa, qb, qc, qd, qe, qf, qg); + return (qa, qb); + } - if (new string[] { "Jupiter", "Saturn" }.Contains(planet.Name)) - { - var j7 = j3 - j2; - var u1 = (j3).Sine(); - var u2 = (j3).Cosine(); - var u3 = (2.0 * j3).Sine(); - var u4 = (2.0 * j3).Cosine(); - var u5 = (j5).Sine(); - var u6 = (j5).Cosine(); - var u7 = (2.0 * j5).Sine(); - var u8a = (j6).Sine(); - var u9 = (j7).Sine(); - var ua = (j7).Cosine(); - var ub = (2.0 * j7).Sine(); - var uc = (2.0 * j7).Cosine(); - var ud = (3.0 * j7).Sine(); - var ue = (3.0 * j7).Cosine(); - var uf = (4.0 * j7).Sine(); - var ug = (4.0 * j7).Cosine(); - var vh = (5.0 * j7).Cosine(); - - if (planet.Name == "Saturn") - { - var ui = (3.0 * j3).Sine(); - var uj = (3.0 * j3).Cosine(); - var uk = (4.0 * j3).Sine(); - var ul = (4.0 * j3).Cosine(); - var vi = (2.0 * j5).Cosine(); - var un = (5.0 * j7).Sine(); - var j8 = j4 - j3; - var uo = (2.0 * j8).Sine(); - var up = (2.0 * j8).Cosine(); - var uq = (3.0 * j8).Sine(); - var ur = (3.0 * j8).Cosine(); - - qc = 0.007581 * u7 - 0.007986 * u8a - 0.148811 * u9; - qc = qc - (0.814181 - (0.01815 - 0.016714 * j1) * j1) * u5; - qc = qc - (0.010497 - (0.160906 - 0.0041 * j1) * j1) * u6; - qc = qc - 0.015208 * ud - 0.006339 * uf - 0.006244 * u1; - qc = qc - 0.0165 * ub * u1 - 0.040786 * ub; - qc = qc + (0.008931 + 0.002728 * j1) * u9 * u1 - 0.005775 * ud * u1; - qc = qc + (0.081344 + 0.003206 * j1) * ua * u1 + 0.015019 * uc * u1; - qc = qc + (0.085581 + 0.002494 * j1) * u9 * u2 + 0.014394 * uc * u2; - qc = qc + (0.025328 - 0.003117 * j1) * ua * u2 + 0.006319 * ue * u2; - qc = qc + 0.006369 * u9 * u3 + 0.009156 * ub * u3 + 0.007525 * uq * u3; - qc = qc - 0.005236 * ua * u4 - 0.007736 * uc * u4 - 0.007528 * ur * u4; - qc = qc.ToRadians(); - - qd = (-7927.0 + (2548.0 + 91.0 * j1) * j1) * u5; - qd = qd + (13381.0 + (1226.0 - 253.0 * j1) * j1) * u6 + (248.0 - 121.0 * j1) * u7; - qd = qd - (305.0 + 91.0 * j1) * vi + 412.0 * ub + 12415.0 * u1; - qd = qd + (390.0 - 617.0 * j1) * u9 * u1 + (165.0 - 204.0 * j1) * ub * u1; - qd = qd + 26599.0 * ua * u1 - 4687.0 * uc * u1 - 1870.0 * ue * u1 - 821.0 * ug * u1; - qd = qd - 377.0 * vh * u1 + 497.0 * up * u1 + (163.0 - 611.0 * j1) * u2; - qd = qd - 12696.0 * u9 * u2 - 4200.0 * ub * u2 - 1503.0 * ud * u2 - 619.0 * uf * u2; - qd = qd - 268.0 * un * u2 - (282.0 + 1306.0 * j1) * ua * u2; - qd = qd + (-86.0 + 230.0 * j1) * uc * u2 + 461.0 * uo * u2 - 350.0 * u3; - qd = qd + (2211.0 - 286.0 * j1) * u9 * u3 - 2208.0 * ub * u3 - 568.0 * ud * u3; - qd = qd - 346.0 * uf * u3 - (2780.0 + 222.0 * j1) * ua * u3; - qd = qd + (2022.0 + 263.0 * j1) * uc * u3 + 248.0 * ue * u3 + 242.0 * uq * u3; - qd = qd + 467.0 * ur * u3 - 490.0 * u4 - (2842.0 + 279.0 * j1) * u9 * u4; - qd = qd + (128.0 + 226.0 * j1) * ub * u4 + 224.0 * ud * u4; - qd = qd + (-1594.0 + 282.0 * j1) * ua * u4 + (2162.0 - 207.0 * j1) * uc * u4; - qd = qd + 561.0 * ue * u4 + 343.0 * ug * u4 + 469.0 * uq * u4 - 242.0 * ur * u4; - qd = qd - 205.0 * u9 * ui + 262.0 * ud * ui + 208.0 * ua * uj - 271.0 * ue * uj; - qd = qd - 382.0 * ue * uk - 376.0 * ud * ul; - qd = qd * 0.0000001; - - vk = (0.077108 + (0.007186 - 0.001533 * j1) * j1) * u5; - vk = vk - 0.007075 * u9; - vk = vk + (0.045803 - (0.014766 + 0.000536 * j1) * j1) * u6; - vk = vk - 0.072586 * u2 - 0.075825 * u9 * u1 - 0.024839 * ub * u1; - vk = vk - 0.008631 * ud * u1 - 0.150383 * ua * u2; - vk = vk + 0.026897 * uc * u2 + 0.010053 * ue * u2; - vk = vk - (0.013597 + 0.001719 * j1) * u9 * u3 + 0.011981 * ub * u4; - vk = vk - (0.007742 - 0.001517 * j1) * ua * u3; - vk = vk + (0.013586 - 0.001375 * j1) * uc * u3; - vk = vk - (0.013667 - 0.001239 * j1) * u9 * u4; - vk = vk + (0.014861 + 0.001136 * j1) * ua * u4; - vk = vk - (0.013064 + 0.001628 * j1) * uc * u4; - qe = qc - (vk.ToRadians() / planet.Value4); - - qf = 572.0 * u5 - 1590.0 * ub * u2 + 2933.0 * u6 - 647.0 * ud * u2; - qf = qf + 33629.0 * ua - 344.0 * uf * u2 - 3081.0 * uc + 2885.0 * ua * u2; - qf = qf - 1423.0 * ue + (2172.0 + 102.0 * j1) * uc * u2 - 671.0 * ug; - qf = qf + 296.0 * ue * u2 - 320.0 * vh - 267.0 * ub * u3 + 1098.0 * u1; - qf = qf - 778.0 * ua * u3 - 2812.0 * u9 * u1 + 495.0 * uc * u3 + 688.0 * ub * u1; - qf = qf + 250.0 * ue * u3 - 393.0 * ud * u1 - 856.0 * u9 * u4 - 228.0 * uf * u1; - qf = qf + 441.0 * ub * u4 + 2138.0 * ua * u1 + 296.0 * uc * u4 - 999.0 * uc * u1; - qf = qf + 211.0 * ue * u4 - 642.0 * ue * u1 - 427.0 * u9 * ui - 325.0 * ug * u1; - qf = qf + 398.0 * ud * ui - 890.0 * u2 + 344.0 * ua * uj + 2206.0 * u9 * u2; - qf = qf - 427.0 * ue * uj; - qf = qf * 0.000001; - - qg = 0.000747 * ua * u1 + 0.001069 * ua * u2 + 0.002108 * ub * u3; - qg = qg + 0.001261 * uc * u3 + 0.001236 * ub * u4 - 0.002075 * uc * u4; - qg = qg.ToRadians(); - - return (qa, qb, qc, qd, qe, qf, qg); - } + /// + /// Helper function for planet_long_lat() + /// + public static (double qa, double qb, double qc, double qe) PlanetLong_L4735(List pl, double ms, double t) + { + var qc = 0.00077 * (4.1406 + t * 2.6227).Sine(); + qc = qc.ToRadians(); + var qe = qc; + + var qa = 0.00313 * (2.0 * ms - 2.0 * pl[2].APValue - 2.587).Cosine(); + qa = qa + 0.00198 * (3.0 * ms - 3.0 * pl[2].APValue + 0.044768).Cosine(); + qa = qa + 0.00136 * (ms - pl[2].APValue - 2.0788).Cosine(); + qa = qa + 0.00096 * (3.0 * ms - 2.0 * pl[2].APValue - 2.3721).Cosine(); + qa = qa + 0.00082 * (pl[4].APValue - pl[2].APValue - 3.6318).Cosine(); + + var qb = 0.000022501 * (2.0 * ms - 2.0 * pl[2].APValue - 1.01592).Cosine(); + qb = qb + 0.000019045 * (3.0 * ms - 3.0 * pl[2].APValue + 1.61577).Cosine(); + qb = qb + 0.000006887 * (pl[4].APValue - pl[2].APValue - 2.06106).Cosine(); + qb = qb + 0.000005172 * (ms - pl[2].APValue - 0.508065).Cosine(); + qb = qb + 0.00000362 * (5.0 * ms - 4.0 * pl[2].APValue - 1.81877).Cosine(); + qb = qb + 0.000003283 * (4.0 * ms - 4.0 * pl[2].APValue + 1.10851).Cosine(); + qb = qb + 0.000003074 * (2.0 * pl[4].APValue - 2.0 * pl[2].APValue - 0.962846).Cosine(); + + return (qa, qb, qc, qe); + } + + /// + /// Helper function for planet_long_lat() + /// + public static (double a, double sa, double ca, double qc, double qe, double qa, double qb) PlanetLong_L4810(List pl, double ms) + { + var a = 3.0 * pl[4].APValue - 8.0 * pl[3].APValue + 4.0 * ms; + var sa = a.Sine(); + var ca = a.Cosine(); + var qc = -(0.01133 * sa + 0.00933 * ca); + qc = qc.ToRadians(); + var qe = qc; + + var qa = 0.00705 * (pl[4].APValue - pl[3].APValue - 0.85448).Cosine(); + qa = qa + 0.00607 * (2.0 * pl[4].APValue - pl[3].APValue - 3.2873).Cosine(); + qa = qa + 0.00445 * (2.0 * pl[4].APValue - 2.0 * pl[3].APValue - 3.3492).Cosine(); + qa = qa + 0.00388 * (ms - 2.0 * pl[3].APValue + 0.35771).Cosine(); + qa = qa + 0.00238 * (ms - pl[3].APValue + 0.61256).Cosine(); + qa = qa + 0.00204 * (2.0 * ms - 3.0 * pl[3].APValue + 2.7688).Cosine(); + qa = qa + 0.00177 * (3.0 * pl[3].APValue - pl[2].APValue - 1.0053).Cosine(); + qa = qa + 0.00136 * (2.0 * ms - 4.0 * pl[3].APValue + 2.6894).Cosine(); + qa = qa + 0.00104 * (pl[4].APValue + 0.30749).Cosine(); + + var qb = 0.000053227 * (pl[4].APValue - pl[3].APValue + 0.717864).Cosine(); + qb = qb + 0.000050989 * (2.0 * pl[4].APValue - 2.0 * pl[3].APValue - 1.77997).Cosine(); + qb = qb + 0.000038278 * (2.0 * pl[4].APValue - pl[3].APValue - 1.71617).Cosine(); + qb = qb + 0.000015996 * (ms - pl[3].APValue - 0.969618).Cosine(); + qb = qb + 0.000014764 * (2.0 * ms - 3.0 * pl[3].APValue + 1.19768).Cosine(); + qb = qb + 0.000008966 * (pl[4].APValue - 2.0 * pl[3].APValue + 0.761225).Cosine(); + qb = qb + 0.000007914 * (3.0 * pl[4].APValue - 2.0 * pl[3].APValue - 2.43887).Cosine(); + qb = qb + 0.000007004 * (2.0 * pl[4].APValue - 3.0 * pl[3].APValue - 1.79573).Cosine(); + qb = qb + 0.00000662 * (ms - 2.0 * pl[3].APValue + 1.97575).Cosine(); + qb = qb + 0.00000493 * (3.0 * pl[4].APValue - 3.0 * pl[3].APValue - 1.33069).Cosine(); + qb = qb + 0.000004693 * (3.0 * ms - 5.0 * pl[3].APValue + 3.32665).Cosine(); + qb = qb + 0.000004571 * (2.0 * ms - 4.0 * pl[3].APValue + 4.27086).Cosine(); + qb = qb + 0.000004409 * (3.0 * pl[4].APValue - pl[3].APValue - 2.02158).Cosine(); + + return (a, sa, ca, qc, qe, qa, qb); + } + + /// + /// Helper function for planet_long_lat() + /// + public static (double qa, double qb, double qc, double qd, double qe, double qf, double qg) PlanetLong_L4945(double t, PlanetDataPrecise planet) + { + var qa = 0.0; + var qb = 0.0; + var qc = 0.0; + var qd = 0.0; + var qe = 0.0; + var qf = 0.0; + var qg = 0.0; + var vk = 0.0; + var ja = 0.0; + var jb = 0.0; + var jc = 0.0; + + var j1 = t / 5.0 + 0.1; + var j2 = Unwind(4.14473 + 52.9691 * t); + var j3 = Unwind(4.641118 + 21.32991 * t); + var j4 = Unwind(4.250177 + 7.478172 * t); + var j5 = 5.0 * j3 - 2.0 * j2; + var j6 = 2.0 * j2 - 6.0 * j3 + 3.0 * j4; + + if (new string[] { "Mercury", "Venus", "Mars" }.Contains(planet.Name)) + return (qa, qb, qc, qd, qe, qf, qg); - qc = (0.331364 - (0.010281 + 0.004692 * j1) * j1) * u5; - qc = qc + (0.003228 - (0.064436 - 0.002075 * j1) * j1) * u6; - qc = qc - (0.003083 + (0.000275 - 0.000489 * j1) * j1) * u7; - qc = qc + 0.002472 * u8a + 0.013619 * u9 + 0.018472 * ub; - qc = qc + 0.006717 * ud + 0.002775 * uf + 0.006417 * ub * u1; - qc = qc + (0.007275 - 0.001253 * j1) * u9 * u1 + 0.002439 * ud * u1; - qc = qc - (0.035681 + 0.001208 * j1) * u9 * u2 - 0.003767 * uc * u1; - qc = qc - (0.033839 + 0.001125 * j1) * ua * u1 - 0.004261 * ub * u2; - qc = qc + (0.001161 * j1 - 0.006333) * ua * u2 + 0.002178 * u2; - qc = qc - 0.006675 * uc * u2 - 0.002664 * ue * u2 - 0.002572 * u9 * u3; - qc = qc - 0.003567 * ub * u3 + 0.002094 * ua * u4 + 0.003342 * uc * u4; + if (new string[] { "Jupiter", "Saturn" }.Contains(planet.Name)) + { + var j7 = j3 - j2; + var u1 = (j3).Sine(); + var u2 = (j3).Cosine(); + var u3 = (2.0 * j3).Sine(); + var u4 = (2.0 * j3).Cosine(); + var u5 = (j5).Sine(); + var u6 = (j5).Cosine(); + var u7 = (2.0 * j5).Sine(); + var u8a = (j6).Sine(); + var u9 = (j7).Sine(); + var ua = (j7).Cosine(); + var ub = (2.0 * j7).Sine(); + var uc = (2.0 * j7).Cosine(); + var ud = (3.0 * j7).Sine(); + var ue = (3.0 * j7).Cosine(); + var uf = (4.0 * j7).Sine(); + var ug = (4.0 * j7).Cosine(); + var vh = (5.0 * j7).Cosine(); + + if (planet.Name == "Saturn") + { + var ui = (3.0 * j3).Sine(); + var uj = (3.0 * j3).Cosine(); + var uk = (4.0 * j3).Sine(); + var ul = (4.0 * j3).Cosine(); + var vi = (2.0 * j5).Cosine(); + var un = (5.0 * j7).Sine(); + var j8 = j4 - j3; + var uo = (2.0 * j8).Sine(); + var up = (2.0 * j8).Cosine(); + var uq = (3.0 * j8).Sine(); + var ur = (3.0 * j8).Cosine(); + + qc = 0.007581 * u7 - 0.007986 * u8a - 0.148811 * u9; + qc = qc - (0.814181 - (0.01815 - 0.016714 * j1) * j1) * u5; + qc = qc - (0.010497 - (0.160906 - 0.0041 * j1) * j1) * u6; + qc = qc - 0.015208 * ud - 0.006339 * uf - 0.006244 * u1; + qc = qc - 0.0165 * ub * u1 - 0.040786 * ub; + qc = qc + (0.008931 + 0.002728 * j1) * u9 * u1 - 0.005775 * ud * u1; + qc = qc + (0.081344 + 0.003206 * j1) * ua * u1 + 0.015019 * uc * u1; + qc = qc + (0.085581 + 0.002494 * j1) * u9 * u2 + 0.014394 * uc * u2; + qc = qc + (0.025328 - 0.003117 * j1) * ua * u2 + 0.006319 * ue * u2; + qc = qc + 0.006369 * u9 * u3 + 0.009156 * ub * u3 + 0.007525 * uq * u3; + qc = qc - 0.005236 * ua * u4 - 0.007736 * uc * u4 - 0.007528 * ur * u4; qc = qc.ToRadians(); - qd = (3606.0 + (130.0 - 43.0 * j1) * j1) * u5 + (1289.0 - 580.0 * j1) * u6; - qd = qd - 6764.0 * u9 * u1 - 1110.0 * ub * u1 - 224.0 * ud * u1 - 204.0 * u1; - qd = qd + (1284.0 + 116.0 * j1) * ua * u1 + 188.0 * uc * u1; - qd = qd + (1460.0 + 130.0 * j1) * u9 * u2 + 224.0 * ub * u2 - 817.0 * u2; - qd = qd + 6074.0 * u2 * ua + 992.0 * uc * u2 + 508.0 * ue * u2 + 230.0 * ug * u2; - qd = qd + 108.0 * vh * u2 - (956.0 + 73.0 * j1) * u9 * u3 + 448.0 * ub * u3; - qd = qd + 137.0 * ud * u3 + (108.0 * j1 - 997.0) * ua * u3 + 480.0 * uc * u3; - qd = qd + 148.0 * ue * u3 + (99.0 * j1 - 956.0) * u9 * u4 + 490.0 * ub * u4; - qd = qd + 158.0 * ud * u4 + 179.0 * u4 + (1024.0 + 75.0 * j1) * ua * u4; - qd = qd - 437.0 * uc * u4 - 132.0 * ue * u4; + qd = (-7927.0 + (2548.0 + 91.0 * j1) * j1) * u5; + qd = qd + (13381.0 + (1226.0 - 253.0 * j1) * j1) * u6 + (248.0 - 121.0 * j1) * u7; + qd = qd - (305.0 + 91.0 * j1) * vi + 412.0 * ub + 12415.0 * u1; + qd = qd + (390.0 - 617.0 * j1) * u9 * u1 + (165.0 - 204.0 * j1) * ub * u1; + qd = qd + 26599.0 * ua * u1 - 4687.0 * uc * u1 - 1870.0 * ue * u1 - 821.0 * ug * u1; + qd = qd - 377.0 * vh * u1 + 497.0 * up * u1 + (163.0 - 611.0 * j1) * u2; + qd = qd - 12696.0 * u9 * u2 - 4200.0 * ub * u2 - 1503.0 * ud * u2 - 619.0 * uf * u2; + qd = qd - 268.0 * un * u2 - (282.0 + 1306.0 * j1) * ua * u2; + qd = qd + (-86.0 + 230.0 * j1) * uc * u2 + 461.0 * uo * u2 - 350.0 * u3; + qd = qd + (2211.0 - 286.0 * j1) * u9 * u3 - 2208.0 * ub * u3 - 568.0 * ud * u3; + qd = qd - 346.0 * uf * u3 - (2780.0 + 222.0 * j1) * ua * u3; + qd = qd + (2022.0 + 263.0 * j1) * uc * u3 + 248.0 * ue * u3 + 242.0 * uq * u3; + qd = qd + 467.0 * ur * u3 - 490.0 * u4 - (2842.0 + 279.0 * j1) * u9 * u4; + qd = qd + (128.0 + 226.0 * j1) * ub * u4 + 224.0 * ud * u4; + qd = qd + (-1594.0 + 282.0 * j1) * ua * u4 + (2162.0 - 207.0 * j1) * uc * u4; + qd = qd + 561.0 * ue * u4 + 343.0 * ug * u4 + 469.0 * uq * u4 - 242.0 * ur * u4; + qd = qd - 205.0 * u9 * ui + 262.0 * ud * ui + 208.0 * ua * uj - 271.0 * ue * uj; + qd = qd - 382.0 * ue * uk - 376.0 * ud * ul; qd = qd * 0.0000001; - vk = (0.007192 - 0.003147 * j1) * u5 - 0.004344 * u1; - vk = vk + (j1 * (0.000197 * j1 - 0.000675) - 0.020428) * u6; - vk = vk + 0.034036 * ua * u1 + (0.007269 + 0.000672 * j1) * u9 * u1; - vk = vk + 0.005614 * uc * u1 + 0.002964 * ue * u1 + 0.037761 * u9 * u2; - vk = vk + 0.006158 * ub * u2 - 0.006603 * ua * u2 - 0.005356 * u9 * u3; - vk = vk + 0.002722 * ub * u3 + 0.004483 * ua * u3; - vk = vk - 0.002642 * uc * u3 + 0.004403 * u9 * u4; - vk = vk - 0.002536 * ub * u4 + 0.005547 * ua * u4 - 0.002689 * uc * u4; + vk = (0.077108 + (0.007186 - 0.001533 * j1) * j1) * u5; + vk = vk - 0.007075 * u9; + vk = vk + (0.045803 - (0.014766 + 0.000536 * j1) * j1) * u6; + vk = vk - 0.072586 * u2 - 0.075825 * u9 * u1 - 0.024839 * ub * u1; + vk = vk - 0.008631 * ud * u1 - 0.150383 * ua * u2; + vk = vk + 0.026897 * uc * u2 + 0.010053 * ue * u2; + vk = vk - (0.013597 + 0.001719 * j1) * u9 * u3 + 0.011981 * ub * u4; + vk = vk - (0.007742 - 0.001517 * j1) * ua * u3; + vk = vk + (0.013586 - 0.001375 * j1) * uc * u3; + vk = vk - (0.013667 - 0.001239 * j1) * u9 * u4; + vk = vk + (0.014861 + 0.001136 * j1) * ua * u4; + vk = vk - (0.013064 + 0.001628 * j1) * uc * u4; qe = qc - (vk.ToRadians() / planet.Value4); - qf = 205.0 * ua - 263.0 * u6 + 693.0 * uc + 312.0 * ue + 147.0 * ug + 299.0 * u9 * u1; - qf = qf + 181.0 * uc * u1 + 204.0 * ub * u2 + 111.0 * ud * u2 - 337.0 * ua * u2; - qf = qf - 111.0 * uc * u2; + qf = 572.0 * u5 - 1590.0 * ub * u2 + 2933.0 * u6 - 647.0 * ud * u2; + qf = qf + 33629.0 * ua - 344.0 * uf * u2 - 3081.0 * uc + 2885.0 * ua * u2; + qf = qf - 1423.0 * ue + (2172.0 + 102.0 * j1) * uc * u2 - 671.0 * ug; + qf = qf + 296.0 * ue * u2 - 320.0 * vh - 267.0 * ub * u3 + 1098.0 * u1; + qf = qf - 778.0 * ua * u3 - 2812.0 * u9 * u1 + 495.0 * uc * u3 + 688.0 * ub * u1; + qf = qf + 250.0 * ue * u3 - 393.0 * ud * u1 - 856.0 * u9 * u4 - 228.0 * uf * u1; + qf = qf + 441.0 * ub * u4 + 2138.0 * ua * u1 + 296.0 * uc * u4 - 999.0 * uc * u1; + qf = qf + 211.0 * ue * u4 - 642.0 * ue * u1 - 427.0 * u9 * ui - 325.0 * ug * u1; + qf = qf + 398.0 * ud * ui - 890.0 * u2 + 344.0 * ua * uj + 2206.0 * u9 * u2; + qf = qf - 427.0 * ue * uj; qf = qf * 0.000001; + qg = 0.000747 * ua * u1 + 0.001069 * ua * u2 + 0.002108 * ub * u3; + qg = qg + 0.001261 * uc * u3 + 0.001236 * ub * u4 - 0.002075 * uc * u4; + qg = qg.ToRadians(); + return (qa, qb, qc, qd, qe, qf, qg); } - if (new string[] { "Uranus", "Neptune" }.Contains(planet.Name)) - { - var j8 = Unwind(1.46205 + 3.81337 * t); - var j9 = 2.0 * j8 - j4; - var vj = (j9).Sine(); - var uu = (j9).Cosine(); - var uv = (2.0 * j9).Sine(); - var uw = (2.0 * j9).Cosine(); - - if (planet.Name == "Neptune") - { - ja = j8 - j2; - jb = j8 - j3; - jc = j8 - j4; - qc = (0.001089 * j1 - 0.589833) * vj; - qc = qc + (0.004658 * j1 - 0.056094) * uu - 0.024286 * uv; - qc = qc.ToRadians(); - - vk = 0.024039 * vj - 0.025303 * uu + 0.006206 * uv; - vk = vk - 0.005992 * uw; - qe = qc - (vk.ToRadians() / planet.Value4); - - qd = 4389.0 * vj + 1129.0 * uv + 4262.0 * uu + 1089.0 * uw; - qd = qd * 0.0000001; - - qf = 8189.0 * uu - 817.0 * vj + 781.0 * uw; - qf = qf * 0.000001; - - var vd = (2.0 * jc).Sine(); - var ve = (2.0 * jc).Cosine(); - var vf = (j8).Sine(); - var vg = (j8).Cosine(); - qa = -0.009556 * (ja).Sine() - 0.005178 * (jb).Sine(); - qa = qa + 0.002572 * vd - 0.002972 * ve * vf - 0.002833 * vd * vg; - - qg = 0.000336 * ve * vf + 0.000364 * vd * vg; - qg = qg.ToRadians(); - - qb = -40596.0 + 4992.0 * (ja).Cosine() + 2744.0 * (jb).Cosine(); - qb = qb + 2044.0 * (jc).Cosine() + 1051.0 * ve; - qb = qb * 0.000001; - - return (qa, qb, qc, qd, qe, qf, qg); - } + qc = (0.331364 - (0.010281 + 0.004692 * j1) * j1) * u5; + qc = qc + (0.003228 - (0.064436 - 0.002075 * j1) * j1) * u6; + qc = qc - (0.003083 + (0.000275 - 0.000489 * j1) * j1) * u7; + qc = qc + 0.002472 * u8a + 0.013619 * u9 + 0.018472 * ub; + qc = qc + 0.006717 * ud + 0.002775 * uf + 0.006417 * ub * u1; + qc = qc + (0.007275 - 0.001253 * j1) * u9 * u1 + 0.002439 * ud * u1; + qc = qc - (0.035681 + 0.001208 * j1) * u9 * u2 - 0.003767 * uc * u1; + qc = qc - (0.033839 + 0.001125 * j1) * ua * u1 - 0.004261 * ub * u2; + qc = qc + (0.001161 * j1 - 0.006333) * ua * u2 + 0.002178 * u2; + qc = qc - 0.006675 * uc * u2 - 0.002664 * ue * u2 - 0.002572 * u9 * u3; + qc = qc - 0.003567 * ub * u3 + 0.002094 * ua * u4 + 0.003342 * uc * u4; + qc = qc.ToRadians(); + + qd = (3606.0 + (130.0 - 43.0 * j1) * j1) * u5 + (1289.0 - 580.0 * j1) * u6; + qd = qd - 6764.0 * u9 * u1 - 1110.0 * ub * u1 - 224.0 * ud * u1 - 204.0 * u1; + qd = qd + (1284.0 + 116.0 * j1) * ua * u1 + 188.0 * uc * u1; + qd = qd + (1460.0 + 130.0 * j1) * u9 * u2 + 224.0 * ub * u2 - 817.0 * u2; + qd = qd + 6074.0 * u2 * ua + 992.0 * uc * u2 + 508.0 * ue * u2 + 230.0 * ug * u2; + qd = qd + 108.0 * vh * u2 - (956.0 + 73.0 * j1) * u9 * u3 + 448.0 * ub * u3; + qd = qd + 137.0 * ud * u3 + (108.0 * j1 - 997.0) * ua * u3 + 480.0 * uc * u3; + qd = qd + 148.0 * ue * u3 + (99.0 * j1 - 956.0) * u9 * u4 + 490.0 * ub * u4; + qd = qd + 158.0 * ud * u4 + 179.0 * u4 + (1024.0 + 75.0 * j1) * ua * u4; + qd = qd - 437.0 * uc * u4 - 132.0 * ue * u4; + qd = qd * 0.0000001; + + vk = (0.007192 - 0.003147 * j1) * u5 - 0.004344 * u1; + vk = vk + (j1 * (0.000197 * j1 - 0.000675) - 0.020428) * u6; + vk = vk + 0.034036 * ua * u1 + (0.007269 + 0.000672 * j1) * u9 * u1; + vk = vk + 0.005614 * uc * u1 + 0.002964 * ue * u1 + 0.037761 * u9 * u2; + vk = vk + 0.006158 * ub * u2 - 0.006603 * ua * u2 - 0.005356 * u9 * u3; + vk = vk + 0.002722 * ub * u3 + 0.004483 * ua * u3; + vk = vk - 0.002642 * uc * u3 + 0.004403 * u9 * u4; + vk = vk - 0.002536 * ub * u4 + 0.005547 * ua * u4 - 0.002689 * uc * u4; + qe = qc - (vk.ToRadians() / planet.Value4); + + qf = 205.0 * ua - 263.0 * u6 + 693.0 * uc + 312.0 * ue + 147.0 * ug + 299.0 * u9 * u1; + qf = qf + 181.0 * uc * u1 + 204.0 * ub * u2 + 111.0 * ud * u2 - 337.0 * ua * u2; + qf = qf - 111.0 * uc * u2; + qf = qf * 0.000001; + + return (qa, qb, qc, qd, qe, qf, qg); + } + + if (new string[] { "Uranus", "Neptune" }.Contains(planet.Name)) + { + var j8 = Unwind(1.46205 + 3.81337 * t); + var j9 = 2.0 * j8 - j4; + var vj = (j9).Sine(); + var uu = (j9).Cosine(); + var uv = (2.0 * j9).Sine(); + var uw = (2.0 * j9).Cosine(); - ja = j4 - j2; - jb = j4 - j3; + if (planet.Name == "Neptune") + { + ja = j8 - j2; + jb = j8 - j3; jc = j8 - j4; - qc = (0.864319 - 0.001583 * j1) * vj; - qc = qc + (0.082222 - 0.006833 * j1) * uu + 0.036017 * uv; - qc = qc - 0.003019 * uw + 0.008122 * (j6).Sine(); + qc = (0.001089 * j1 - 0.589833) * vj; + qc = qc + (0.004658 * j1 - 0.056094) * uu - 0.024286 * uv; qc = qc.ToRadians(); - vk = 0.120303 * vj + 0.006197 * uv; - vk = vk + (0.019472 - 0.000947 * j1) * uu; + vk = 0.024039 * vj - 0.025303 * uu + 0.006206 * uv; + vk = vk - 0.005992 * uw; qe = qc - (vk.ToRadians() / planet.Value4); - qd = (163.0 * j1 - 3349.0) * vj + 20981.0 * uu + 1311.0 * uw; + qd = 4389.0 * vj + 1129.0 * uv + 4262.0 * uu + 1089.0 * uw; qd = qd * 0.0000001; - qf = -0.003825 * uu; - - qa = (-0.038581 + (0.002031 - 0.00191 * j1) * j1) * (j4 + jb).Cosine(); - qa = qa + (0.010122 - 0.000988 * j1) * (j4 + jb).Sine(); - var a = (0.034964 - (0.001038 - 0.000868 * j1) * j1) * (2.0 * j4 + jb).Cosine(); - qa = a + qa + 0.005594 * (j4 + 3.0 * jc).Sine() - 0.014808 * (ja).Sine(); - qa = qa - 0.005794 * (jb).Sine() + 0.002347 * (jb).Cosine(); - qa = qa + 0.009872 * (jc).Sine() + 0.008803 * (2.0 * jc).Sine(); - qa = qa - 0.004308 * (3.0 * jc).Sine(); - - var ux = jb.Sine(); - var uy = jb.Cosine(); - var uz = j4.Sine(); - var va = j4.Cosine(); - var vb = (2.0 * j4).Sine(); - var vc = (2.0 * j4).Cosine(); - qg = (0.000458 * ux - 0.000642 * uy - 0.000517 * (4.0 * jc).Cosine()) * uz; - qg = qg - (0.000347 * ux + 0.000853 * uy + 0.000517 * (4.0 * jb).Sine()) * va; - qg = qg + 0.000403 * ((2.0 * jc).Cosine() * vb + (2.0 * jc).Sine() * vc); + qf = 8189.0 * uu - 817.0 * vj + 781.0 * uw; + qf = qf * 0.000001; + + var vd = (2.0 * jc).Sine(); + var ve = (2.0 * jc).Cosine(); + var vf = (j8).Sine(); + var vg = (j8).Cosine(); + qa = -0.009556 * (ja).Sine() - 0.005178 * (jb).Sine(); + qa = qa + 0.002572 * vd - 0.002972 * ve * vf - 0.002833 * vd * vg; + + qg = 0.000336 * ve * vf + 0.000364 * vd * vg; qg = qg.ToRadians(); - qb = -25948.0 + 4985.0 * (ja).Cosine() - 1230.0 * va + 3354.0 * uy; - qb = qb + 904.0 * (2.0 * jc).Cosine() + 894.0 * ((jc).Cosine() - (3.0 * jc).Cosine()); - qb = qb + (5795.0 * va - 1165.0 * uz + 1388.0 * vc) * ux; - qb = qb + (1351.0 * va + 5702.0 * uz + 1388.0 * vb) * uy; + qb = -40596.0 + 4992.0 * (ja).Cosine() + 2744.0 * (jb).Cosine(); + qb = qb + 2044.0 * (jc).Cosine() + 1051.0 * ve; qb = qb * 0.000001; return (qa, qb, qc, qd, qe, qf, qg); } + ja = j4 - j2; + jb = j4 - j3; + jc = j8 - j4; + qc = (0.864319 - 0.001583 * j1) * vj; + qc = qc + (0.082222 - 0.006833 * j1) * uu + 0.036017 * uv; + qc = qc - 0.003019 * uw + 0.008122 * (j6).Sine(); + qc = qc.ToRadians(); + + vk = 0.120303 * vj + 0.006197 * uv; + vk = vk + (0.019472 - 0.000947 * j1) * uu; + qe = qc - (vk.ToRadians() / planet.Value4); + + qd = (163.0 * j1 - 3349.0) * vj + 20981.0 * uu + 1311.0 * uw; + qd = qd * 0.0000001; + + qf = -0.003825 * uu; + + qa = (-0.038581 + (0.002031 - 0.00191 * j1) * j1) * (j4 + jb).Cosine(); + qa = qa + (0.010122 - 0.000988 * j1) * (j4 + jb).Sine(); + var a = (0.034964 - (0.001038 - 0.000868 * j1) * j1) * (2.0 * j4 + jb).Cosine(); + qa = a + qa + 0.005594 * (j4 + 3.0 * jc).Sine() - 0.014808 * (ja).Sine(); + qa = qa - 0.005794 * (jb).Sine() + 0.002347 * (jb).Cosine(); + qa = qa + 0.009872 * (jc).Sine() + 0.008803 * (2.0 * jc).Sine(); + qa = qa - 0.004308 * (3.0 * jc).Sine(); + + var ux = jb.Sine(); + var uy = jb.Cosine(); + var uz = j4.Sine(); + var va = j4.Cosine(); + var vb = (2.0 * j4).Sine(); + var vc = (2.0 * j4).Cosine(); + qg = (0.000458 * ux - 0.000642 * uy - 0.000517 * (4.0 * jc).Cosine()) * uz; + qg = qg - (0.000347 * ux + 0.000853 * uy + 0.000517 * (4.0 * jb).Sine()) * va; + qg = qg + 0.000403 * ((2.0 * jc).Cosine() * vb + (2.0 * jc).Sine() * vc); + qg = qg.ToRadians(); + + qb = -25948.0 + 4985.0 * (ja).Cosine() - 1230.0 * va + 3354.0 * uy; + qb = qb + 904.0 * (2.0 * jc).Cosine() + 894.0 * ((jc).Cosine() - (3.0 * jc).Cosine()); + qb = qb + (5795.0 * va - 1165.0 * uz + 1388.0 * vc) * ux; + qb = qb + (1351.0 * va + 5702.0 * uz + 1388.0 * vb) * uy; + qb = qb * 0.000001; + return (qa, qb, qc, qd, qe, qf, qg); } - /// - /// For W, in radians, return S, also in radians. - /// - /// - /// Original macro name: SolveCubic - /// - public static double SolveCubic(double w) - { - var s = w / 3.0; + return (qa, qb, qc, qd, qe, qf, qg); + } - while (1 == 1) - { - var s2 = s * s; - var d = (s2 + 3.0) * s - w; + /// + /// For W, in radians, return S, also in radians. + /// + /// + /// Original macro name: SolveCubic + /// + public static double SolveCubic(double w) + { + var s = w / 3.0; - if (Math.Abs(d) < 0.000001) - { - return s; - } + while (1 == 1) + { + var s2 = s * s; + var d = (s2 + 3.0) * s - w; - s = ((2.0 * s * s2) + w) / (3.0 * (s2 + 1.0)); + if (Math.Abs(d) < 0.000001) + { + return s; } + + s = ((2.0 * s * s2) + w) / (3.0 * (s2 + 1.0)); } + } - /// - /// Calculate longitude, latitude, and distance of parabolic-orbit comet. - /// - /// - /// Original macro names: PcometLong, PcometLat, PcometDist - /// - /// Local civil time, hour part. - /// Local civil time, minutes part. - /// Local civil time, seconds part. - /// Daylight Savings offset. - /// Time zone correction, in hours. - /// Local date, day part. - /// Local date, month part. - /// Local date, year part. - /// Perihelion epoch (day) - /// Perihelion epoch (month) - /// Perihelion epoch (year) - /// a (AU) - /// Inclination (degrees) - /// Perihelion (degrees) - /// Node (degrees) - /// - /// cometLongDeg -- Comet longitude (degrees) - /// cometLatDeg -- Comet lat (degrees) - /// cometDistAU -- Comet distance from Earth (AU) - /// - public static (double cometLongDeg, double cometLatDeg, double cometDistAU) PCometLongLatDist(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr, double td, int tm, int ty, double q, double i, double p, double n) - { - var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); - var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); - var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); - var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); - var tpe = (ut / 365.242191) + CivilDateToJulianDate(gd, gm, gy) - CivilDateToJulianDate(td, tm, ty); - var lg = (SunLong(lh, lm, ls, ds, zc, dy, mn, yr) + 180.0).ToRadians(); - var re = SunDist(lh, lm, ls, ds, zc, dy, mn, yr); - - var rh2 = 0.0; - var rd = 0.0; - var s3 = 0.0; - var c3 = 0.0; - var lc = 0.0; - var s2 = 0.0; - var c2 = 0.0; - - for (int k = 1; k < 3; k++) + /// + /// Calculate longitude, latitude, and distance of parabolic-orbit comet. + /// + /// + /// Original macro names: PcometLong, PcometLat, PcometDist + /// + /// Local civil time, hour part. + /// Local civil time, minutes part. + /// Local civil time, seconds part. + /// Daylight Savings offset. + /// Time zone correction, in hours. + /// Local date, day part. + /// Local date, month part. + /// Local date, year part. + /// Perihelion epoch (day) + /// Perihelion epoch (month) + /// Perihelion epoch (year) + /// a (AU) + /// Inclination (degrees) + /// Perihelion (degrees) + /// Node (degrees) + /// + /// cometLongDeg -- Comet longitude (degrees) + /// cometLatDeg -- Comet lat (degrees) + /// cometDistAU -- Comet distance from Earth (AU) + /// + public static (double cometLongDeg, double cometLatDeg, double cometDistAU) PCometLongLatDist(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr, double td, int tm, int ty, double q, double i, double p, double n) + { + var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); + var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); + var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); + var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); + var tpe = (ut / 365.242191) + CivilDateToJulianDate(gd, gm, gy) - CivilDateToJulianDate(td, tm, ty); + var lg = (SunLong(lh, lm, ls, ds, zc, dy, mn, yr) + 180.0).ToRadians(); + var re = SunDist(lh, lm, ls, ds, zc, dy, mn, yr); + + var rh2 = 0.0; + var rd = 0.0; + var s3 = 0.0; + var c3 = 0.0; + var lc = 0.0; + var s2 = 0.0; + var c2 = 0.0; + + for (int k = 1; k < 3; k++) + { + var s = SolveCubic(0.0364911624 * tpe / (q * (q).SquareRoot())); + var nu = 2.0 * s.AngleTangent(); + var r = q * (1.0 + s * s); + var l = nu + p.ToRadians(); + var s1 = l.Sine(); + var c1 = l.Cosine(); + var i1 = i.ToRadians(); + s2 = s1 * i1.Sine(); + var ps = s2.ASine(); + var y = s1 * i1.Cosine(); + lc = y.AngleTangent2(c1) + n.ToRadians(); + c2 = ps.Cosine(); + rd = r * c2; + var ll = lc - lg; + c3 = ll.Cosine(); + s3 = ll.Sine(); + var rh = ((re * re) + (r * r) - (2.0 * re * rd * c3 * (ps).Cosine())).SquareRoot(); + if (k == 1) { - var s = SolveCubic(0.0364911624 * tpe / (q * (q).SquareRoot())); - var nu = 2.0 * s.AngleTangent(); - var r = q * (1.0 + s * s); - var l = nu + p.ToRadians(); - var s1 = l.Sine(); - var c1 = l.Cosine(); - var i1 = i.ToRadians(); - s2 = s1 * i1.Sine(); - var ps = s2.ASine(); - var y = s1 * i1.Cosine(); - lc = y.AngleTangent2(c1) + n.ToRadians(); - c2 = ps.Cosine(); - rd = r * c2; - var ll = lc - lg; - c3 = ll.Cosine(); - s3 = ll.Sine(); - var rh = ((re * re) + (r * r) - (2.0 * re * rd * c3 * (ps).Cosine())).SquareRoot(); - if (k == 1) - { - rh2 = ((re * re) + (r * r) - (2.0 * re * r * (ps).Cosine() * (l + (n).ToRadians() - lg).Cosine())).SquareRoot(); - } + rh2 = ((re * re) + (r * r) - (2.0 * re * r * (ps).Cosine() * (l + (n).ToRadians() - lg).Cosine())).SquareRoot(); } + } - double ep; + double ep; - ep = (rd < re) ? ((-rd * s3) / (re - (rd * c3))).AngleTangent() + lg + 3.141592654 : ((re * s3) / (rd - (re * c3))).AngleTangent() + lc; - ep = Unwind(ep); + ep = (rd < re) ? ((-rd * s3) / (re - (rd * c3))).AngleTangent() + lg + 3.141592654 : ((re * s3) / (rd - (re * c3))).AngleTangent() + lc; + ep = Unwind(ep); - var tb = (rd * s2 * (ep - lc).Sine()) / (c2 * re * s3); - var bp = tb.AngleTangent(); + var tb = (rd * s2 * (ep - lc).Sine()) / (c2 * re * s3); + var bp = tb.AngleTangent(); - var cometLongDeg = Degrees(ep); - var cometLatDeg = Degrees(bp); - var cometDistAU = rh2; + var cometLongDeg = Degrees(ep); + var cometLatDeg = Degrees(bp); + var cometDistAU = rh2; - return (cometLongDeg, cometLatDeg, cometDistAU); - } + return (cometLongDeg, cometLatDeg, cometDistAU); + } - /// - /// Calculate longitude, latitude, and horizontal parallax of the Moon. - /// - /// - /// Original macro names: MoonLong, MoonLat, MoonHP - /// - /// Local civil time, hour part. - /// Local civil time, minutes part. - /// Local civil time, seconds part. - /// Daylight Savings offset. - /// Time zone correction, in hours. - /// Local date, day part. - /// Local date, month part. - /// Local date, year part. - /// - /// moonLongDeg -- Moon longitude (degrees) - /// moonLatDeg -- Moon latitude (degrees) - /// moonHorPara -- Moon horizontal parallax (degrees) - /// - public static (double moonLongDeg, double moonLatDeg, double moonHorPara) MoonLongLatHP(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); - var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); - var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); - var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); - var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020.0) / 36525.0) + (ut / 876600.0); - var t2 = t * t; - - var m1 = 27.32158213; - var m2 = 365.2596407; - var m3 = 27.55455094; - var m4 = 29.53058868; - var m5 = 27.21222039; - var m6 = 6798.363307; - var q = CivilDateToJulianDate(gd, gm, gy) - 2415020.0 + (ut / 24.0); - m1 = q / m1; - m2 = q / m2; - m3 = q / m3; - m4 = q / m4; - m5 = q / m5; - m6 = q / m6; - m1 = 360.0 * (m1 - m1.Floor()); - m2 = 360.0 * (m2 - m2.Floor()); - m3 = 360.0 * (m3 - m3.Floor()); - m4 = 360.0 * (m4 - m4.Floor()); - m5 = 360.0 * (m5 - m5.Floor()); - m6 = 360.0 * (m6 - m6.Floor()); - - var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; - var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; - var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; - var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; - var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; - var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; - var a = (51.2 + 20.2 * t).ToRadians(); - var s1 = a.Sine(); - var s2 = na.ToRadians().Sine(); - var b = 346.56 + (132.87 - 0.0091731 * t) * t; - var s3 = 0.003964 * b.ToRadians().Sine(); - var c = (na + 275.05 - 2.3 * t).ToRadians(); - var s4 = c.Sine(); - ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; - ms = ms - 0.001778 * s1; - md = md + 0.000817 * s1 + s3 + 0.002541 * s2; - mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; - me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; - var e = 1.0 - (0.002495 + 0.00000752 * t) * t; - var e2 = e * e; - ml = ml.ToRadians(); - ms = ms.ToRadians(); - na = na.ToRadians(); - me1 = me1.ToRadians(); - mf = mf.ToRadians(); - md = md.ToRadians(); - - // Longitude-specific - var l = 6.28875 * md.Sine() + 1.274018 * (2.0 * me1 - md).Sine(); - l = l + 0.658309 * (2.0 * me1).Sine() + 0.213616 * (2.0 * md).Sine(); - l = l - e * 0.185596 * ms.Sine() - 0.114336 * (2.0 * mf).Sine(); - l = l + 0.058793 * (2.0 * (me1 - md)).Sine(); - l = l + 0.057212 * e * (2.0 * me1 - ms - md).Sine() + 0.05332 * (2.0 * me1 + md).Sine(); - l = l + 0.045874 * e * (2.0 * me1 - ms).Sine() + 0.041024 * e * (md - ms).Sine(); - l = l - 0.034718 * me1.Sine() - e * 0.030465 * (ms + md).Sine(); - l = l + 0.015326 * (2.0 * (me1 - mf)).Sine() - 0.012528 * (2.0 * mf + md).Sine(); - l = l - 0.01098 * (2.0 * mf - md).Sine() + 0.010674 * (4.0 * me1 - md).Sine(); - l = l + 0.010034 * (3.0 * md).Sine() + 0.008548 * (4.0 * me1 - 2.0 * md).Sine(); - l = l - e * 0.00791 * (ms - md + 2.0 * me1).Sine() - e * 0.006783 * (2.0 * me1 + ms).Sine(); - l = l + 0.005162 * (md - me1).Sine() + e * 0.005 * (ms + me1).Sine(); - l = l + 0.003862 * (4.0 * me1).Sine() + e * 0.004049 * (md - ms + 2.0 * me1).Sine(); - l = l + 0.003996 * (2.0 * (md + me1)).Sine() + 0.003665 * (2.0 * me1 - 3.0 * md).Sine(); - l = l + e * 0.002695 * (2.0 * md - ms).Sine() + 0.002602 * (md - 2.0 * (mf + me1)).Sine(); - l = l + e * 0.002396 * (2.0 * (me1 - md) - ms).Sine() - 0.002349 * (md + me1).Sine(); - l = l + e2 * 0.002249 * (2.0 * (me1 - ms)).Sine() - e * 0.002125 * (2.0 * md + ms).Sine(); - l = l - e2 * 0.002079 * (2.0 * ms).Sine() + e2 * 0.002059 * (2.0 * (me1 - ms) - md).Sine(); - l = l - 0.001773 * (md + 2.0 * (me1 - mf)).Sine() - 0.001595 * (2.0 * (mf + me1)).Sine(); - l = l + e * 0.00122 * (4.0 * me1 - ms - md).Sine() - 0.00111 * (2.0 * (md + mf)).Sine(); - l = l + 0.000892 * (md - 3.0 * me1).Sine() - e * 0.000811 * (ms + md + 2.0 * me1).Sine(); - l = l + e * 0.000761 * (4.0 * me1 - ms - 2.0 * md).Sine(); - l = l + e2 * 0.000704 * (md - 2.0 * (ms + me1)).Sine(); - l = l + e * 0.000693 * (ms - 2.0 * (md - me1)).Sine(); - l = l + e * 0.000598 * (2.0 * (me1 - mf) - ms).Sine(); - l = l + 0.00055 * (md + 4.0 * me1).Sine() + 0.000538 * (4.0 * md).Sine(); - l = l + e * 0.000521 * (4.0 * me1 - ms).Sine() + 0.000486 * (2.0 * md - me1).Sine(); - l = l + e2 * 0.000717 * (md - 2.0 * ms).Sine(); - var mm = Unwind(ml + l.ToRadians()); - - // Latitude-specific - var g = 5.128189 * mf.Sine() + 0.280606 * (md + mf).Sine(); - g = g + 0.277693 * (md - mf).Sine() + 0.173238 * (2.0 * me1 - mf).Sine(); - g = g + 0.055413 * (2.0 * me1 + mf - md).Sine() + 0.046272 * (2.0 * me1 - mf - md).Sine(); - g = g + 0.032573 * (2.0 * me1 + mf).Sine() + 0.017198 * (2.0 * md + mf).Sine(); - g = g + 0.009267 * (2.0 * me1 + md - mf).Sine() + 0.008823 * (2.0 * md - mf).Sine(); - g = g + e * 0.008247 * (2.0 * me1 - ms - mf).Sine() + 0.004323 * (2.0 * (me1 - md) - mf).Sine(); - g = g + 0.0042 * (2.0 * me1 + mf + md).Sine() + e * 0.003372 * (mf - ms - 2.0 * me1).Sine(); - g = g + e * 0.002472 * (2.0 * me1 + mf - ms - md).Sine(); - g = g + e * 0.002222 * (2.0 * me1 + mf - ms).Sine(); - g = g + e * 0.002072 * (2.0 * me1 - mf - ms - md).Sine(); - g = g + e * 0.001877 * (mf - ms + md).Sine() + 0.001828 * (4.0 * me1 - mf - md).Sine(); - g = g - e * 0.001803 * (mf + ms).Sine() - 0.00175 * (3.0 * mf).Sine(); - g = g + e * 0.00157 * (md - ms - mf).Sine() - 0.001487 * (mf + me1).Sine(); - g = g - e * 0.001481 * (mf + ms + md).Sine() + e * 0.001417 * (mf - ms - md).Sine(); - g = g + e * 0.00135 * (mf - ms).Sine() + 0.00133 * (mf - me1).Sine(); - g = g + 0.001106 * (mf + 3.0 * md).Sine() + 0.00102 * (4.0 * me1 - mf).Sine(); - g = g + 0.000833 * (mf + 4.0 * me1 - md).Sine() + 0.000781 * (md - 3.0 * mf).Sine(); - g = g + 0.00067 * (mf + 4.0 * me1 - 2.0 * md).Sine() + 0.000606 * (2.0 * me1 - 3.0 * mf).Sine(); - g = g + 0.000597 * (2.0 * (me1 + md) - mf).Sine(); - g = g + e * 0.000492 * (2.0 * me1 + md - ms - mf).Sine() + 0.00045 * (2.0 * (md - me1) - mf).Sine(); - g = g + 0.000439 * (3.0 * md - mf).Sine() + 0.000423 * (mf + 2.0 * (me1 + md)).Sine(); - g = g + 0.000422 * (2.0 * me1 - mf - 3.0 * md).Sine() - e * 0.000367 * (ms + mf + 2.0 * me1 - md).Sine(); - g = g - e * 0.000353 * (ms + mf + 2.0 * me1).Sine() + 0.000331 * (mf + 4.0 * me1).Sine(); - g = g + e * 0.000317 * (2.0 * me1 + mf - ms + md).Sine(); - g = g + e2 * 0.000306 * (2.0 * (me1 - ms) - mf).Sine() - 0.000283 * (md + 3.0 * mf).Sine(); - var w1 = 0.0004664 * na.Cosine(); - var w2 = 0.0000754 * c.Cosine(); - var bm = g.ToRadians() * (1.0 - w1 - w2); - - // Horizontal parallax-specific - var pm = 0.950724 + 0.051818 * md.Cosine() + 0.009531 * (2.0 * me1 - md).Cosine(); - pm = pm + 0.007843 * (2.0 * me1).Cosine() + 0.002824 * (2.0 * md).Cosine(); - pm = pm + 0.000857 * (2.0 * me1 + md).Cosine() + e * 0.000533 * (2.0 * me1 - ms).Cosine(); - pm = pm + e * 0.000401 * (2.0 * me1 - md - ms).Cosine(); - pm = pm + e * 0.00032 * (md - ms).Cosine() - 0.000271 * me1.Cosine(); - pm = pm - e * 0.000264 * (ms + md).Cosine() - 0.000198 * (2.0 * mf - md).Cosine(); - pm = pm + 0.000173 * (3.0 * md).Cosine() + 0.000167 * (4.0 * me1 - md).Cosine(); - pm = pm - e * 0.000111 * ms.Cosine() + 0.000103 * (4.0 * me1 - 2.0 * md).Cosine(); - pm = pm - 0.000084 * (2.0 * md - 2.0 * me1).Cosine() - e * 0.000083 * (2.0 * me1 + ms).Cosine(); - pm = pm + 0.000079 * (2.0 * me1 + 2.0 * md).Cosine() + 0.000072 * (4.0 * me1).Cosine(); - pm = pm + e * 0.000064 * (2.0 * me1 - ms + md).Cosine() - e * 0.000063 * (2.0 * me1 + ms - md).Cosine(); - pm = pm + e * 0.000041 * (ms + me1).Cosine() + e * 0.000035 * (2.0 * md - ms).Cosine(); - pm = pm - 0.000033 * (3.0 * md - 2.0 * me1).Cosine() - 0.00003 * (md + me1).Cosine(); - pm = pm - 0.000029 * (2.0 * (mf - me1)).Cosine() - e * 0.000029 * (2.0 * md + ms).Cosine(); - pm = pm + e2 * 0.000026 * (2.0 * (me1 - ms)).Cosine() - 0.000023 * (2.0 * (mf - me1) + md).Cosine(); - pm = pm + e * 0.000019 * (4.0 * me1 - ms - md).Cosine(); - - var moonLongDeg = Degrees(mm); - var moonLatDeg = Degrees(bm); - var moonHorPara = pm; - - return (moonLongDeg, moonLatDeg, moonHorPara); - } + /// + /// Calculate longitude, latitude, and horizontal parallax of the Moon. + /// + /// + /// Original macro names: MoonLong, MoonLat, MoonHP + /// + /// Local civil time, hour part. + /// Local civil time, minutes part. + /// Local civil time, seconds part. + /// Daylight Savings offset. + /// Time zone correction, in hours. + /// Local date, day part. + /// Local date, month part. + /// Local date, year part. + /// + /// moonLongDeg -- Moon longitude (degrees) + /// moonLatDeg -- Moon latitude (degrees) + /// moonHorPara -- Moon horizontal parallax (degrees) + /// + public static (double moonLongDeg, double moonLatDeg, double moonHorPara) MoonLongLatHP(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); + var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); + var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); + var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); + var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020.0) / 36525.0) + (ut / 876600.0); + var t2 = t * t; + + var m1 = 27.32158213; + var m2 = 365.2596407; + var m3 = 27.55455094; + var m4 = 29.53058868; + var m5 = 27.21222039; + var m6 = 6798.363307; + var q = CivilDateToJulianDate(gd, gm, gy) - 2415020.0 + (ut / 24.0); + m1 = q / m1; + m2 = q / m2; + m3 = q / m3; + m4 = q / m4; + m5 = q / m5; + m6 = q / m6; + m1 = 360.0 * (m1 - m1.Floor()); + m2 = 360.0 * (m2 - m2.Floor()); + m3 = 360.0 * (m3 - m3.Floor()); + m4 = 360.0 * (m4 - m4.Floor()); + m5 = 360.0 * (m5 - m5.Floor()); + m6 = 360.0 * (m6 - m6.Floor()); + + var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; + var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; + var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; + var me1 = 350.737486 + m4 - (0.001436 - 0.0000019 * t) * t2; + var mf = 11.250889 + m5 - (0.003211 + 0.0000003 * t) * t2; + var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; + var a = (51.2 + 20.2 * t).ToRadians(); + var s1 = a.Sine(); + var s2 = na.ToRadians().Sine(); + var b = 346.56 + (132.87 - 0.0091731 * t) * t; + var s3 = 0.003964 * b.ToRadians().Sine(); + var c = (na + 275.05 - 2.3 * t).ToRadians(); + var s4 = c.Sine(); + ml = ml + 0.000233 * s1 + s3 + 0.001964 * s2; + ms = ms - 0.001778 * s1; + md = md + 0.000817 * s1 + s3 + 0.002541 * s2; + mf = mf + s3 - 0.024691 * s2 - 0.004328 * s4; + me1 = me1 + 0.002011 * s1 + s3 + 0.001964 * s2; + var e = 1.0 - (0.002495 + 0.00000752 * t) * t; + var e2 = e * e; + ml = ml.ToRadians(); + ms = ms.ToRadians(); + na = na.ToRadians(); + me1 = me1.ToRadians(); + mf = mf.ToRadians(); + md = md.ToRadians(); + + // Longitude-specific + var l = 6.28875 * md.Sine() + 1.274018 * (2.0 * me1 - md).Sine(); + l = l + 0.658309 * (2.0 * me1).Sine() + 0.213616 * (2.0 * md).Sine(); + l = l - e * 0.185596 * ms.Sine() - 0.114336 * (2.0 * mf).Sine(); + l = l + 0.058793 * (2.0 * (me1 - md)).Sine(); + l = l + 0.057212 * e * (2.0 * me1 - ms - md).Sine() + 0.05332 * (2.0 * me1 + md).Sine(); + l = l + 0.045874 * e * (2.0 * me1 - ms).Sine() + 0.041024 * e * (md - ms).Sine(); + l = l - 0.034718 * me1.Sine() - e * 0.030465 * (ms + md).Sine(); + l = l + 0.015326 * (2.0 * (me1 - mf)).Sine() - 0.012528 * (2.0 * mf + md).Sine(); + l = l - 0.01098 * (2.0 * mf - md).Sine() + 0.010674 * (4.0 * me1 - md).Sine(); + l = l + 0.010034 * (3.0 * md).Sine() + 0.008548 * (4.0 * me1 - 2.0 * md).Sine(); + l = l - e * 0.00791 * (ms - md + 2.0 * me1).Sine() - e * 0.006783 * (2.0 * me1 + ms).Sine(); + l = l + 0.005162 * (md - me1).Sine() + e * 0.005 * (ms + me1).Sine(); + l = l + 0.003862 * (4.0 * me1).Sine() + e * 0.004049 * (md - ms + 2.0 * me1).Sine(); + l = l + 0.003996 * (2.0 * (md + me1)).Sine() + 0.003665 * (2.0 * me1 - 3.0 * md).Sine(); + l = l + e * 0.002695 * (2.0 * md - ms).Sine() + 0.002602 * (md - 2.0 * (mf + me1)).Sine(); + l = l + e * 0.002396 * (2.0 * (me1 - md) - ms).Sine() - 0.002349 * (md + me1).Sine(); + l = l + e2 * 0.002249 * (2.0 * (me1 - ms)).Sine() - e * 0.002125 * (2.0 * md + ms).Sine(); + l = l - e2 * 0.002079 * (2.0 * ms).Sine() + e2 * 0.002059 * (2.0 * (me1 - ms) - md).Sine(); + l = l - 0.001773 * (md + 2.0 * (me1 - mf)).Sine() - 0.001595 * (2.0 * (mf + me1)).Sine(); + l = l + e * 0.00122 * (4.0 * me1 - ms - md).Sine() - 0.00111 * (2.0 * (md + mf)).Sine(); + l = l + 0.000892 * (md - 3.0 * me1).Sine() - e * 0.000811 * (ms + md + 2.0 * me1).Sine(); + l = l + e * 0.000761 * (4.0 * me1 - ms - 2.0 * md).Sine(); + l = l + e2 * 0.000704 * (md - 2.0 * (ms + me1)).Sine(); + l = l + e * 0.000693 * (ms - 2.0 * (md - me1)).Sine(); + l = l + e * 0.000598 * (2.0 * (me1 - mf) - ms).Sine(); + l = l + 0.00055 * (md + 4.0 * me1).Sine() + 0.000538 * (4.0 * md).Sine(); + l = l + e * 0.000521 * (4.0 * me1 - ms).Sine() + 0.000486 * (2.0 * md - me1).Sine(); + l = l + e2 * 0.000717 * (md - 2.0 * ms).Sine(); + var mm = Unwind(ml + l.ToRadians()); + + // Latitude-specific + var g = 5.128189 * mf.Sine() + 0.280606 * (md + mf).Sine(); + g = g + 0.277693 * (md - mf).Sine() + 0.173238 * (2.0 * me1 - mf).Sine(); + g = g + 0.055413 * (2.0 * me1 + mf - md).Sine() + 0.046272 * (2.0 * me1 - mf - md).Sine(); + g = g + 0.032573 * (2.0 * me1 + mf).Sine() + 0.017198 * (2.0 * md + mf).Sine(); + g = g + 0.009267 * (2.0 * me1 + md - mf).Sine() + 0.008823 * (2.0 * md - mf).Sine(); + g = g + e * 0.008247 * (2.0 * me1 - ms - mf).Sine() + 0.004323 * (2.0 * (me1 - md) - mf).Sine(); + g = g + 0.0042 * (2.0 * me1 + mf + md).Sine() + e * 0.003372 * (mf - ms - 2.0 * me1).Sine(); + g = g + e * 0.002472 * (2.0 * me1 + mf - ms - md).Sine(); + g = g + e * 0.002222 * (2.0 * me1 + mf - ms).Sine(); + g = g + e * 0.002072 * (2.0 * me1 - mf - ms - md).Sine(); + g = g + e * 0.001877 * (mf - ms + md).Sine() + 0.001828 * (4.0 * me1 - mf - md).Sine(); + g = g - e * 0.001803 * (mf + ms).Sine() - 0.00175 * (3.0 * mf).Sine(); + g = g + e * 0.00157 * (md - ms - mf).Sine() - 0.001487 * (mf + me1).Sine(); + g = g - e * 0.001481 * (mf + ms + md).Sine() + e * 0.001417 * (mf - ms - md).Sine(); + g = g + e * 0.00135 * (mf - ms).Sine() + 0.00133 * (mf - me1).Sine(); + g = g + 0.001106 * (mf + 3.0 * md).Sine() + 0.00102 * (4.0 * me1 - mf).Sine(); + g = g + 0.000833 * (mf + 4.0 * me1 - md).Sine() + 0.000781 * (md - 3.0 * mf).Sine(); + g = g + 0.00067 * (mf + 4.0 * me1 - 2.0 * md).Sine() + 0.000606 * (2.0 * me1 - 3.0 * mf).Sine(); + g = g + 0.000597 * (2.0 * (me1 + md) - mf).Sine(); + g = g + e * 0.000492 * (2.0 * me1 + md - ms - mf).Sine() + 0.00045 * (2.0 * (md - me1) - mf).Sine(); + g = g + 0.000439 * (3.0 * md - mf).Sine() + 0.000423 * (mf + 2.0 * (me1 + md)).Sine(); + g = g + 0.000422 * (2.0 * me1 - mf - 3.0 * md).Sine() - e * 0.000367 * (ms + mf + 2.0 * me1 - md).Sine(); + g = g - e * 0.000353 * (ms + mf + 2.0 * me1).Sine() + 0.000331 * (mf + 4.0 * me1).Sine(); + g = g + e * 0.000317 * (2.0 * me1 + mf - ms + md).Sine(); + g = g + e2 * 0.000306 * (2.0 * (me1 - ms) - mf).Sine() - 0.000283 * (md + 3.0 * mf).Sine(); + var w1 = 0.0004664 * na.Cosine(); + var w2 = 0.0000754 * c.Cosine(); + var bm = g.ToRadians() * (1.0 - w1 - w2); + + // Horizontal parallax-specific + var pm = 0.950724 + 0.051818 * md.Cosine() + 0.009531 * (2.0 * me1 - md).Cosine(); + pm = pm + 0.007843 * (2.0 * me1).Cosine() + 0.002824 * (2.0 * md).Cosine(); + pm = pm + 0.000857 * (2.0 * me1 + md).Cosine() + e * 0.000533 * (2.0 * me1 - ms).Cosine(); + pm = pm + e * 0.000401 * (2.0 * me1 - md - ms).Cosine(); + pm = pm + e * 0.00032 * (md - ms).Cosine() - 0.000271 * me1.Cosine(); + pm = pm - e * 0.000264 * (ms + md).Cosine() - 0.000198 * (2.0 * mf - md).Cosine(); + pm = pm + 0.000173 * (3.0 * md).Cosine() + 0.000167 * (4.0 * me1 - md).Cosine(); + pm = pm - e * 0.000111 * ms.Cosine() + 0.000103 * (4.0 * me1 - 2.0 * md).Cosine(); + pm = pm - 0.000084 * (2.0 * md - 2.0 * me1).Cosine() - e * 0.000083 * (2.0 * me1 + ms).Cosine(); + pm = pm + 0.000079 * (2.0 * me1 + 2.0 * md).Cosine() + 0.000072 * (4.0 * me1).Cosine(); + pm = pm + e * 0.000064 * (2.0 * me1 - ms + md).Cosine() - e * 0.000063 * (2.0 * me1 + ms - md).Cosine(); + pm = pm + e * 0.000041 * (ms + me1).Cosine() + e * 0.000035 * (2.0 * md - ms).Cosine(); + pm = pm - 0.000033 * (3.0 * md - 2.0 * me1).Cosine() - 0.00003 * (md + me1).Cosine(); + pm = pm - 0.000029 * (2.0 * (mf - me1)).Cosine() - e * 0.000029 * (2.0 * md + ms).Cosine(); + pm = pm + e2 * 0.000026 * (2.0 * (me1 - ms)).Cosine() - 0.000023 * (2.0 * (mf - me1) + md).Cosine(); + pm = pm + e * 0.000019 * (4.0 * me1 - ms - md).Cosine(); + + var moonLongDeg = Degrees(mm); + var moonLatDeg = Degrees(bm); + var moonHorPara = pm; + + return (moonLongDeg, moonLatDeg, moonHorPara); + } - /// - /// Calculate current phase of Moon. - /// - /// - /// Original macro name: MoonPhase - /// - public static double MoonPhase(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var moonResult = MoonLongLatHP(lh, lm, ls, ds, zc, dy, mn, yr); + /// + /// Calculate current phase of Moon. + /// + /// + /// Original macro name: MoonPhase + /// + public static double MoonPhase(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var moonResult = MoonLongLatHP(lh, lm, ls, ds, zc, dy, mn, yr); - var cd = ((moonResult.moonLongDeg - SunLong(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians()).Cosine() * ((moonResult.moonLatDeg).ToRadians()).Cosine(); - var d = cd.ACosine(); - var sd = d.Sine(); - var i = 0.1468 * sd * (1.0 - 0.0549 * (MoonMeanAnomaly(lh, lm, ls, ds, zc, dy, mn, yr)).Sine()); - i = i / (1.0 - 0.0167 * (SunMeanAnomaly(lh, lm, ls, ds, zc, dy, mn, yr)).Sine()); - i = 3.141592654 - d - i.ToRadians(); - var k = (1.0 + (i).Cosine()) / 2.0; + var cd = ((moonResult.moonLongDeg - SunLong(lh, lm, ls, ds, zc, dy, mn, yr)).ToRadians()).Cosine() * ((moonResult.moonLatDeg).ToRadians()).Cosine(); + var d = cd.ACosine(); + var sd = d.Sine(); + var i = 0.1468 * sd * (1.0 - 0.0549 * (MoonMeanAnomaly(lh, lm, ls, ds, zc, dy, mn, yr)).Sine()); + i = i / (1.0 - 0.0167 * (SunMeanAnomaly(lh, lm, ls, ds, zc, dy, mn, yr)).Sine()); + i = 3.141592654 - d - i.ToRadians(); + var k = (1.0 + (i).Cosine()) / 2.0; - return Math.Round(k, 2); - } + return Math.Round(k, 2); + } - /// - /// Calculate the Moon's mean anomaly. - /// - /// - /// Original macro name: MoonMeanAnomaly - /// - public static double MoonMeanAnomaly(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) - { - var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); - var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); - var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); - var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); - var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020.0) / 36525.0) + (ut / 876600.0); - var t2 = t * t; - - var m1 = 27.32158213; - var m2 = 365.2596407; - var m3 = 27.55455094; - var m4 = 29.53058868; - var m5 = 27.21222039; - var m6 = 6798.363307; - var q = CivilDateToJulianDate(gd, gm, gy) - 2415020.0 + (ut / 24.0); - m1 = q / m1; - m2 = q / m2; - m3 = q / m3; - m4 = q / m4; - m5 = q / m5; - m6 = q / m6; - m1 = 360.0 * (m1 - m1.Floor()); - m2 = 360.0 * (m2 - m2.Floor()); - m3 = 360.0 * (m3 - m3.Floor()); - m4 = 360.0 * (m4 - m4.Floor()); - m5 = 360.0 * (m5 - m5.Floor()); - m6 = 360.0 * (m6 - m6.Floor()); - - var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; - var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; - var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; - var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; - var a = (51.2 + 20.2 * t).ToRadians(); - var s1 = a.Sine(); - var s2 = na.ToRadians().Sine(); - var b = 346.56 + (132.87 - 0.0091731 * t) * t; - var s3 = 0.003964 * b.ToRadians().Sine(); - var c = (na + 275.05 - 2.3 * t).ToRadians(); - md = md + 0.000817 * s1 + s3 + 0.002541 * s2; - - return md.ToRadians(); - } + /// + /// Calculate the Moon's mean anomaly. + /// + /// + /// Original macro name: MoonMeanAnomaly + /// + public static double MoonMeanAnomaly(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr) + { + var ut = LocalCivilTimeToUniversalTime(lh, lm, ls, ds, zc, dy, mn, yr); + var gd = LocalCivilTimeGreenwichDay(lh, lm, ls, ds, zc, dy, mn, yr); + var gm = LocalCivilTimeGreenwichMonth(lh, lm, ls, ds, zc, dy, mn, yr); + var gy = LocalCivilTimeGreenwichYear(lh, lm, ls, ds, zc, dy, mn, yr); + var t = ((CivilDateToJulianDate(gd, gm, gy) - 2415020.0) / 36525.0) + (ut / 876600.0); + var t2 = t * t; + + var m1 = 27.32158213; + var m2 = 365.2596407; + var m3 = 27.55455094; + var m4 = 29.53058868; + var m5 = 27.21222039; + var m6 = 6798.363307; + var q = CivilDateToJulianDate(gd, gm, gy) - 2415020.0 + (ut / 24.0); + m1 = q / m1; + m2 = q / m2; + m3 = q / m3; + m4 = q / m4; + m5 = q / m5; + m6 = q / m6; + m1 = 360.0 * (m1 - m1.Floor()); + m2 = 360.0 * (m2 - m2.Floor()); + m3 = 360.0 * (m3 - m3.Floor()); + m4 = 360.0 * (m4 - m4.Floor()); + m5 = 360.0 * (m5 - m5.Floor()); + m6 = 360.0 * (m6 - m6.Floor()); + + var ml = 270.434164 + m1 - (0.001133 - 0.0000019 * t) * t2; + var ms = 358.475833 + m2 - (0.00015 + 0.0000033 * t) * t2; + var md = 296.104608 + m3 + (0.009192 + 0.0000144 * t) * t2; + var na = 259.183275 - m6 + (0.002078 + 0.0000022 * t) * t2; + var a = (51.2 + 20.2 * t).ToRadians(); + var s1 = a.Sine(); + var s2 = na.ToRadians().Sine(); + var b = 346.56 + (132.87 - 0.0091731 * t) * t; + var s3 = 0.003964 * b.ToRadians().Sine(); + var c = (na + 275.05 - 2.3 * t).ToRadians(); + md = md + 0.000817 * s1 + s3 + 0.002541 * s2; + + return md.ToRadians(); + } - /// - /// Calculate Julian date of New Moon. - /// - /// - /// Original macro name: NewMoon - /// - /// Daylight Savings offset. - /// Time zone correction, in hours. - /// Local date, day part. - /// Local date, month part. - /// Local date, year part. - public static double NewMoon(int ds, int zc, double dy, int mn, int yr) - { - var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - - var j0 = CivilDateToJulianDate(0.0, 1, y0) - 2415020.0; - var dj = CivilDateToJulianDate(d0, m0, y0) - 2415020.0; - var k = Lint(((y0 - 1900.0 + ((dj - j0) / 365.0)) * 12.3685) + 0.5); - var tn = k / 1236.85; - var tf = (k + 0.5) / 1236.85; - var t = tn; - var nmfmResult1 = NewMoonFullMoon_L6855(k, t); - var ni = nmfmResult1.a; - var nf = nmfmResult1.b; - t = tf; - k = k + 0.5; - var nmfmResult2 = NewMoonFullMoon_L6855(k, t); - - return ni + 2415020.0 + nf; - } + /// + /// Calculate Julian date of New Moon. + /// + /// + /// Original macro name: NewMoon + /// + /// Daylight Savings offset. + /// Time zone correction, in hours. + /// Local date, day part. + /// Local date, month part. + /// Local date, year part. + public static double NewMoon(int ds, int zc, double dy, int mn, int yr) + { + var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + + var j0 = CivilDateToJulianDate(0.0, 1, y0) - 2415020.0; + var dj = CivilDateToJulianDate(d0, m0, y0) - 2415020.0; + var k = Lint(((y0 - 1900.0 + ((dj - j0) / 365.0)) * 12.3685) + 0.5); + var tn = k / 1236.85; + var tf = (k + 0.5) / 1236.85; + var t = tn; + var nmfmResult1 = NewMoonFullMoon_L6855(k, t); + var ni = nmfmResult1.a; + var nf = nmfmResult1.b; + t = tf; + k = k + 0.5; + var nmfmResult2 = NewMoonFullMoon_L6855(k, t); + + return ni + 2415020.0 + nf; + } - /// - /// Calculate Julian date of Full Moon. - /// - /// - /// Original macro name: FullMoon - /// - /// Daylight Savings offset. - /// Time zone correction, in hours. - /// Local date, day part. - /// Local date, month part. - /// Local date, year part. - public static double FullMoon(int ds, int zc, double dy, int mn, int yr) - { - var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - - var j0 = CivilDateToJulianDate(0.0, 1, y0) - 2415020.0; - var dj = CivilDateToJulianDate(d0, m0, y0) - 2415020.0; - var k = Lint(((y0 - 1900.0 + ((dj - j0) / 365.0)) * 12.3685) + 0.5); - var tn = k / 1236.85; - var tf = (k + 0.5) / 1236.85; - var t = tn; - var nmfnResult1 = NewMoonFullMoon_L6855(k, t); - t = tf; - k = k + 0.5; - var nmfnResult2 = NewMoonFullMoon_L6855(k, t); - var fi = nmfnResult2.a; - var ff = nmfnResult2.b; - - return fi + 2415020.0 + ff; - } + /// + /// Calculate Julian date of Full Moon. + /// + /// + /// Original macro name: FullMoon + /// + /// Daylight Savings offset. + /// Time zone correction, in hours. + /// Local date, day part. + /// Local date, month part. + /// Local date, year part. + public static double FullMoon(int ds, int zc, double dy, int mn, int yr) + { + var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + + var j0 = CivilDateToJulianDate(0.0, 1, y0) - 2415020.0; + var dj = CivilDateToJulianDate(d0, m0, y0) - 2415020.0; + var k = Lint(((y0 - 1900.0 + ((dj - j0) / 365.0)) * 12.3685) + 0.5); + var tn = k / 1236.85; + var tf = (k + 0.5) / 1236.85; + var t = tn; + var nmfnResult1 = NewMoonFullMoon_L6855(k, t); + t = tf; + k = k + 0.5; + var nmfnResult2 = NewMoonFullMoon_L6855(k, t); + var fi = nmfnResult2.a; + var ff = nmfnResult2.b; + + return fi + 2415020.0 + ff; + } - /// - /// Helper function for new_moon() and full_moon() """ - /// - public static (double a, double b, double f) NewMoonFullMoon_L6855(double k, double t) - { - var t2 = t * t; - var e = 29.53 * k; - var c = 166.56 + (132.87 - 0.009173 * t) * t; - c = c.ToRadians(); - var b = 0.00058868 * k + (0.0001178 - 0.000000155 * t) * t2; - b = b + 0.00033 * c.Sine() + 0.75933; - var a = k / 12.36886; - var a1 = 359.2242 + 360.0 * Fract(a) - (0.0000333 + 0.00000347 * t) * t2; - var a2 = 306.0253 + 360.0 * Fract(k / 0.9330851); - a2 = a2 + (0.0107306 + 0.00001236 * t) * t2; - a = k / 0.9214926; - var f = 21.2964 + 360.0 * Fract(a) - (0.0016528 + 0.00000239 * t) * t2; - a1 = UnwindDeg(a1); - a2 = UnwindDeg(a2); - f = UnwindDeg(f); - a1 = a1.ToRadians(); - a2 = a2.ToRadians(); - f = f.ToRadians(); - - var dd = (0.1734 - 0.000393 * t) * a1.Sine() + 0.0021 * (2.0 * a1).Sine(); - dd = dd - 0.4068 * a2.Sine() + 0.0161 * (2.0 * a2).Sine() - 0.0004 * (3.0 * a2).Sine(); - dd = dd + 0.0104 * (2.0 * f).Sine() - 0.0051 * (a1 + a2).Sine(); - dd = dd - 0.0074 * (a1 - a2).Sine() + 0.0004 * (2.0 * f + a1).Sine(); - dd = dd - 0.0004 * (2.0 * f - a1).Sine() - 0.0006 * (2.0 * f + a2).Sine() + 0.001 * (2.0 * f - a2).Sine(); - dd = dd + 0.0005 * (a1 + 2.0 * a2).Sine(); - var e1 = e.Floor(); - b = b + dd + (e - e1); - var b1 = b.Floor(); - a = e1 + b1; - b = b - b1; - - return (a, b, f); - } + /// + /// Helper function for new_moon() and full_moon() """ + /// + public static (double a, double b, double f) NewMoonFullMoon_L6855(double k, double t) + { + var t2 = t * t; + var e = 29.53 * k; + var c = 166.56 + (132.87 - 0.009173 * t) * t; + c = c.ToRadians(); + var b = 0.00058868 * k + (0.0001178 - 0.000000155 * t) * t2; + b = b + 0.00033 * c.Sine() + 0.75933; + var a = k / 12.36886; + var a1 = 359.2242 + 360.0 * Fract(a) - (0.0000333 + 0.00000347 * t) * t2; + var a2 = 306.0253 + 360.0 * Fract(k / 0.9330851); + a2 = a2 + (0.0107306 + 0.00001236 * t) * t2; + a = k / 0.9214926; + var f = 21.2964 + 360.0 * Fract(a) - (0.0016528 + 0.00000239 * t) * t2; + a1 = UnwindDeg(a1); + a2 = UnwindDeg(a2); + f = UnwindDeg(f); + a1 = a1.ToRadians(); + a2 = a2.ToRadians(); + f = f.ToRadians(); + + var dd = (0.1734 - 0.000393 * t) * a1.Sine() + 0.0021 * (2.0 * a1).Sine(); + dd = dd - 0.4068 * a2.Sine() + 0.0161 * (2.0 * a2).Sine() - 0.0004 * (3.0 * a2).Sine(); + dd = dd + 0.0104 * (2.0 * f).Sine() - 0.0051 * (a1 + a2).Sine(); + dd = dd - 0.0074 * (a1 - a2).Sine() + 0.0004 * (2.0 * f + a1).Sine(); + dd = dd - 0.0004 * (2.0 * f - a1).Sine() - 0.0006 * (2.0 * f + a2).Sine() + 0.001 * (2.0 * f - a2).Sine(); + dd = dd + 0.0005 * (a1 + 2.0 * a2).Sine(); + var e1 = e.Floor(); + b = b + dd + (e - e1); + var b1 = b.Floor(); + a = e1 + b1; + b = b - b1; + + return (a, b, f); + } - /// - /// Original macro name: FRACT - /// - public static double Fract(double w) - { - return w - Lint(w); - } + /// + /// Original macro name: FRACT + /// + public static double Fract(double w) + { + return w - Lint(w); + } - /// - /// Original macro name: LINT - /// - public static double Lint(double w) - { - return IInt(w) + IInt(((1.0 * Sign(w)) - 1.0) / 2.0); - } + /// + /// Original macro name: LINT + /// + public static double Lint(double w) + { + return IInt(w) + IInt(((1.0 * Sign(w)) - 1.0) / 2.0); + } - /// - /// Original macro name: IINT - /// - public static double IInt(double w) - { - return Sign(w) * Math.Abs(w).Floor(); - } + /// + /// Original macro name: IINT + /// + public static double IInt(double w) + { + return Sign(w) * Math.Abs(w).Floor(); + } - /// - /// Calculate sign of number. - /// - /// Number to calculate the sign of. - /// signValue -- Sign value: -1, 0, or 1 - public static double Sign(double numberToCheck) - { - var signValue = 0.0; + /// + /// Calculate sign of number. + /// + /// Number to calculate the sign of. + /// signValue -- Sign value: -1, 0, or 1 + public static double Sign(double numberToCheck) + { + var signValue = 0.0; - if (numberToCheck < 0.0) - signValue = -1.0; + if (numberToCheck < 0.0) + signValue = -1.0; - if (numberToCheck > 0.0) - signValue = 1.0; + if (numberToCheck > 0.0) + signValue = 1.0; - return signValue; - } + return signValue; + } - /// - /// Original macro name: UTDayAdjust - /// - public static double UTDayAdjust(double ut, double g1) - { - var returnValue = ut; + /// + /// Original macro name: UTDayAdjust + /// + public static double UTDayAdjust(double ut, double g1) + { + var returnValue = ut; - if ((ut - g1) < -6.0) - returnValue = ut + 24.0; + if ((ut - g1) < -6.0) + returnValue = ut + 24.0; - if ((ut - g1) > 6.0) - returnValue = ut - 24.0; + if ((ut - g1) > 6.0) + returnValue = ut - 24.0; - return returnValue; - } + return returnValue; + } - /// - /// Original macro name: Fpart - /// - public static double FPart(double w) - { - return w - Lint(w); - } + /// + /// Original macro name: Fpart + /// + public static double FPart(double w) + { + return w - Lint(w); + } - /// - /// Original macro name: EQElat - /// - public static double EQELat(double rah, double ram, double ras, double dd, double dm, double ds, double gd, int gm, int gy) - { - var a = (DegreeHoursToDecimalDegrees(HMStoDH(rah, ram, ras))).ToRadians(); - var b = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var c = (Obliq(gd, gm, gy)).ToRadians(); - var d = b.Sine() * c.Cosine() - b.Cosine() * c.Sine() * a.Sine(); + /// + /// Original macro name: EQElat + /// + public static double EQELat(double rah, double ram, double ras, double dd, double dm, double ds, double gd, int gm, int gy) + { + var a = (DegreeHoursToDecimalDegrees(HMStoDH(rah, ram, ras))).ToRadians(); + var b = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var c = (Obliq(gd, gm, gy)).ToRadians(); + var d = b.Sine() * c.Cosine() - b.Cosine() * c.Sine() * a.Sine(); - return Degrees(d.ASine()); - } + return Degrees(d.ASine()); + } - /// - /// Original macro name: EQElong - /// - public static double EQELong(double rah, double ram, double ras, double dd, double dm, double ds, double gd, int gm, int gy) - { - var a = (DegreeHoursToDecimalDegrees(HMStoDH(rah, ram, ras))).ToRadians(); - var b = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); - var c = (Obliq(gd, gm, gy)).ToRadians(); - var d = a.Sine() * c.Cosine() + b.Tangent() * c.Sine(); - var e = a.Cosine(); - var f = Degrees(d.AngleTangent2(e)); - - return f - 360.0 * (f / 360.0).Floor(); - } + /// + /// Original macro name: EQElong + /// + public static double EQELong(double rah, double ram, double ras, double dd, double dm, double ds, double gd, int gm, int gy) + { + var a = (DegreeHoursToDecimalDegrees(HMStoDH(rah, ram, ras))).ToRadians(); + var b = (DegreesMinutesSecondsToDecimalDegrees(dd, dm, ds)).ToRadians(); + var c = (Obliq(gd, gm, gy)).ToRadians(); + var d = a.Sine() * c.Cosine() + b.Tangent() * c.Sine(); + var e = a.Cosine(); + var f = Degrees(d.AngleTangent2(e)); + + return f - 360.0 * (f / 360.0).Floor(); + } + + /// + /// Local time of moonrise. + /// + /// + /// Original macro name: MoonRiseLCT + /// + /// hours + public static double MoonRiseLCT(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) + { + var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var lct = 12.0; + var dy1 = dy; + var mn1 = mn; + var yr1 = yr; + + var lct6700result1 = MoonRiseLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + var lu = lct6700result1.lu; + lct = lct6700result1.lct; + + if (lct == -99.0) + return lct; + + var la = lu; - /// - /// Local time of moonrise. - /// - /// - /// Original macro name: MoonRiseLCT - /// - /// hours - public static double MoonRiseLCT(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) + double x; + double ut; + var g1 = 0.0; + var gu = 0.0; + + for (int k = 1; k < 9; k++) { - var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var lct = 12.0; - var dy1 = dy; - var mn1 = mn; - var yr1 = yr; - - var lct6700result1 = MoonRiseLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - var lu = lct6700result1.lu; - lct = lct6700result1.lct; + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + + g1 = (k == 1) ? ut : gu; + + gu = ut; + ut = gu; + + var lct6680result = MoonRiseLCT_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); + lct = lct6680result.lct; + dy1 = lct6680result.dy1; + mn1 = lct6680result.mn1; + yr1 = lct6680result.yr1; + gdy = lct6680result.gdy; + gmn = lct6680result.gmn; + gyr = lct6680result.gyr; + + var lct6700result2 = MoonRiseLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + lu = lct6700result2.lu; + lct = lct6700result2.lct; if (lct == -99.0) return lct; - var la = lu; + la = lu; + } + + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - double x; - double ut; - var g1 = 0.0; - var gu = 0.0; + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; - for (int k = 1; k < 9; k++) - { - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + ut = UTDayAdjust(ut, g1); + lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + + return lct; + } - g1 = (k == 1) ? ut : gu; + /// + /// Helper function for MoonRiseLCT + /// + public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonRiseLCT_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + { + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; + + ut = UTDayAdjust(ut, g1); + var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + ut = ut - 24.0 * (ut / 24.0).Floor(); + + return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); + } - gu = ut; - ut = gu; + /// + /// Helper function for MoonRiseLCT + /// + public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonRiseLCT_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) + { + var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); + var dp = NutatLong(gdy, gmn, gyr); + var th = 0.27249 * pm.Sine(); + var di = th + 0.0098902 - pm; + var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); + var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); + var lu = RiseSetLocalSiderealTimeRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + + if (!ERS(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat).Equals("OK")) + lct = -99.0; + + return (mm, bm, pm, dp, th, di, p, q, lu, lct); + } - var lct6680result = MoonRiseLCT_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); - lct = lct6680result.lct; - dy1 = lct6680result.dy1; - mn1 = lct6680result.mn1; - yr1 = lct6680result.yr1; - gdy = lct6680result.gdy; - gmn = lct6680result.gmn; - gyr = lct6680result.gyr; + /// + /// Local date of moonrise. + /// + /// + /// Original macro names: MoonRiseLcDay, MoonRiseLcMonth, MoonRiseLcYear + /// + /// + /// Local date (day) + /// Local date (month) + /// Local date (year) + /// + public static (double dy1, int mn1, int yr1) MoonRiseLcDMY(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) + { + var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var lct = 12.0; + var dy1 = dy; + var mn1 = mn; + var yr1 = yr; - var lct6700result2 = MoonRiseLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - lu = lct6700result2.lu; - lct = lct6700result2.lct; + var lct6700result1 = MoonRiseLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + var lu = lct6700result1.lu; + lct = lct6700result1.lct; - if (lct == -99.0) - return lct; + if (lct == -99.0) + return (lct, (int)lct, (int)lct); - la = lu; - } + var la = lu; + double x; + double ut; + var g1 = 0.0; + var gu = 0.0; + for (int k = 1; k < 9; k++) + { x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + g1 = (k == 1) ? ut : gu; - return lct; - } + gu = ut; + ut = gu; - /// - /// Helper function for MoonRiseLCT - /// - public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonRiseLCT_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) - { - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - ut = ut - 24.0 * (ut / 24.0).Floor(); - - return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); - } + var lct6680result1 = MoonRiseLcDMY_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); + lct = lct6680result1.lct; + dy1 = lct6680result1.dy1; + mn1 = lct6680result1.mn1; + yr1 = lct6680result1.yr1; + gdy = lct6680result1.gdy; + gmn = lct6680result1.gmn; + gyr = lct6680result1.gyr; - /// - /// Helper function for MoonRiseLCT - /// - public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonRiseLCT_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) - { - var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); - var dp = NutatLong(gdy, gmn, gyr); - var th = 0.27249 * pm.Sine(); - var di = th + 0.0098902 - pm; - var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); - var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); - var lu = RiseSetLocalSiderealTimeRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - - if (!ERS(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat).Equals("OK")) - lct = -99.0; - - return (mm, bm, pm, dp, th, di, p, q, lu, lct); - } + var lct6700result2 = MoonRiseLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - /// - /// Local date of moonrise. - /// - /// - /// Original macro names: MoonRiseLcDay, MoonRiseLcMonth, MoonRiseLcYear - /// - /// - /// Local date (day) - /// Local date (month) - /// Local date (year) - /// - public static (double dy1, int mn1, int yr1) MoonRiseLcDMY(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) - { - var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var lct = 12.0; - var dy1 = dy; - var mn1 = mn; - var yr1 = yr; - - var lct6700result1 = MoonRiseLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - var lu = lct6700result1.lu; - lct = lct6700result1.lct; + lu = lct6700result2.lu; + lct = lct6700result2.lct; if (lct == -99.0) return (lct, (int)lct, (int)lct); - var la = lu; + la = lu; + } - double x; - double ut; - var g1 = 0.0; - var gu = 0.0; - for (int k = 1; k < 9; k++) - { - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - g1 = (k == 1) ? ut : gu; + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; - gu = ut; - ut = gu; + ut = UTDayAdjust(ut, g1); + dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var lct6680result1 = MoonRiseLcDMY_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); - lct = lct6680result1.lct; - dy1 = lct6680result1.dy1; - mn1 = lct6680result1.mn1; - yr1 = lct6680result1.yr1; - gdy = lct6680result1.gdy; - gmn = lct6680result1.gmn; - gyr = lct6680result1.gyr; + return (dy1, mn1, yr1); + } - var lct6700result2 = MoonRiseLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + /// + /// Helper function for MoonRiseLcDMY + /// + public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonRiseLcDMY_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + { + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; + + ut = UTDayAdjust(ut, g1); + var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + ut = ut - 24.0 * (ut / 24.0).Floor(); + + return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); + } - lu = lct6700result2.lu; - lct = lct6700result2.lct; + /// + /// Helper function for MoonRiseLcDMY + /// + public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonRiseLcDMY_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) + { + var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); + var dp = NutatLong(gdy, gmn, gyr); + var th = 0.27249 * pm.Sine(); + var di = th + 0.0098902 - pm; + var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); + var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); + var lu = RiseSetLocalSiderealTimeRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + + return (mm, bm, pm, dp, th, di, p, q, lu, lct); + } - if (lct == -99.0) - return (lct, (int)lct, (int)lct); + /// + /// Local azimuth of moonrise. + /// + /// + /// Original macro name: MoonRiseAz + /// + /// degrees + public static double MoonRiseAz(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) + { + var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var lct = 12.0; + var dy1 = dy; + var mn1 = mn; + var yr1 = yr; + + var az6700result1 = MoonRiseAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + var lu = az6700result1.lu; + lct = az6700result1.lct; + double au; + + if (lct == -99.0) + return lct; - la = lu; - } + var la = lu; + double x; + double ut; + double g1; + var gu = 0.0; + var aa = 0.0; + for (int k = 1; k < 9; k++) + { x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - - return (dy1, mn1, yr1); - } + g1 = (k == 1) ? ut : gu; - /// - /// Helper function for MoonRiseLcDMY - /// - public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonRiseLcDMY_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) - { - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - ut = ut - 24.0 * (ut / 24.0).Floor(); - - return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); - } + gu = ut; + ut = gu; - /// - /// Helper function for MoonRiseLcDMY - /// - public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonRiseLcDMY_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) - { - var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); - var dp = NutatLong(gdy, gmn, gyr); - var th = 0.27249 * pm.Sine(); - var di = th + 0.0098902 - pm; - var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); - var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); - var lu = RiseSetLocalSiderealTimeRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - - return (mm, bm, pm, dp, th, di, p, q, lu, lct); - } + var az6680result1 = MoonRiseAz_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); + lct = az6680result1.lct; + dy1 = az6680result1.dy1; + mn1 = az6680result1.mn1; + yr1 = az6680result1.yr1; + gdy = az6680result1.gdy; + gmn = az6680result1.gmn; + gyr = az6680result1.gyr; - /// - /// Local azimuth of moonrise. - /// - /// - /// Original macro name: MoonRiseAz - /// - /// degrees - public static double MoonRiseAz(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) - { - var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var lct = 12.0; - var dy1 = dy; - var mn1 = mn; - var yr1 = yr; - - var az6700result1 = MoonRiseAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - var lu = az6700result1.lu; - lct = az6700result1.lct; - double au; + var az6700result2 = MoonRiseAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + lu = az6700result2.lu; + lct = az6700result2.lct; + au = az6700result2.au; if (lct == -99.0) return lct; - var la = lu; - - double x; - double ut; - double g1; - var gu = 0.0; - var aa = 0.0; - for (int k = 1; k < 9; k++) - { - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + la = lu; + aa = au; + } - g1 = (k == 1) ? ut : gu; + au = aa; - gu = ut; - ut = gu; + return au; + } - var az6680result1 = MoonRiseAz_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); - lct = az6680result1.lct; - dy1 = az6680result1.dy1; - mn1 = az6680result1.mn1; - yr1 = az6680result1.yr1; - gdy = az6680result1.gdy; - gmn = az6680result1.gmn; - gyr = az6680result1.gyr; + /// + /// Helper function for MoonRiseAz + /// + public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonRiseAz_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + { + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; + + ut = UTDayAdjust(ut, g1); + var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + ut = ut - 24.0 * (ut / 24.0).Floor(); + + return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); + } - var az6700result2 = MoonRiseAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - lu = az6700result2.lu; - lct = az6700result2.lct; - au = az6700result2.au; + /// + /// Helper function for MoonRiseAz + /// + public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct, double au) MoonRiseAz_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) + { + var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); + var dp = NutatLong(gdy, gmn, gyr); + var th = 0.27249 * pm.Sine(); + var di = th + 0.0098902 - pm; + var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); + var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); + var lu = RiseSetLocalSiderealTimeRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + var au = RiseSetAzimuthRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + + return (mm, bm, pm, dp, th, di, p, q, lu, lct, au); + } - if (lct == -99.0) - return lct; + /// + /// Local time of moonset. + /// + /// + /// Original macro name: MoonSetLCT + /// + /// hours + public static double MoonSetLCT(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) + { + var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var lct = 12.0; + var dy1 = dy; + var mn1 = mn; + var yr1 = yr; + + var lct6700result1 = MoonSetLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + var lu = lct6700result1.lu; + lct = lct6700result1.lct; + + if (lct == -99.0) + return lct; - la = lu; - aa = au; - } + var la = lu; - au = aa; + double x; + double ut; + var g1 = 0.0; + var gu = 0.0; + for (int k = 1; k < 9; k++) + { + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - return au; - } + g1 = (k == 1) ? ut : gu; - /// - /// Helper function for MoonRiseAz - /// - public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonRiseAz_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) - { - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - ut = ut - 24.0 * (ut / 24.0).Floor(); - - return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); - } + gu = ut; + ut = gu; - /// - /// Helper function for MoonRiseAz - /// - public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct, double au) MoonRiseAz_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) - { - var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); - var dp = NutatLong(gdy, gmn, gyr); - var th = 0.27249 * pm.Sine(); - var di = th + 0.0098902 - pm; - var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); - var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); - var lu = RiseSetLocalSiderealTimeRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - var au = RiseSetAzimuthRise(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - - return (mm, bm, pm, dp, th, di, p, q, lu, lct, au); - } + var lct6680result1 = MoonSetLCT_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); + lct = lct6680result1.lct; + dy1 = lct6680result1.dy1; + mn1 = lct6680result1.mn1; + yr1 = lct6680result1.yr1; + gdy = lct6680result1.gdy; + gmn = lct6680result1.gmn; + gyr = lct6680result1.gyr; - /// - /// Local time of moonset. - /// - /// - /// Original macro name: MoonSetLCT - /// - /// hours - public static double MoonSetLCT(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) - { - var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var lct = 12.0; - var dy1 = dy; - var mn1 = mn; - var yr1 = yr; - - var lct6700result1 = MoonSetLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - var lu = lct6700result1.lu; - lct = lct6700result1.lct; + var lct6700result2 = MoonSetLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + lu = lct6700result2.lu; + lct = lct6700result2.lct; if (lct == -99.0) return lct; - var la = lu; - - double x; - double ut; - var g1 = 0.0; - var gu = 0.0; - for (int k = 1; k < 9; k++) - { - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + la = lu; + } - g1 = (k == 1) ? ut : gu; + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - gu = ut; - ut = gu; + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; - var lct6680result1 = MoonSetLCT_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); - lct = lct6680result1.lct; - dy1 = lct6680result1.dy1; - mn1 = lct6680result1.mn1; - yr1 = lct6680result1.yr1; - gdy = lct6680result1.gdy; - gmn = lct6680result1.gmn; - gyr = lct6680result1.gyr; + ut = UTDayAdjust(ut, g1); + lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var lct6700result2 = MoonSetLCT_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - lu = lct6700result2.lu; - lct = lct6700result2.lct; + return lct; + } - if (lct == -99.0) - return lct; + /// + /// Helper function for MoonSetLCT + /// + public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonSetLCT_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + { + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; + + ut = UTDayAdjust(ut, g1); + var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + ut = ut - 24.0 * (ut / 24.0).Floor(); + + return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); + } - la = lu; - } + /// + /// Helper function for MoonSetLCT + /// + public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonSetLCT_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) + { + var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); + var dp = NutatLong(gdy, gmn, gyr); + var th = 0.27249 * pm.Sine(); + var di = th + 0.0098902 - pm; + var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); + var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); + var lu = RiseSetLocalSiderealTimeSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + + if (!ERS(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat).Equals("OK")) + lct = -99.0; + + return (mm, bm, pm, dp, th, di, p, q, lu, lct); + } - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + /// + /// Local date of moonset. + /// + /// + /// Original macro names: MoonSetLcDay, MoonSetLcMonth, MoonSetLcYear + /// + /// + /// Local date (day) + /// Local date (month) + /// Local date (year) + /// + public static (double dy1, int mn1, int yr1) MoonSetLcDMY(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) + { + var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var lct = 12.0; + var dy1 = dy; + var mn1 = mn; + var yr1 = yr; - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; + var dmy6700result1 = MoonSetLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + var lu = dmy6700result1.lu; + lct = dmy6700result1.lct; - ut = UTDayAdjust(ut, g1); - lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + if (lct == -99.0) + return (lct, (int)lct, (int)lct); - return lct; - } + var la = lu; - /// - /// Helper function for MoonSetLCT - /// - public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonSetLCT_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + double x; + double ut; + var g1 = 0.0; + var gu = 0.0; + for (int k = 1; k < 9; k++) { - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - ut = ut - 24.0 * (ut / 24.0).Floor(); - - return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); - } + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - /// - /// Helper function for MoonSetLCT - /// - public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonSetLCT_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) - { - var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); - var dp = NutatLong(gdy, gmn, gyr); - var th = 0.27249 * pm.Sine(); - var di = th + 0.0098902 - pm; - var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); - var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); - var lu = RiseSetLocalSiderealTimeSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - - if (!ERS(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat).Equals("OK")) - lct = -99.0; - - return (mm, bm, pm, dp, th, di, p, q, lu, lct); - } + g1 = (k == 1) ? ut : gu; - /// - /// Local date of moonset. - /// - /// - /// Original macro names: MoonSetLcDay, MoonSetLcMonth, MoonSetLcYear - /// - /// - /// Local date (day) - /// Local date (month) - /// Local date (year) - /// - public static (double dy1, int mn1, int yr1) MoonSetLcDMY(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) - { - var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var lct = 12.0; - var dy1 = dy; - var mn1 = mn; - var yr1 = yr; - - var dmy6700result1 = MoonSetLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - var lu = dmy6700result1.lu; - lct = dmy6700result1.lct; + gu = ut; + ut = gu; + + var dmy6680result1 = MoonSetLcDMY_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); + lct = dmy6680result1.lct; + dy1 = dmy6680result1.dy1; + mn1 = dmy6680result1.mn1; + yr1 = dmy6680result1.yr1; + gdy = dmy6680result1.gdy; + gmn = dmy6680result1.gmn; + gyr = dmy6680result1.gyr; + + var dmy6700result2 = MoonSetLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + lu = dmy6700result2.lu; + lct = dmy6700result2.lct; if (lct == -99.0) return (lct, (int)lct, (int)lct); - var la = lu; + la = lu; + } - double x; - double ut; - var g1 = 0.0; - var gu = 0.0; - for (int k = 1; k < 9; k++) - { - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - g1 = (k == 1) ? ut : gu; + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; - gu = ut; - ut = gu; + ut = UTDayAdjust(ut, g1); + dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var dmy6680result1 = MoonSetLcDMY_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); - lct = dmy6680result1.lct; - dy1 = dmy6680result1.dy1; - mn1 = dmy6680result1.mn1; - yr1 = dmy6680result1.yr1; - gdy = dmy6680result1.gdy; - gmn = dmy6680result1.gmn; - gyr = dmy6680result1.gyr; + return (dy1, mn1, yr1); + } - var dmy6700result2 = MoonSetLcDMY_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - lu = dmy6700result2.lu; - lct = dmy6700result2.lct; + /// + /// Helper function for MoonSetLcDMY + /// + public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonSetLcDMY_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + { + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; + + ut = UTDayAdjust(ut, g1); + var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + ut = ut - 24.0 * (ut / 24.0).Floor(); + + return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); + } - if (lct == -99.0) - return (lct, (int)lct, (int)lct); + /// + /// Helper function for MoonSetLcDMY + /// + public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonSetLcDMY_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) + { + var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); + var dp = NutatLong(gdy, gmn, gyr); + var th = 0.27249 * pm.Sine(); + var di = th + 0.0098902 - pm; + var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); + var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); + var lu = RiseSetLocalSiderealTimeSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + + return (mm, bm, pm, dp, th, di, p, q, lu, lct); + } - la = lu; - } + /// + /// Local azimuth of moonset. + /// + /// + /// Original macro name: MoonSetAz + /// + /// degrees + public static double MoonSetAz(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) + { + var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var lct = 12.0; + var dy1 = dy; + var mn1 = mn; + var yr1 = yr; - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); + var az6700result1 = MoonSetAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + var lu = az6700result1.lu; + lct = az6700result1.lct; - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; + double au; - ut = UTDayAdjust(ut, g1); - dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + if (lct == -99.0) + return lct; - return (dy1, mn1, yr1); - } + var la = lu; - /// - /// Helper function for MoonSetLcDMY - /// - public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonSetLcDMY_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + double x; + double ut; + double g1; + var gu = 0.0; + var aa = 0.0; + for (int k = 1; k < 9; k++) { - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - ut = ut - 24.0 * (ut / 24.0).Floor(); - - return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); - } + x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); + ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - /// - /// Helper function for MoonSetLcDMY - /// - public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct) MoonSetLcDMY_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) - { - var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); - var dp = NutatLong(gdy, gmn, gyr); - var th = 0.27249 * pm.Sine(); - var di = th + 0.0098902 - pm; - var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); - var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); - var lu = RiseSetLocalSiderealTimeSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - - return (mm, bm, pm, dp, th, di, p, q, lu, lct); - } + g1 = (k == 1) ? ut : gu; - /// - /// Local azimuth of moonset. - /// - /// - /// Original macro name: MoonSetAz - /// - /// degrees - public static double MoonSetAz(double dy, int mn, int yr, int ds, int zc, double gLong, double gLat) - { - var gdy = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gmn = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var gyr = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var lct = 12.0; - var dy1 = dy; - var mn1 = mn; - var yr1 = yr; + gu = ut; + ut = gu; - var az6700result1 = MoonSetAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - var lu = az6700result1.lu; - lct = az6700result1.lct; + var az6680result1 = MoonSetAz_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); + lct = az6680result1.lct; + dy1 = az6680result1.dy1; + mn1 = az6680result1.mn1; + yr1 = az6680result1.yr1; + gdy = az6680result1.gdy; + gmn = az6680result1.gmn; + gyr = az6680result1.gyr; - double au; + var az6700result2 = MoonSetAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); + lu = az6700result2.lu; + lct = az6700result2.lct; + au = az6700result2.au; if (lct == -99.0) return lct; - var la = lu; - - double x; - double ut; - double g1; - var gu = 0.0; - var aa = 0.0; - for (int k = 1; k < 9; k++) - { - x = LocalSiderealTimeToGreenwichSiderealTime(la, 0.0, 0.0, gLong); - ut = GreenwichSiderealTimeToUniversalTime(x, 0.0, 0.0, gdy, gmn, gyr); - - g1 = (k == 1) ? ut : gu; - - gu = ut; - ut = gu; + la = lu; + aa = au; + } - var az6680result1 = MoonSetAz_L6680(x, ds, zc, gdy, gmn, gyr, g1, ut); - lct = az6680result1.lct; - dy1 = az6680result1.dy1; - mn1 = az6680result1.mn1; - yr1 = az6680result1.yr1; - gdy = az6680result1.gdy; - gmn = az6680result1.gmn; - gyr = az6680result1.gyr; + au = aa; - var az6700result2 = MoonSetAz_L6700(lct, ds, zc, dy1, mn1, yr1, gdy, gmn, gyr, gLat); - lu = az6700result2.lu; - lct = az6700result2.lct; - au = az6700result2.au; + return au; + } - if (lct == -99.0) - return lct; + /// + /// Helper function for moon_set_az + /// + public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonSetAz_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) + { + if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) + if (Math.Abs(g1 - ut) > 0.5) + ut = ut + 23.93447; + + ut = UTDayAdjust(ut, g1); + var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); + gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + ut = ut - 24.0 * (ut / 24.0).Floor(); + + return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); + } - la = lu; - aa = au; - } + /// + /// Helper function for moon_set_az + /// + public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct, double au) MoonSetAz_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) + { + var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); + var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); + var dp = NutatLong(gdy, gmn, gyr); + var th = 0.27249 * pm.Sine(); + var di = th + 0.0098902 - pm; + var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); + var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); + var lu = RiseSetLocalSiderealTimeSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + var au = RiseSetAzimuthSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); + + return (mm, bm, pm, dp, th, di, p, q, lu, lct, au); + } - au = aa; + /// + /// Determine if a lunar eclipse is likely to occur. + /// + /// + /// Original macro name: LEOccurrence + /// + public static string LunarEclipseOccurrence(int ds, int zc, double dy, int mn, int yr) + { + var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - return au; - } + var j0 = CivilDateToJulianDate(0.0, 1, y0); + var dj = CivilDateToJulianDate(d0, m0, y0); + var k = (y0 - 1900.0 + ((dj - j0) * 1.0 / 365.0)) * 12.3685; + k = Lint(k + 0.5); + var tn = k / 1236.85; + var tf = (k + 0.5) / 1236.85; + var t = tn; + var l6855result1 = LunarEclipseOccurrence_L6855(t, k); + t = tf; + k = k + 0.5; + var l6855result2 = LunarEclipseOccurrence_L6855(t, k); + var fb = l6855result2.f; - /// - /// Helper function for moon_set_az - /// - public static (double ut, double lct, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr) MoonSetAz_L6680(double x, int ds, int zc, double gdy, int gmn, int gyr, double g1, double ut) - { - if (!EGstUt(x, 0.0, 0.0, gdy, gmn, gyr).Equals(PAWarningFlag.OK)) - if (Math.Abs(g1 - ut) > 0.5) - ut = ut + 23.93447; - - ut = UTDayAdjust(ut, g1); - var lct = UniversalTimeToLocalCivilTime(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var dy1 = UniversalTime_LocalCivilDay(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var mn1 = UniversalTime_LocalCivilMonth(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - var yr1 = UniversalTime_LocalCivilYear(ut, 0.0, 0.0, ds, zc, gdy, gmn, gyr); - gdy = LocalCivilTimeGreenwichDay(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gmn = LocalCivilTimeGreenwichMonth(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - gyr = LocalCivilTimeGreenwichYear(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - ut = ut - 24.0 * (ut / 24.0).Floor(); - - return (ut, lct, dy1, mn1, yr1, gdy, gmn, gyr); - } + var df = Math.Abs(fb - 3.141592654 * Lint(fb / 3.141592654)); - /// - /// Helper function for moon_set_az - /// - public static (double mm, double bm, double pm, double dp, double th, double di, double p, double q, double lu, double lct, double au) MoonSetAz_L6700(double lct, int ds, int zc, double dy1, int mn1, int yr1, double gdy, int gmn, int gyr, double gLat) - { - var mm = MoonLong(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var bm = MoonLat(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1); - var pm = (MoonHP(lct, 0.0, 0.0, ds, zc, dy1, mn1, yr1)).ToRadians(); - var dp = NutatLong(gdy, gmn, gyr); - var th = 0.27249 * pm.Sine(); - var di = th + 0.0098902 - pm; - var p = DecimalDegreesToDegreeHours(EcRA(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr)); - var q = EcDec(mm + dp, 0.0, 0.0, bm, 0.0, 0.0, gdy, gmn, gyr); - var lu = RiseSetLocalSiderealTimeSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - var au = RiseSetAzimuthSet(p, 0.0, 0.0, q, 0.0, 0.0, Degrees(di), gLat); - - return (mm, bm, pm, dp, th, di, p, q, lu, lct, au); - } + if (df > 0.37) + df = 3.141592654 - df; - /// - /// Determine if a lunar eclipse is likely to occur. - /// - /// - /// Original macro name: LEOccurrence - /// - public static string LunarEclipseOccurrence(int ds, int zc, double dy, int mn, int yr) + var s = "Lunar eclipse certain"; + if (df >= 0.242600766) { - var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - - var j0 = CivilDateToJulianDate(0.0, 1, y0); - var dj = CivilDateToJulianDate(d0, m0, y0); - var k = (y0 - 1900.0 + ((dj - j0) * 1.0 / 365.0)) * 12.3685; - k = Lint(k + 0.5); - var tn = k / 1236.85; - var tf = (k + 0.5) / 1236.85; - var t = tn; - var l6855result1 = LunarEclipseOccurrence_L6855(t, k); - t = tf; - k = k + 0.5; - var l6855result2 = LunarEclipseOccurrence_L6855(t, k); - var fb = l6855result2.f; - - var df = Math.Abs(fb - 3.141592654 * Lint(fb / 3.141592654)); + s = "Lunar eclipse possible"; if (df > 0.37) - df = 3.141592654 - df; - - var s = "Lunar eclipse certain"; - if (df >= 0.242600766) - { - s = "Lunar eclipse possible"; - - if (df > 0.37) - s = "No lunar eclipse"; - } - - return s; + s = "No lunar eclipse"; } - /// - /// Helper function for lunar_eclipse_occurrence - /// - public static (double f, double dd, double e1, double b1, double a, double b) LunarEclipseOccurrence_L6855(double t, double k) - { - var t2 = t * t; - var e = 29.53 * k; - var c = 166.56 + (132.87 - 0.009173 * t) * t; - c = c.ToRadians(); - var b = 0.00058868 * k + (0.0001178 - 0.000000155 * t) * t2; - b = b + 0.00033 * c.Sine() + 0.75933; - var a = k / 12.36886; - var a1 = 359.2242 + 360.0 * FPart(a) - (0.0000333 + 0.00000347 * t) * t2; - var a2 = 306.0253 + 360.0 * FPart(k / 0.9330851); - a2 = a2 + (0.0107306 + 0.00001236 * t) * t2; - a = k / 0.9214926; - var f = 21.2964 + 360.0 * FPart(a) - (0.0016528 + 0.00000239 * t) * t2; - a1 = UnwindDeg(a1); - a2 = UnwindDeg(a2); - f = UnwindDeg(f); - a1 = a1.ToRadians(); - a2 = a2.ToRadians(); - f = f.ToRadians(); - - var dd = (0.1734 - 0.000393 * t) * a1.Sine() + 0.0021 * (2.0 * a1).Sine(); - dd = dd - 0.4068 * a2.Sine() + 0.0161 * (2.0 * a2).Sine() - 0.0004 * (3.0 * a2).Sine(); - dd = dd + 0.0104 * (2.0 * f).Sine() - 0.0051 * (a1 + a2).Sine(); - dd = dd - 0.0074 * (a1 - a2).Sine() + 0.0004 * (2.0 * f + a1).Sine(); - dd = dd - 0.0004 * (2.0 * f - a1).Sine() - 0.0006 * (2.0 * f + a2).Sine() + 0.001 * (2.0 * f - a2).Sine(); - dd = dd + 0.0005 * (a1 + 2.0 * a2).Sine(); - var e1 = e.Floor(); - b = b + dd + (e - e1); - var b1 = b.Floor(); - a = e1 + b1; - b = b - b1; - - return (f, dd, e1, b1, a, b); - } + return s; + } - /// - /// Calculate time of maximum shadow for lunar eclipse (UT) - /// - /// - /// Original macro name: UTMaxLunarEclipse - /// - public static double UTMaxLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var rp = (hd + rn + ps) * 1.02; - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - return z1; - } + /// + /// Helper function for lunar_eclipse_occurrence + /// + public static (double f, double dd, double e1, double b1, double a, double b) LunarEclipseOccurrence_L6855(double t, double k) + { + var t2 = t * t; + var e = 29.53 * k; + var c = 166.56 + (132.87 - 0.009173 * t) * t; + c = c.ToRadians(); + var b = 0.00058868 * k + (0.0001178 - 0.000000155 * t) * t2; + b = b + 0.00033 * c.Sine() + 0.75933; + var a = k / 12.36886; + var a1 = 359.2242 + 360.0 * FPart(a) - (0.0000333 + 0.00000347 * t) * t2; + var a2 = 306.0253 + 360.0 * FPart(k / 0.9330851); + a2 = a2 + (0.0107306 + 0.00001236 * t) * t2; + a = k / 0.9214926; + var f = 21.2964 + 360.0 * FPart(a) - (0.0016528 + 0.00000239 * t) * t2; + a1 = UnwindDeg(a1); + a2 = UnwindDeg(a2); + f = UnwindDeg(f); + a1 = a1.ToRadians(); + a2 = a2.ToRadians(); + f = f.ToRadians(); + + var dd = (0.1734 - 0.000393 * t) * a1.Sine() + 0.0021 * (2.0 * a1).Sine(); + dd = dd - 0.4068 * a2.Sine() + 0.0161 * (2.0 * a2).Sine() - 0.0004 * (3.0 * a2).Sine(); + dd = dd + 0.0104 * (2.0 * f).Sine() - 0.0051 * (a1 + a2).Sine(); + dd = dd - 0.0074 * (a1 - a2).Sine() + 0.0004 * (2.0 * f + a1).Sine(); + dd = dd - 0.0004 * (2.0 * f - a1).Sine() - 0.0006 * (2.0 * f + a2).Sine() + 0.001 * (2.0 * f - a2).Sine(); + dd = dd + 0.0005 * (a1 + 2.0 * a2).Sine(); + var e1 = e.Floor(); + b = b + dd + (e - e1); + var b1 = b.Floor(); + a = e1 + b1; + b = b - b1; + + return (f, dd, e1, b1, a, b); + } - /// - /// Calculate time of first shadow contact for lunar eclipse (UT) - /// - /// - /// Original macro name: UTFirstContactLunarEclipse - /// - public static double UTFirstContactLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var rp = (hd + rn + ps) * 1.02; - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z6 = z1 - zd; - - if (z6 < 0.0) - z6 = z6 + 24.0; - - return z6; - } + /// + /// Calculate time of maximum shadow for lunar eclipse (UT) + /// + /// + /// Original macro name: UTMaxLunarEclipse + /// + public static double UTMaxLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var rp = (hd + rn + ps) * 1.02; + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + return z1; + } - /// - /// Calculate time of last shadow contact for lunar eclipse (UT) - /// - /// - /// Original macro name: UTLastContactLunarEclipse - /// - public static double UTLastContactLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var rp = (hd + rn + ps) * 1.02; - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z7 = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; - - return z7; - } + /// + /// Calculate time of first shadow contact for lunar eclipse (UT) + /// + /// + /// Original macro name: UTFirstContactLunarEclipse + /// + public static double UTFirstContactLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var rp = (hd + rn + ps) * 1.02; + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z6 = z1 - zd; + + if (z6 < 0.0) + z6 = z6 + 24.0; + + return z6; + } - /// - /// Calculate start time of umbra phase of lunar eclipse (UT) - /// - /// - /// Original macro name: UTStartUmbraLunarEclipse - /// - public static double UTStartUmbraLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var ru = (hd - rn + ps) * 1.02; - var rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z6 = z1 - zd; - - r = rm + ru; - dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - zd = dd.SquareRoot(); - var z8 = z1 - zd; - - if (z8 < 0.0) - z8 = z8 + 24.0; - - return z8; - } + /// + /// Calculate time of last shadow contact for lunar eclipse (UT) + /// + /// + /// Original macro name: UTLastContactLunarEclipse + /// + public static double UTLastContactLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var rp = (hd + rn + ps) * 1.02; + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z7 = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; + + return z7; + } - /// - /// Calculate end time of umbra phase of lunar eclipse (UT) - /// - /// - /// Original macro name: UTEndUmbraLunarEclipse - /// - public static double UTEndUmbraLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var ru = (hd - rn + ps) * 1.02; - var rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z6 = z1 - zd; - - r = rm + ru; - dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - zd = dd.SquareRoot(); - var z9 = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; - - return z9; - } + /// + /// Calculate start time of umbra phase of lunar eclipse (UT) + /// + /// + /// Original macro name: UTStartUmbraLunarEclipse + /// + public static double UTStartUmbraLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var ru = (hd - rn + ps) * 1.02; + var rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z6 = z1 - zd; + + r = rm + ru; + dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + zd = dd.SquareRoot(); + var z8 = z1 - zd; + + if (z8 < 0.0) + z8 = z8 + 24.0; + + return z8; + } - /// - /// Calculate start time of total phase of lunar eclipse (UT) - /// - /// - /// Original macro name: UTStartTotalLunarEclipse - /// - public static double UTStartTotalLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var ru = (hd - rn + ps) * 1.02; - var rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = (dd).SquareRoot(); - var z6 = z1 - zd; - - r = rm + ru; - dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - zd = (dd).SquareRoot(); - var z8 = z1 - zd; - - r = ru - rm; - dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - zd = (dd).SquareRoot(); - var zcc = z1 - zd; - - if (zcc < 0.0) - zcc = zc + 24.0; - - return zcc; - } + /// + /// Calculate end time of umbra phase of lunar eclipse (UT) + /// + /// + /// Original macro name: UTEndUmbraLunarEclipse + /// + public static double UTEndUmbraLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var ru = (hd - rn + ps) * 1.02; + var rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z6 = z1 - zd; + + r = rm + ru; + dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + zd = dd.SquareRoot(); + var z9 = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; + + return z9; + } - /// - /// Calculate end time of total phase of lunar eclipse (UT) - /// - /// - /// Original macro name: UTEndTotalLunarEclipse - /// - public static double UTEndTotalLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var ru = (hd - rn + ps) * 1.02; - var rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z6 = z1 - zd; - - r = rm + ru; - dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - zd = dd.SquareRoot(); - var z8 = z1 - zd; - - r = ru - rm; - dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - zd = dd.SquareRoot(); - var zb = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; - - return zb; - } + /// + /// Calculate start time of total phase of lunar eclipse (UT) + /// + /// + /// Original macro name: UTStartTotalLunarEclipse + /// + public static double UTStartTotalLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var ru = (hd - rn + ps) * 1.02; + var rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = (dd).SquareRoot(); + var z6 = z1 - zd; + + r = rm + ru; + dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + zd = (dd).SquareRoot(); + var z8 = z1 - zd; + + r = ru - rm; + dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + zd = (dd).SquareRoot(); + var zcc = z1 - zd; + + if (zcc < 0.0) + zcc = zc + 24.0; + + return zcc; + } - /// - /// Calculate magnitude of lunar eclipse. - /// - /// - /// Original macro name: MagLunarEclipse - /// - public static double MagLunarEclipse(double dy, int mn, int yr, int ds, int zc) - { - var tp = 2.0 * Math.PI; - - if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) - return -99.0; - - var dj = FullMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utfm = xi * 24.0; - var ut = utfm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utfm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utfm; - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var q = 0.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; - by = by - q; - bz = bz - q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var ru = (hd - rn + ps) * 1.02; - var rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rp; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z6 = z1 - zd; - - r = rm + ru; - dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - var mg = (rm + rp - pj) / (2.0 * rm); - - if (dd < 0.0) - return mg; - - zd = dd.SquareRoot(); - var z8 = z1 - zd; - - - r = ru - rm; - dd = z1 - x0; - mg = (rm + ru - pj) / (2.0 * rm); + /// + /// Calculate end time of total phase of lunar eclipse (UT) + /// + /// + /// Original macro name: UTEndTotalLunarEclipse + /// + public static double UTEndTotalLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var ru = (hd - rn + ps) * 1.02; + var rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z6 = z1 - zd; + + r = rm + ru; + dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + zd = dd.SquareRoot(); + var z8 = z1 - zd; + + r = ru - rm; + dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + zd = dd.SquareRoot(); + var zb = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; + + return zb; + } + /// + /// Calculate magnitude of lunar eclipse. + /// + /// + /// Original macro name: MagLunarEclipse + /// + public static double MagLunarEclipse(double dy, int mn, int yr, int ds, int zc) + { + var tp = 2.0 * Math.PI; + + if (LunarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No lunar eclipse")) + return -99.0; + + var dj = FullMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utfm = xi * 24.0; + var ut = utfm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utfm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utfm; + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var q = 0.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + sr = sr + Math.PI - Lint((sr + Math.PI) / tp) * tp; + by = by - q; + bz = bz - q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var ru = (hd - rn + ps) * 1.02; + var rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rp; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z6 = z1 - zd; + + r = rm + ru; + dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + var mg = (rm + rp - pj) / (2.0 * rm); + + if (dd < 0.0) return mg; - } - /// - /// Determine if a solar eclipse is likely to occur. - /// - /// - /// Original macro name: SEOccurrence - /// - public static string SolarEclipseOccurrence(int ds, int zc, double dy, int mn, int yr) - { - var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); - - var j0 = CivilDateToJulianDate(0.0, 1, y0); - var dj = CivilDateToJulianDate(d0, m0, y0); - var k = (y0 - 1900.0 + ((dj - j0) * 1.0 / 365.0)) * 12.3685; - k = Lint(k + 0.5); - var tn = k / 1236.85; - var tf = (k + 0.5) / 1236.85; - var t = tn; - var l6855result1 = SolarEclipseOccurrence_L6855(t, k); - var nb = l6855result1.f; - t = tf; - k = k + 0.5; - var l6855result2 = SolarEclipseOccurrence_L6855(t, k); - - var df = Math.Abs(nb - 3.141592654 * Lint(nb / 3.141592654)); + zd = dd.SquareRoot(); + var z8 = z1 - zd; - if (df > 0.37) - df = 3.141592654 - df; - var s = "Solar eclipse certain"; - if (df >= 0.242600766) - { - s = "Solar eclipse possible"; - if (df > 0.37) - s = "No solar eclipse"; - } + r = ru - rm; + dd = z1 - x0; + mg = (rm + ru - pj) / (2.0 * rm); - return s; - } + return mg; + } - /// - /// Helper function for SolarEclipseOccurrence - /// - public static (double f, double dd, double e1, double b1, double a, double b) SolarEclipseOccurrence_L6855(double t, double k) - { - var t2 = t * t; - var e = 29.53 * k; - var c = 166.56 + (132.87 - 0.009173 * t) * t; - c = c.ToRadians(); - var b = 0.00058868 * k + (0.0001178 - 0.000000155 * t) * t2; - b = b + 0.00033 * c.Sine() + 0.75933; - var a = k / 12.36886; - var a1 = 359.2242 + 360.0 * FPart(a) - (0.0000333 + 0.00000347 * t) * t2; - var a2 = 306.0253 + 360.0 * FPart(k / 0.9330851); - a2 = a2 + (0.0107306 + 0.00001236 * t) * t2; - a = k / 0.9214926; - var f = 21.2964 + 360.0 * FPart(a) - (0.0016528 + 0.00000239 * t) * t2; - a1 = UnwindDeg(a1); - a2 = UnwindDeg(a2); - f = UnwindDeg(f); - a1 = a1.ToRadians(); - a2 = a2.ToRadians(); - f = f.ToRadians(); - - var dd = (0.1734 - 0.000393 * t) * (a1).Sine() + 0.0021 * (2.0 * a1).Sine(); - dd = dd - 0.4068 * (a2).Sine() + 0.0161 * (2.0 * a2).Sine() - 0.0004 * (3.0 * a2).Sine(); - dd = dd + 0.0104 * (2.0 * f).Sine() - 0.0051 * (a1 + a2).Sine(); - dd = dd - 0.0074 * (a1 - a2).Sine() + 0.0004 * (2.0 * f + a1).Sine(); - dd = dd - 0.0004 * (2.0 * f - a1).Sine() - 0.0006 * (2.0 * f + a2).Sine() + 0.001 * (2.0 * f - a2).Sine(); - dd = dd + 0.0005 * (a1 + 2.0 * a2).Sine(); - var e1 = e.Floor(); - b = b + dd + (e - e1); - var b1 = b.Floor(); - a = e1 + b1; - b = b - b1; - - return (f, dd, e1, b1, a, b); + /// + /// Determine if a solar eclipse is likely to occur. + /// + /// + /// Original macro name: SEOccurrence + /// + public static string SolarEclipseOccurrence(int ds, int zc, double dy, int mn, int yr) + { + var d0 = LocalCivilTimeGreenwichDay(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var m0 = LocalCivilTimeGreenwichMonth(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + var y0 = LocalCivilTimeGreenwichYear(12.0, 0.0, 0.0, ds, zc, dy, mn, yr); + + var j0 = CivilDateToJulianDate(0.0, 1, y0); + var dj = CivilDateToJulianDate(d0, m0, y0); + var k = (y0 - 1900.0 + ((dj - j0) * 1.0 / 365.0)) * 12.3685; + k = Lint(k + 0.5); + var tn = k / 1236.85; + var tf = (k + 0.5) / 1236.85; + var t = tn; + var l6855result1 = SolarEclipseOccurrence_L6855(t, k); + var nb = l6855result1.f; + t = tf; + k = k + 0.5; + var l6855result2 = SolarEclipseOccurrence_L6855(t, k); + + var df = Math.Abs(nb - 3.141592654 * Lint(nb / 3.141592654)); + + if (df > 0.37) + df = 3.141592654 - df; + + var s = "Solar eclipse certain"; + if (df >= 0.242600766) + { + s = "Solar eclipse possible"; + if (df > 0.37) + s = "No solar eclipse"; } - /// - /// Calculate time of maximum shadow for solar eclipse (UT) - /// - /// - /// Original macro name: UTMaxSolarEclipse - /// - public static double UTMaxSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) - { - var tp = 2.0 * Math.PI; - - if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) - return -99.0; - - var dj = NewMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utnm = xi * 24.0; - var ut = utnm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utnm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utnm; - var x = my; - var y = by; - var tm = xh - 1.0; - var hp = hy; - var l7390result1 = UTMaxSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - my = l7390result1.p; - by = l7390result1.q; - x = mz; - y = bz; - tm = xh + 1.0; - hp = hz; - var l7390result2 = UTMaxSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - mz = l7390result2.p; - bz = l7390result2.q; - - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - x = sr; - y = 0.0; - tm = ut; - hp = 0.00004263452 / rr; - var l7390result3 = UTMaxSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - // let(_paa, _qaa, _xaa, _pbb, _qbb, _xbb, p, q) = - sr = l7390result3.p; - by = by - l7390result3.q; - bz = bz - l7390result3.q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var _ru = (hd - rn + ps) * 1.02; - var _rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rn; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - - return z1; - } + return s; + } - /// - /// Helper function for ut_max_solar_eclipse - /// - public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) UTMaxSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) - { - var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - - return (paa, qaa, xaa, pbb, qbb, xbb, p, q); - } + /// + /// Helper function for SolarEclipseOccurrence + /// + public static (double f, double dd, double e1, double b1, double a, double b) SolarEclipseOccurrence_L6855(double t, double k) + { + var t2 = t * t; + var e = 29.53 * k; + var c = 166.56 + (132.87 - 0.009173 * t) * t; + c = c.ToRadians(); + var b = 0.00058868 * k + (0.0001178 - 0.000000155 * t) * t2; + b = b + 0.00033 * c.Sine() + 0.75933; + var a = k / 12.36886; + var a1 = 359.2242 + 360.0 * FPart(a) - (0.0000333 + 0.00000347 * t) * t2; + var a2 = 306.0253 + 360.0 * FPart(k / 0.9330851); + a2 = a2 + (0.0107306 + 0.00001236 * t) * t2; + a = k / 0.9214926; + var f = 21.2964 + 360.0 * FPart(a) - (0.0016528 + 0.00000239 * t) * t2; + a1 = UnwindDeg(a1); + a2 = UnwindDeg(a2); + f = UnwindDeg(f); + a1 = a1.ToRadians(); + a2 = a2.ToRadians(); + f = f.ToRadians(); + + var dd = (0.1734 - 0.000393 * t) * (a1).Sine() + 0.0021 * (2.0 * a1).Sine(); + dd = dd - 0.4068 * (a2).Sine() + 0.0161 * (2.0 * a2).Sine() - 0.0004 * (3.0 * a2).Sine(); + dd = dd + 0.0104 * (2.0 * f).Sine() - 0.0051 * (a1 + a2).Sine(); + dd = dd - 0.0074 * (a1 - a2).Sine() + 0.0004 * (2.0 * f + a1).Sine(); + dd = dd - 0.0004 * (2.0 * f - a1).Sine() - 0.0006 * (2.0 * f + a2).Sine() + 0.001 * (2.0 * f - a2).Sine(); + dd = dd + 0.0005 * (a1 + 2.0 * a2).Sine(); + var e1 = e.Floor(); + b = b + dd + (e - e1); + var b1 = b.Floor(); + a = e1 + b1; + b = b - b1; + + return (f, dd, e1, b1, a, b); + } - /// - /// Calculate time of first contact for solar eclipse (UT) - /// - /// - /// Original macro name: UTFirstContactSolarEclipse - /// - public static double UTFirstContactSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) - { - var tp = 2.0 * Math.PI; - - if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) - return -99.0; - - var dj = NewMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utnm = xi * 24.0; - var ut = utnm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utnm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utnm; - var x = my; - var y = by; - var tm = xh - 1.0; - var hp = hy; - var l7390result1 = UTFirstContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - my = l7390result1.p; - by = l7390result1.q; - x = mz; - y = bz; - tm = xh + 1.0; - hp = hz; - var l7390result2 = UTFirstContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - mz = l7390result2.p; - bz = l7390result2.q; - - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - x = sr; - y = 0.0; - tm = ut; - hp = 0.00004263452 / rr; - var l7390result3 = UTFirstContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - sr = l7390result3.p; - by = by - l7390result3.q; - bz = bz - l7390result3.q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var _ru = (hd - rn + ps) * 1.02; - var _rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rn; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z6 = z1 - zd; - - if (z6 < 0.0) - z6 = z6 + 24.0; - - return z6; - } + /// + /// Calculate time of maximum shadow for solar eclipse (UT) + /// + /// + /// Original macro name: UTMaxSolarEclipse + /// + public static double UTMaxSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) + { + var tp = 2.0 * Math.PI; + + if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) + return -99.0; + + var dj = NewMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utnm = xi * 24.0; + var ut = utnm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utnm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utnm; + var x = my; + var y = by; + var tm = xh - 1.0; + var hp = hy; + var l7390result1 = UTMaxSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + my = l7390result1.p; + by = l7390result1.q; + x = mz; + y = bz; + tm = xh + 1.0; + hp = hz; + var l7390result2 = UTMaxSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + mz = l7390result2.p; + bz = l7390result2.q; + + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + x = sr; + y = 0.0; + tm = ut; + hp = 0.00004263452 / rr; + var l7390result3 = UTMaxSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + // let(_paa, _qaa, _xaa, _pbb, _qbb, _xbb, p, q) = + sr = l7390result3.p; + by = by - l7390result3.q; + bz = bz - l7390result3.q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var _ru = (hd - rn + ps) * 1.02; + var _rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rn; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + + return z1; + } - /// - /// Helper function for UTFirstContactSolarEclipse - /// - public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) UTFirstContactSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) - { - var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - - return (paa, qaa, xaa, pbb, qbb, xbb, p, q); - } + /// + /// Helper function for ut_max_solar_eclipse + /// + public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) UTMaxSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) + { + var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + + return (paa, qaa, xaa, pbb, qbb, xbb, p, q); + } - /// - /// Calculate time of last contact for solar eclipse (UT) - /// - /// - /// Original macro name: UTLastContactSolarEclipse - /// - public static double UTLastContactSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) - { - var tp = 2.0 * Math.PI; - - if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) - return -99.0; - - var dj = NewMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utnm = xi * 24.0; - var ut = utnm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utnm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utnm; - var x = my; - var y = by; - var tm = xh - 1.0; - var hp = hy; - var l7390result1 = UTLastContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - my = l7390result1.p; - by = l7390result1.q; - x = mz; - y = bz; - tm = xh + 1.0; - hp = hz; - var l7390result2 = UTLastContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - mz = l7390result2.p; - bz = l7390result2.q; - - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - x = sr; - y = 0.0; - tm = ut; - hp = 0.00004263452 / rr; - var l7390result3 = UTLastContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - sr = l7390result3.p; - by = by - l7390result3.q; - bz = bz - l7390result3.q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var _ru = (hd - rn + ps) * 1.02; - var _rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rn; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - var z7 = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; - - return z7; - } + /// + /// Calculate time of first contact for solar eclipse (UT) + /// + /// + /// Original macro name: UTFirstContactSolarEclipse + /// + public static double UTFirstContactSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) + { + var tp = 2.0 * Math.PI; + + if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) + return -99.0; + + var dj = NewMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utnm = xi * 24.0; + var ut = utnm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utnm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utnm; + var x = my; + var y = by; + var tm = xh - 1.0; + var hp = hy; + var l7390result1 = UTFirstContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + my = l7390result1.p; + by = l7390result1.q; + x = mz; + y = bz; + tm = xh + 1.0; + hp = hz; + var l7390result2 = UTFirstContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + mz = l7390result2.p; + bz = l7390result2.q; + + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + x = sr; + y = 0.0; + tm = ut; + hp = 0.00004263452 / rr; + var l7390result3 = UTFirstContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + sr = l7390result3.p; + by = by - l7390result3.q; + bz = bz - l7390result3.q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var _ru = (hd - rn + ps) * 1.02; + var _rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rn; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z6 = z1 - zd; + + if (z6 < 0.0) + z6 = z6 + 24.0; + + return z6; + } - /// - /// Helper function for ut_last_contact_solar_eclipse - /// - public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) UTLastContactSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) - { - var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - - return (paa, qaa, xaa, pbb, qbb, xbb, p, q); - } + /// + /// Helper function for UTFirstContactSolarEclipse + /// + public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) UTFirstContactSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) + { + var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + + return (paa, qaa, xaa, pbb, qbb, xbb, p, q); + } - /// - /// Calculate magnitude of solar eclipse. - /// - /// - /// Original macro name: MagSolarEclipse - /// - public static double MagSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) - { - var tp = 2.0 * Math.PI; - - if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) - return -99.0; - - var dj = NewMoon(ds, zc, dy, mn, yr); - var gday = JulianDateDay(dj); - var gmonth = JulianDateMonth(dj); - var gyear = JulianDateYear(dj); - var igday = gday.Floor(); - var xi = gday - igday; - var utnm = xi * 24.0; - var ut = utnm - 1.0; - var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - ut = utnm + 1.0; - var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; - var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - - if (sb < 0.0) - sb = sb + tp; - - var xh = utnm; - var x = my; - var y = by; - var tm = xh - 1.0; - var hp = hy; - var l7390result1 = MagSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - my = l7390result1.p; - by = l7390result1.q; - x = mz; - y = bz; - tm = xh + 1.0; - hp = hz; - var l7390result2 = MagSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - mz = l7390result2.p; - bz = l7390result2.q; - - var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); - var dm = mz - my; - - if (dm < 0.0) - dm = dm + tp; - - var lj = (dm - sb) / 2.0; - var mr = my + (dm * (x0 - xh + 1.0) / 2.0); - ut = x0 - 0.13851852; - var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); - var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); - sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); - x = sr; - y = 0.0; - tm = ut; - hp = 0.00004263452 / rr; - var l7390result3 = MagSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); - sr = l7390result3.p; - by = by - l7390result3.q; - bz = bz - l7390result3.q; - var p3 = 0.00004263; - var zh = (sr - mr) / lj; - var tc = x0 + zh; - var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; - var s2 = sh * sh; - var z2 = zh * zh; - var ps = p3 / (rr * lj); - var z1 = (zh * z2 / (z2 + s2)) + x0; - var h0 = (hy + hz) / (2.0 * lj); - var rm = 0.272446 * h0; - var rn = 0.00465242 / (lj * rr); - var hd = h0 * 0.99834; - var _ru = (hd - rn + ps) * 1.02; - var _rp = (hd + rn + ps) * 1.02; - var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); - var r = rm + rn; - var dd = z1 - x0; - dd = dd * dd - ((z2 - (r * r)) * dd / zh); - - if (dd < 0.0) - return -99.0; - - var zd = dd.SquareRoot(); - - var mg = (rm + rn - pj) / (2.0 * rn); + /// + /// Calculate time of last contact for solar eclipse (UT) + /// + /// + /// Original macro name: UTLastContactSolarEclipse + /// + public static double UTLastContactSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) + { + var tp = 2.0 * Math.PI; + + if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) + return -99.0; + + var dj = NewMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utnm = xi * 24.0; + var ut = utnm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utnm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utnm; + var x = my; + var y = by; + var tm = xh - 1.0; + var hp = hy; + var l7390result1 = UTLastContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + my = l7390result1.p; + by = l7390result1.q; + x = mz; + y = bz; + tm = xh + 1.0; + hp = hz; + var l7390result2 = UTLastContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + mz = l7390result2.p; + bz = l7390result2.q; + + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + x = sr; + y = 0.0; + tm = ut; + hp = 0.00004263452 / rr; + var l7390result3 = UTLastContactSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + sr = l7390result3.p; + by = by - l7390result3.q; + bz = bz - l7390result3.q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var _ru = (hd - rn + ps) * 1.02; + var _rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rn; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + var z7 = z1 + zd - Lint((z1 + zd) / 24.0) * 24.0; + + return z7; + } - return mg; - } + /// + /// Helper function for ut_last_contact_solar_eclipse + /// + public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) UTLastContactSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) + { + var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + + return (paa, qaa, xaa, pbb, qbb, xbb, p, q); + } - /// - /// Helper function for mag_solar_eclipse - /// - public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) MagSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) - { - var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); - var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); - var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); - var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); - - return (paa, qaa, xaa, pbb, qbb, xbb, p, q); - } + /// + /// Calculate magnitude of solar eclipse. + /// + /// + /// Original macro name: MagSolarEclipse + /// + public static double MagSolarEclipse(double dy, int mn, int yr, int ds, int zc, double glong, double glat) + { + var tp = 2.0 * Math.PI; + + if (SolarEclipseOccurrence(ds, zc, dy, mn, yr).Equals("No solar eclipse")) + return -99.0; + + var dj = NewMoon(ds, zc, dy, mn, yr); + var gday = JulianDateDay(dj); + var gmonth = JulianDateMonth(dj); + var gyear = JulianDateYear(dj); + var igday = gday.Floor(); + var xi = gday - igday; + var utnm = xi * 24.0; + var ut = utnm - 1.0; + var ly = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var my = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var by = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hy = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + ut = utnm + 1.0; + var sb = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians() - ly; + var mz = (MoonLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var bz = (MoonLat(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + var hz = (MoonHP(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + + if (sb < 0.0) + sb = sb + tp; + + var xh = utnm; + var x = my; + var y = by; + var tm = xh - 1.0; + var hp = hy; + var l7390result1 = MagSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + my = l7390result1.p; + by = l7390result1.q; + x = mz; + y = bz; + tm = xh + 1.0; + hp = hz; + var l7390result2 = MagSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + mz = l7390result2.p; + bz = l7390result2.q; + + var x0 = xh + 1.0 - (2.0 * bz / (bz - by)); + var dm = mz - my; + + if (dm < 0.0) + dm = dm + tp; + + var lj = (dm - sb) / 2.0; + var mr = my + (dm * (x0 - xh + 1.0) / 2.0); + ut = x0 - 0.13851852; + var rr = SunDist(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear); + var sr = (SunLong(ut, 0.0, 0.0, 0, 0, igday, gmonth, gyear)).ToRadians(); + sr = sr + (NutatLong(igday, gmonth, gyear) - 0.00569).ToRadians(); + x = sr; + y = 0.0; + tm = ut; + hp = 0.00004263452 / rr; + var l7390result3 = MagSolarEclipse_L7390(x, y, igday, gmonth, gyear, tm, glong, glat, hp); + sr = l7390result3.p; + by = by - l7390result3.q; + bz = bz - l7390result3.q; + var p3 = 0.00004263; + var zh = (sr - mr) / lj; + var tc = x0 + zh; + var sh = (((bz - by) * (tc - xh - 1.0) / 2.0) + bz) / lj; + var s2 = sh * sh; + var z2 = zh * zh; + var ps = p3 / (rr * lj); + var z1 = (zh * z2 / (z2 + s2)) + x0; + var h0 = (hy + hz) / (2.0 * lj); + var rm = 0.272446 * h0; + var rn = 0.00465242 / (lj * rr); + var hd = h0 * 0.99834; + var _ru = (hd - rn + ps) * 1.02; + var _rp = (hd + rn + ps) * 1.02; + var pj = Math.Abs(sh * zh / (s2 + z2).SquareRoot()); + var r = rm + rn; + var dd = z1 - x0; + dd = dd * dd - ((z2 - (r * r)) * dd / zh); + + if (dd < 0.0) + return -99.0; + + var zd = dd.SquareRoot(); + + var mg = (rm + rn - pj) / (2.0 * rn); + + return mg; + } + + /// + /// Helper function for mag_solar_eclipse + /// + public static (double paa, double qaa, double xaa, double pbb, double qbb, double xbb, double p, double q) MagSolarEclipse_L7390(double x, double y, double igday, int gmonth, int gyear, double tm, double glong, double glat, double hp) + { + var paa = EcRA(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var qaa = EcDec(Degrees(x), 0.0, 0.0, Degrees(y), 0.0, 0.0, igday, gmonth, gyear); + var xaa = RightAscensionToHourAngle(DecimalDegreesToDegreeHours(paa), 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var pbb = ParallaxHA(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var qbb = ParallaxDec(xaa, 0.0, 0.0, qaa, 0.0, 0.0, PACoordinateType.True, glat, 0.0, Degrees(hp)); + var xbb = HourAngleToRightAscension(pbb, 0.0, 0.0, tm, 0.0, 0.0, 0, 0, igday, gmonth, gyear, glong); + var p = (EQELong(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + var q = (EQELat(xbb, 0.0, 0.0, qbb, 0.0, 0.0, igday, gmonth, gyear)).ToRadians(); + + return (paa, qaa, xaa, pbb, qbb, xbb, p, q); } -} \ No newline at end of file +} diff --git a/PALib/PAMoon.cs b/PALib/PAMoon.cs index 9985741..979d6f4 100644 --- a/PALib/PAMoon.cs +++ b/PALib/PAMoon.cs @@ -1,273 +1,272 @@ using System; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Moon calculations. +/// +public class PAMoon { /// - /// Moon calculations. + /// Calculate approximate position of the Moon. + /// + /// + /// moon_ra_hour -- Right ascension of Moon (hour part) + /// moon_ra_min -- Right ascension of Moon (minutes part) + /// moon_ra_sec -- Right ascension of Moon (seconds part) + /// moon_dec_deg -- Declination of Moon (degrees part) + /// moon_dec_min -- Declination of Moon (minutes part) + /// moon_dec_sec -- Declination of Moon (seconds part) + /// + public (double moonRAHour, double moonRAMin, double moonRASec, double moonDecDeg, double moonDecMin, double moonDecSec) ApproximatePositionOfMoon(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var l0 = 91.9293359879052; + var p0 = 130.143076320618; + var n0 = 291.682546643194; + var i = 5.145396; + + var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var utHours = PAMacros.LocalCivilTimeToUniversalTime(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var dDays = PAMacros.CivilDateToJulianDate(gdateDay, gdateMonth, gdateYear) - PAMacros.CivilDateToJulianDate(0.0, 1, 2010) + utHours / 24; + var sunLongDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var sunMeanAnomalyRad = PAMacros.SunMeanAnomaly(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var lmDeg = PAMacros.UnwindDeg(13.1763966 * dDays + l0); + var mmDeg = PAMacros.UnwindDeg(lmDeg - 0.1114041 * dDays - p0); + var nDeg = PAMacros.UnwindDeg(n0 - (0.0529539 * dDays)); + var evDeg = 1.2739 * ((2.0 * (lmDeg - sunLongDeg) - mmDeg).ToRadians()).Sine(); + var aeDeg = 0.1858 * (sunMeanAnomalyRad).Sine(); + var a3Deg = 0.37 * (sunMeanAnomalyRad).Sine(); + var mmdDeg = mmDeg + evDeg - aeDeg - a3Deg; + var ecDeg = 6.2886 * mmdDeg.ToRadians().Sine(); + var a4Deg = 0.214 * (2.0 * (mmdDeg).ToRadians()).Sine(); + var ldDeg = lmDeg + evDeg + ecDeg - aeDeg + a4Deg; + var vDeg = 0.6583 * (2.0 * (ldDeg - sunLongDeg).ToRadians()).Sine(); + var lddDeg = ldDeg + vDeg; + var ndDeg = nDeg - 0.16 * (sunMeanAnomalyRad).Sine(); + var y = ((lddDeg - ndDeg).ToRadians()).Sine() * i.ToRadians().Cosine(); + var x = (lddDeg - ndDeg).ToRadians().Cosine(); + + var moonLongDeg = PAMacros.UnwindDeg(PAMacros.Degrees(y.AngleTangent2(x)) + ndDeg); + var moonLatDeg = PAMacros.Degrees(((lddDeg - ndDeg).ToRadians().Sine() * i.ToRadians().Sine()).ASine()); + var moonRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(moonLongDeg, 0, 0, moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)); + var moonDecDeg1 = PAMacros.EcDec(moonLongDeg, 0, 0, moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear); + + var moonRAHour = PAMacros.DecimalHoursHour(moonRAHours1); + var moonRAMin = PAMacros.DecimalHoursMinute(moonRAHours1); + var moonRASec = PAMacros.DecimalHoursSecond(moonRAHours1); + var moonDecDeg = PAMacros.DecimalDegreesDegrees(moonDecDeg1); + var moonDecMin = PAMacros.DecimalDegreesMinutes(moonDecDeg1); + var moonDecSec = PAMacros.DecimalDegreesSeconds(moonDecDeg1); + + return (moonRAHour, moonRAMin, moonRASec, moonDecDeg, moonDecMin, moonDecSec); + } + + /// + /// Calculate precise position of the Moon. + /// + /// + /// moonRAHour -- Right ascension of Moon (hour part) + /// moonRAMin -- Right ascension of Moon (minutes part) + /// moonRASec -- Right ascension of Moon (seconds part) + /// moonDecDeg -- Declination of Moon (degrees part) + /// moonDecMin -- Declination of Moon (minutes part) + /// moonDecSec -- Declination of Moon (seconds part) + /// earthMoonDistKM -- Distance from Earth to Moon (km) + /// moonHorParallaxDeg -- Horizontal parallax of Moon (degrees) + /// + public (double moonRAHour, double moonRAMin, double moonRASec, double moonDecDeg, double moonDecMin, double moonDecSec, double earthMoonDistKM, double moonHorParallaxDeg) PrecisePositionOfMoon(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var moonResult = PAMacros.MoonLongLatHP(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var nutationInLongitudeDeg = PAMacros.NutatLong(gdateDay, gdateMonth, gdateYear); + var correctedLongDeg = moonResult.moonLongDeg + nutationInLongitudeDeg; + var earthMoonDistanceKM = 6378.14 / moonResult.moonHorPara.ToRadians().Sine(); + var moonRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(correctedLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)); + var moonDecDeg1 = PAMacros.EcDec(correctedLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear); + + var moonRAHour = PAMacros.DecimalHoursHour(moonRAHours1); + var moonRAMin = PAMacros.DecimalHoursMinute(moonRAHours1); + var moonRASec = PAMacros.DecimalHoursSecond(moonRAHours1); + var moonDecDeg = PAMacros.DecimalDegreesDegrees(moonDecDeg1); + var moonDecMin = PAMacros.DecimalDegreesMinutes(moonDecDeg1); + var moonDecSec = PAMacros.DecimalDegreesSeconds(moonDecDeg1); + var earthMoonDistKM = Math.Round(earthMoonDistanceKM, 0); + var moonHorParallaxDeg = Math.Round(moonResult.moonHorPara, 6); + + return (moonRAHour, moonRAMin, moonRASec, moonDecDeg, moonDecMin, moonDecSec, earthMoonDistKM, moonHorParallaxDeg); + } + + /// + /// Calculate Moon phase and position angle of bright limb. + /// + /// + /// moonPhase -- Phase of Moon, between 0 and 1, where 0 is New and 1 is Full. + /// paBrightLimbDeg -- Position angle of the bright limb (degrees) + /// + public (double moonPhase, double paBrightLimbDeg) MoonPhase(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, PAAccuracyLevel accuracyLevel) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var sunLongDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var moonResult = PAMacros.MoonLongLatHP(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var dRad = (moonResult.moonLongDeg - sunLongDeg).ToRadians(); + + var moonPhase1 = (accuracyLevel == PAAccuracyLevel.Precise) ? PAMacros.MoonPhase(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear) : (1.0 - (dRad).Cosine()) / 2.0; + + var sunRARad = (PAMacros.EcRA(sunLongDeg, 0, 0, 0, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); + var moonRARad = (PAMacros.EcRA(moonResult.moonLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); + var sunDecRad = (PAMacros.EcDec(sunLongDeg, 0, 0, 0, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); + var moonDecRad = (PAMacros.EcDec(moonResult.moonLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); + + var y = (sunDecRad).Cosine() * (sunRARad - moonRARad).Sine(); + var x = (moonDecRad).Cosine() * (sunDecRad).Sine() - (moonDecRad).Sine() * (sunDecRad).Cosine() * (sunRARad - moonRARad).Cosine(); + + var chiDeg = PAMacros.Degrees(y.AngleTangent2(x)); + + var moonPhase = Math.Round(moonPhase1, 2); + var paBrightLimbDeg = Math.Round(chiDeg, 2); + + return (moonPhase, paBrightLimbDeg); + } + + /// + /// Calculate new moon and full moon instances. + /// + /// + /// nmLocalTimeHour -- new Moon instant - local time (hour) + /// nmLocalTimeMin -- new Moon instant - local time (minutes) + /// nmLocalDateDay -- new Moon instance - local date (day) + /// nmLocalDateMonth -- new Moon instance - local date (month) + /// nmLocalDateYear -- new Moon instance - local date (year) + /// fmLocalTimeHour -- full Moon instant - local time (hour) + /// fmLocalTimeMin -- full Moon instant - local time (minutes) + /// fmLocalDateDay -- full Moon instance - local date (day) + /// fmLocalDateMonth -- full Moon instance - local date (month) + /// fmLocalDateYear -- full Moon instance - local date (year) + /// + public (double nmLocalTimeHour, double nmLocalTimeMin, double nmLocalDateDay, int nmLocalDateMonth, int nmLocalDateYear, double fmLocalTimeHour, double fmLocalTimeMin, double fmLocalDateDay, int fmLocalDateMonth, int fmLocalDateYear) TimesOfNewMoonAndFullMoon(bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var jdOfNewMoonDays = PAMacros.NewMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var jdOfFullMoonDays = PAMacros.FullMoon(3, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var gDateOfNewMoonDay = PAMacros.JulianDateDay(jdOfNewMoonDays); + var integerDay1 = gDateOfNewMoonDay.Floor(); + var gDateOfNewMoonMonth = PAMacros.JulianDateMonth(jdOfNewMoonDays); + var gDateOfNewMoonYear = PAMacros.JulianDateYear(jdOfNewMoonDays); + + var gDateOfFullMoonDay = PAMacros.JulianDateDay(jdOfFullMoonDays); + var integerDay2 = gDateOfFullMoonDay.Floor(); + var gDateOfFullMoonMonth = PAMacros.JulianDateMonth(jdOfFullMoonDays); + var gDateOfFullMoonYear = PAMacros.JulianDateYear(jdOfFullMoonDays); + + var utOfNewMoonHours = 24.0 * (gDateOfNewMoonDay - integerDay1); + var utOfFullMoonHours = 24.0 * (gDateOfFullMoonDay - integerDay2); + var lctOfNewMoonHours = PAMacros.UniversalTimeToLocalCivilTime(utOfNewMoonHours + 0.008333, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var lctOfFullMoonHours = PAMacros.UniversalTimeToLocalCivilTime(utOfFullMoonHours + 0.008333, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); + + var nmLocalTimeHour = PAMacros.DecimalHoursHour(lctOfNewMoonHours); + var nmLocalTimeMin = PAMacros.DecimalHoursMinute(lctOfNewMoonHours); + var nmLocalDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfNewMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var nmLocalDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfNewMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var nmLocalDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfNewMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); + var fmLocalTimeHour = PAMacros.DecimalHoursHour(lctOfFullMoonHours); + var fmLocalTimeMin = PAMacros.DecimalHoursMinute(lctOfFullMoonHours); + var fmLocalDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfFullMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); + var fmLocalDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfFullMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); + var fmLocalDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfFullMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); + + return (nmLocalTimeHour, nmLocalTimeMin, nmLocalDateDay, nmLocalDateMonth, nmLocalDateYear, fmLocalTimeHour, fmLocalTimeMin, fmLocalDateDay, fmLocalDateMonth, fmLocalDateYear); + } + + /// + /// Calculate Moon's distance, angular diameter, and horizontal parallax. + /// + /// + /// earth_moon_dist -- Earth-Moon distance (km) + /// ang_diameter_deg -- Angular diameter (degrees part) + /// ang_diameter_min -- Angular diameter (minutes part) + /// hor_parallax_deg -- Horizontal parallax (degrees part) + /// hor_parallax_min -- Horizontal parallax (minutes part) + /// hor_parallax_sec -- Horizontal parallax (seconds part) + /// + public (double earthMoonDist, double angDiameterDeg, double angDiameterMin, double horParallaxDeg, double horParallaxMin, double horParallaxSec) MoonDistAngDiamHorParallax(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var moonDistance = PAMacros.MoonDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var moonAngularDiameter = PAMacros.MoonSize(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var moonHorizontalParallax = PAMacros.MoonHP(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var earthMoonDist = Math.Round(moonDistance, 0); + var angDiameterDeg = PAMacros.DecimalDegreesDegrees(moonAngularDiameter + 0.008333); + var angDiameterMin = PAMacros.DecimalDegreesMinutes(moonAngularDiameter + 0.008333); + var horParallaxDeg = PAMacros.DecimalDegreesDegrees(moonHorizontalParallax); + var horParallaxMin = PAMacros.DecimalDegreesMinutes(moonHorizontalParallax); + var horParallaxSec = PAMacros.DecimalDegreesSeconds(moonHorizontalParallax); + + return (earthMoonDist, angDiameterDeg, angDiameterMin, horParallaxDeg, horParallaxMin, horParallaxSec); + } + + /// + /// Calculate date/time of local moonrise and moonset. /// - public class PAMoon + /// + /// mrLTHour -- Moonrise, local time (hour part) + /// mrLTMin -- Moonrise, local time (minutes part) + /// mrLocalDateDay -- Moonrise, local date (day) + /// mrLocalDateMonth -- Moonrise, local date (month) + /// mrLocalDateYear -- Moonrise, local date (year) + /// mrAzimuthDeg -- Moonrise, azimuth (degrees) + /// msLTHour -- Moonset, local time (hour part) + /// msLTMin -- Moonset, local time (minutes part) + /// msLocalDateDay -- Moonset, local date (day) + /// msLocalDateMonth -- Moonset, local date (month) + /// msLocalDateYear -- Moonset, local date (year) + /// msAzimuthDeg -- Moonset, azimuth (degrees) + /// + public (double mrLTHour, double mrLTMin, double mrLocalDateDay, int mrLocalDateMonth, int mrLocalDateYear, double mrAzimuthDeg, double msLTHour, double msLTMin, double msLocalDateDay, int msLocalDateMonth, int msLocalDateYear, double msAzimuthDeg) MoonriseAndMoonset(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours, double geogLongDeg, double geogLatDeg) { - /// - /// Calculate approximate position of the Moon. - /// - /// - /// moon_ra_hour -- Right ascension of Moon (hour part) - /// moon_ra_min -- Right ascension of Moon (minutes part) - /// moon_ra_sec -- Right ascension of Moon (seconds part) - /// moon_dec_deg -- Declination of Moon (degrees part) - /// moon_dec_min -- Declination of Moon (minutes part) - /// moon_dec_sec -- Declination of Moon (seconds part) - /// - public (double moonRAHour, double moonRAMin, double moonRASec, double moonDecDeg, double moonDecMin, double moonDecSec) ApproximatePositionOfMoon(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var l0 = 91.9293359879052; - var p0 = 130.143076320618; - var n0 = 291.682546643194; - var i = 5.145396; - - var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var utHours = PAMacros.LocalCivilTimeToUniversalTime(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var dDays = PAMacros.CivilDateToJulianDate(gdateDay, gdateMonth, gdateYear) - PAMacros.CivilDateToJulianDate(0.0, 1, 2010) + utHours / 24; - var sunLongDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var sunMeanAnomalyRad = PAMacros.SunMeanAnomaly(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var lmDeg = PAMacros.UnwindDeg(13.1763966 * dDays + l0); - var mmDeg = PAMacros.UnwindDeg(lmDeg - 0.1114041 * dDays - p0); - var nDeg = PAMacros.UnwindDeg(n0 - (0.0529539 * dDays)); - var evDeg = 1.2739 * ((2.0 * (lmDeg - sunLongDeg) - mmDeg).ToRadians()).Sine(); - var aeDeg = 0.1858 * (sunMeanAnomalyRad).Sine(); - var a3Deg = 0.37 * (sunMeanAnomalyRad).Sine(); - var mmdDeg = mmDeg + evDeg - aeDeg - a3Deg; - var ecDeg = 6.2886 * mmdDeg.ToRadians().Sine(); - var a4Deg = 0.214 * (2.0 * (mmdDeg).ToRadians()).Sine(); - var ldDeg = lmDeg + evDeg + ecDeg - aeDeg + a4Deg; - var vDeg = 0.6583 * (2.0 * (ldDeg - sunLongDeg).ToRadians()).Sine(); - var lddDeg = ldDeg + vDeg; - var ndDeg = nDeg - 0.16 * (sunMeanAnomalyRad).Sine(); - var y = ((lddDeg - ndDeg).ToRadians()).Sine() * i.ToRadians().Cosine(); - var x = (lddDeg - ndDeg).ToRadians().Cosine(); - - var moonLongDeg = PAMacros.UnwindDeg(PAMacros.Degrees(y.AngleTangent2(x)) + ndDeg); - var moonLatDeg = PAMacros.Degrees(((lddDeg - ndDeg).ToRadians().Sine() * i.ToRadians().Sine()).ASine()); - var moonRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(moonLongDeg, 0, 0, moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)); - var moonDecDeg1 = PAMacros.EcDec(moonLongDeg, 0, 0, moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear); - - var moonRAHour = PAMacros.DecimalHoursHour(moonRAHours1); - var moonRAMin = PAMacros.DecimalHoursMinute(moonRAHours1); - var moonRASec = PAMacros.DecimalHoursSecond(moonRAHours1); - var moonDecDeg = PAMacros.DecimalDegreesDegrees(moonDecDeg1); - var moonDecMin = PAMacros.DecimalDegreesMinutes(moonDecDeg1); - var moonDecSec = PAMacros.DecimalDegreesSeconds(moonDecDeg1); - - return (moonRAHour, moonRAMin, moonRASec, moonDecDeg, moonDecMin, moonDecSec); - } - - /// - /// Calculate precise position of the Moon. - /// - /// - /// moonRAHour -- Right ascension of Moon (hour part) - /// moonRAMin -- Right ascension of Moon (minutes part) - /// moonRASec -- Right ascension of Moon (seconds part) - /// moonDecDeg -- Declination of Moon (degrees part) - /// moonDecMin -- Declination of Moon (minutes part) - /// moonDecSec -- Declination of Moon (seconds part) - /// earthMoonDistKM -- Distance from Earth to Moon (km) - /// moonHorParallaxDeg -- Horizontal parallax of Moon (degrees) - /// - public (double moonRAHour, double moonRAMin, double moonRASec, double moonDecDeg, double moonDecMin, double moonDecSec, double earthMoonDistKM, double moonHorParallaxDeg) PrecisePositionOfMoon(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var moonResult = PAMacros.MoonLongLatHP(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var nutationInLongitudeDeg = PAMacros.NutatLong(gdateDay, gdateMonth, gdateYear); - var correctedLongDeg = moonResult.moonLongDeg + nutationInLongitudeDeg; - var earthMoonDistanceKM = 6378.14 / moonResult.moonHorPara.ToRadians().Sine(); - var moonRAHours1 = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(correctedLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)); - var moonDecDeg1 = PAMacros.EcDec(correctedLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear); - - var moonRAHour = PAMacros.DecimalHoursHour(moonRAHours1); - var moonRAMin = PAMacros.DecimalHoursMinute(moonRAHours1); - var moonRASec = PAMacros.DecimalHoursSecond(moonRAHours1); - var moonDecDeg = PAMacros.DecimalDegreesDegrees(moonDecDeg1); - var moonDecMin = PAMacros.DecimalDegreesMinutes(moonDecDeg1); - var moonDecSec = PAMacros.DecimalDegreesSeconds(moonDecDeg1); - var earthMoonDistKM = Math.Round(earthMoonDistanceKM, 0); - var moonHorParallaxDeg = Math.Round(moonResult.moonHorPara, 6); - - return (moonRAHour, moonRAMin, moonRASec, moonDecDeg, moonDecMin, moonDecSec, earthMoonDistKM, moonHorParallaxDeg); - } - - /// - /// Calculate Moon phase and position angle of bright limb. - /// - /// - /// moonPhase -- Phase of Moon, between 0 and 1, where 0 is New and 1 is Full. - /// paBrightLimbDeg -- Position angle of the bright limb (degrees) - /// - public (double moonPhase, double paBrightLimbDeg) MoonPhase(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, PAAccuracyLevel accuracyLevel) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var sunLongDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var moonResult = PAMacros.MoonLongLatHP(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var dRad = (moonResult.moonLongDeg - sunLongDeg).ToRadians(); - - var moonPhase1 = (accuracyLevel == PAAccuracyLevel.Precise) ? PAMacros.MoonPhase(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear) : (1.0 - (dRad).Cosine()) / 2.0; - - var sunRARad = (PAMacros.EcRA(sunLongDeg, 0, 0, 0, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); - var moonRARad = (PAMacros.EcRA(moonResult.moonLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); - var sunDecRad = (PAMacros.EcDec(sunLongDeg, 0, 0, 0, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); - var moonDecRad = (PAMacros.EcDec(moonResult.moonLongDeg, 0, 0, moonResult.moonLatDeg, 0, 0, gdateDay, gdateMonth, gdateYear)).ToRadians(); - - var y = (sunDecRad).Cosine() * (sunRARad - moonRARad).Sine(); - var x = (moonDecRad).Cosine() * (sunDecRad).Sine() - (moonDecRad).Sine() * (sunDecRad).Cosine() * (sunRARad - moonRARad).Cosine(); - - var chiDeg = PAMacros.Degrees(y.AngleTangent2(x)); - - var moonPhase = Math.Round(moonPhase1, 2); - var paBrightLimbDeg = Math.Round(chiDeg, 2); - - return (moonPhase, paBrightLimbDeg); - } - - /// - /// Calculate new moon and full moon instances. - /// - /// - /// nmLocalTimeHour -- new Moon instant - local time (hour) - /// nmLocalTimeMin -- new Moon instant - local time (minutes) - /// nmLocalDateDay -- new Moon instance - local date (day) - /// nmLocalDateMonth -- new Moon instance - local date (month) - /// nmLocalDateYear -- new Moon instance - local date (year) - /// fmLocalTimeHour -- full Moon instant - local time (hour) - /// fmLocalTimeMin -- full Moon instant - local time (minutes) - /// fmLocalDateDay -- full Moon instance - local date (day) - /// fmLocalDateMonth -- full Moon instance - local date (month) - /// fmLocalDateYear -- full Moon instance - local date (year) - /// - public (double nmLocalTimeHour, double nmLocalTimeMin, double nmLocalDateDay, int nmLocalDateMonth, int nmLocalDateYear, double fmLocalTimeHour, double fmLocalTimeMin, double fmLocalDateDay, int fmLocalDateMonth, int fmLocalDateYear) TimesOfNewMoonAndFullMoon(bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var jdOfNewMoonDays = PAMacros.NewMoon(daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var jdOfFullMoonDays = PAMacros.FullMoon(3, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var gDateOfNewMoonDay = PAMacros.JulianDateDay(jdOfNewMoonDays); - var integerDay1 = gDateOfNewMoonDay.Floor(); - var gDateOfNewMoonMonth = PAMacros.JulianDateMonth(jdOfNewMoonDays); - var gDateOfNewMoonYear = PAMacros.JulianDateYear(jdOfNewMoonDays); - - var gDateOfFullMoonDay = PAMacros.JulianDateDay(jdOfFullMoonDays); - var integerDay2 = gDateOfFullMoonDay.Floor(); - var gDateOfFullMoonMonth = PAMacros.JulianDateMonth(jdOfFullMoonDays); - var gDateOfFullMoonYear = PAMacros.JulianDateYear(jdOfFullMoonDays); - - var utOfNewMoonHours = 24.0 * (gDateOfNewMoonDay - integerDay1); - var utOfFullMoonHours = 24.0 * (gDateOfFullMoonDay - integerDay2); - var lctOfNewMoonHours = PAMacros.UniversalTimeToLocalCivilTime(utOfNewMoonHours + 0.008333, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var lctOfFullMoonHours = PAMacros.UniversalTimeToLocalCivilTime(utOfFullMoonHours + 0.008333, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); - - var nmLocalTimeHour = PAMacros.DecimalHoursHour(lctOfNewMoonHours); - var nmLocalTimeMin = PAMacros.DecimalHoursMinute(lctOfNewMoonHours); - var nmLocalDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfNewMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var nmLocalDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfNewMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var nmLocalDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfNewMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay1, gDateOfNewMoonMonth, gDateOfNewMoonYear); - var fmLocalTimeHour = PAMacros.DecimalHoursHour(lctOfFullMoonHours); - var fmLocalTimeMin = PAMacros.DecimalHoursMinute(lctOfFullMoonHours); - var fmLocalDateDay = PAMacros.UniversalTime_LocalCivilDay(utOfFullMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); - var fmLocalDateMonth = PAMacros.UniversalTime_LocalCivilMonth(utOfFullMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); - var fmLocalDateYear = PAMacros.UniversalTime_LocalCivilYear(utOfFullMoonHours, 0, 0, daylightSaving, zoneCorrectionHours, integerDay2, gDateOfFullMoonMonth, gDateOfFullMoonYear); - - return (nmLocalTimeHour, nmLocalTimeMin, nmLocalDateDay, nmLocalDateMonth, nmLocalDateYear, fmLocalTimeHour, fmLocalTimeMin, fmLocalDateDay, fmLocalDateMonth, fmLocalDateYear); - } - - /// - /// Calculate Moon's distance, angular diameter, and horizontal parallax. - /// - /// - /// earth_moon_dist -- Earth-Moon distance (km) - /// ang_diameter_deg -- Angular diameter (degrees part) - /// ang_diameter_min -- Angular diameter (minutes part) - /// hor_parallax_deg -- Horizontal parallax (degrees part) - /// hor_parallax_min -- Horizontal parallax (minutes part) - /// hor_parallax_sec -- Horizontal parallax (seconds part) - /// - public (double earthMoonDist, double angDiameterDeg, double angDiameterMin, double horParallaxDeg, double horParallaxMin, double horParallaxSec) MoonDistAngDiamHorParallax(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var moonDistance = PAMacros.MoonDist(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var moonAngularDiameter = PAMacros.MoonSize(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var moonHorizontalParallax = PAMacros.MoonHP(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var earthMoonDist = Math.Round(moonDistance, 0); - var angDiameterDeg = PAMacros.DecimalDegreesDegrees(moonAngularDiameter + 0.008333); - var angDiameterMin = PAMacros.DecimalDegreesMinutes(moonAngularDiameter + 0.008333); - var horParallaxDeg = PAMacros.DecimalDegreesDegrees(moonHorizontalParallax); - var horParallaxMin = PAMacros.DecimalDegreesMinutes(moonHorizontalParallax); - var horParallaxSec = PAMacros.DecimalDegreesSeconds(moonHorizontalParallax); - - return (earthMoonDist, angDiameterDeg, angDiameterMin, horParallaxDeg, horParallaxMin, horParallaxSec); - } - - /// - /// Calculate date/time of local moonrise and moonset. - /// - /// - /// mrLTHour -- Moonrise, local time (hour part) - /// mrLTMin -- Moonrise, local time (minutes part) - /// mrLocalDateDay -- Moonrise, local date (day) - /// mrLocalDateMonth -- Moonrise, local date (month) - /// mrLocalDateYear -- Moonrise, local date (year) - /// mrAzimuthDeg -- Moonrise, azimuth (degrees) - /// msLTHour -- Moonset, local time (hour part) - /// msLTMin -- Moonset, local time (minutes part) - /// msLocalDateDay -- Moonset, local date (day) - /// msLocalDateMonth -- Moonset, local date (month) - /// msLocalDateYear -- Moonset, local date (year) - /// msAzimuthDeg -- Moonset, azimuth (degrees) - /// - public (double mrLTHour, double mrLTMin, double mrLocalDateDay, int mrLocalDateMonth, int mrLocalDateYear, double mrAzimuthDeg, double msLTHour, double msLTMin, double msLocalDateDay, int msLocalDateMonth, int msLocalDateYear, double msAzimuthDeg) MoonriseAndMoonset(double localDateDay, int localDateMonth, int localDateYear, bool isDaylightSaving, int zoneCorrectionHours, double geogLongDeg, double geogLatDeg) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var localTimeOfMoonriseHours = PAMacros.MoonRiseLCT(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); - var moonRiseLCResult = PAMacros.MoonRiseLcDMY(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); - var localAzimuthDeg1 = PAMacros.MoonRiseAz(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); - - var localTimeOfMoonsetHours = PAMacros.MoonSetLCT(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); - var moonSetLCResult = PAMacros.MoonSetLcDMY(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); - var localAzimuthDeg2 = PAMacros.MoonSetAz(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); - - var mrLTHour = PAMacros.DecimalHoursHour(localTimeOfMoonriseHours + 0.008333); - var mrLTMin = PAMacros.DecimalHoursMinute(localTimeOfMoonriseHours + 0.008333); - var mrLocalDateDay = moonRiseLCResult.dy1; - var mrLocalDateMonth = moonRiseLCResult.mn1; - var mrLocalDateYear = moonRiseLCResult.yr1; - var mrAzimuthDeg = Math.Round(localAzimuthDeg1, 2); - var msLTHour = PAMacros.DecimalHoursHour(localTimeOfMoonsetHours + 0.008333); - var msLTMin = PAMacros.DecimalHoursMinute(localTimeOfMoonsetHours + 0.008333); - var msLocalDateDay = moonSetLCResult.dy1; - var msLocalDateMonth = moonSetLCResult.mn1; - var msLocalDateYear = moonSetLCResult.yr1; - var msAzimuthDeg = Math.Round(localAzimuthDeg2, 2); - - return (mrLTHour, mrLTMin, mrLocalDateDay, mrLocalDateMonth, mrLocalDateYear, mrAzimuthDeg, msLTHour, msLTMin, msLocalDateDay, msLocalDateMonth, msLocalDateYear, msAzimuthDeg); - } + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var localTimeOfMoonriseHours = PAMacros.MoonRiseLCT(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); + var moonRiseLCResult = PAMacros.MoonRiseLcDMY(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); + var localAzimuthDeg1 = PAMacros.MoonRiseAz(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); + + var localTimeOfMoonsetHours = PAMacros.MoonSetLCT(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); + var moonSetLCResult = PAMacros.MoonSetLcDMY(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); + var localAzimuthDeg2 = PAMacros.MoonSetAz(localDateDay, localDateMonth, localDateYear, daylightSaving, zoneCorrectionHours, geogLongDeg, geogLatDeg); + + var mrLTHour = PAMacros.DecimalHoursHour(localTimeOfMoonriseHours + 0.008333); + var mrLTMin = PAMacros.DecimalHoursMinute(localTimeOfMoonriseHours + 0.008333); + var mrLocalDateDay = moonRiseLCResult.dy1; + var mrLocalDateMonth = moonRiseLCResult.mn1; + var mrLocalDateYear = moonRiseLCResult.yr1; + var mrAzimuthDeg = Math.Round(localAzimuthDeg1, 2); + var msLTHour = PAMacros.DecimalHoursHour(localTimeOfMoonsetHours + 0.008333); + var msLTMin = PAMacros.DecimalHoursMinute(localTimeOfMoonsetHours + 0.008333); + var msLocalDateDay = moonSetLCResult.dy1; + var msLocalDateMonth = moonSetLCResult.mn1; + var msLocalDateYear = moonSetLCResult.yr1; + var msAzimuthDeg = Math.Round(localAzimuthDeg2, 2); + + return (mrLTHour, mrLTMin, mrLocalDateDay, mrLocalDateMonth, mrLocalDateYear, mrAzimuthDeg, msLTHour, msLTMin, msLocalDateDay, msLocalDateMonth, msLocalDateYear, msAzimuthDeg); } -} \ No newline at end of file +} diff --git a/PALib/PAPlanet.cs b/PALib/PAPlanet.cs index 0fcde3d..7881a26 100644 --- a/PALib/PAPlanet.cs +++ b/PALib/PAPlanet.cs @@ -2,145 +2,144 @@ using PALib.Data; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Planet calculations. +/// +public class PAPlanet { /// - /// Planet calculations. + /// Calculate approximate position of a planet. + /// + public (double planetRAHour, double planetRAMin, double planetRASec, double planetDecDeg, double planetDecMin, double planetDecSec) ApproximatePositionOfPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var planetInfo = PlanetInfo.GetPlanetInfo(planetName); + + var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var utHours = PAMacros.LocalCivilTimeToUniversalTime(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var dDays = PAMacros.CivilDateToJulianDate(gdateDay + (utHours / 24), gdateMonth, gdateYear) - PAMacros.CivilDateToJulianDate(0, 1, 2010); + var npDeg1 = 360 * dDays / (365.242191 * planetInfo.tp_PeriodOrbit); + var npDeg2 = npDeg1 - 360 * (npDeg1 / 360).Floor(); + var mpDeg = npDeg2 + planetInfo.long_LongitudeEpoch - planetInfo.peri_LongitudePerihelion; + var lpDeg1 = npDeg2 + (360 * planetInfo.ecc_EccentricityOrbit * mpDeg.ToRadians().Sine() / Math.PI) + planetInfo.long_LongitudeEpoch; + var lpDeg2 = lpDeg1 - 360 * (lpDeg1 / 360).Floor(); + var planetTrueAnomalyDeg = lpDeg2 - planetInfo.peri_LongitudePerihelion; + var rAU = planetInfo.axis_AxisOrbit * (1 - Math.Pow(planetInfo.ecc_EccentricityOrbit, 2)) / (1 + planetInfo.ecc_EccentricityOrbit * planetTrueAnomalyDeg.ToRadians().Cosine()); + + var earthInfo = PlanetInfo.GetPlanetInfo("Earth"); + + var neDeg1 = 360 * dDays / (365.242191 * earthInfo.tp_PeriodOrbit); + var neDeg2 = neDeg1 - 360 * (neDeg1 / 360).Floor(); + var meDeg = neDeg2 + earthInfo.long_LongitudeEpoch - earthInfo.peri_LongitudePerihelion; + var leDeg1 = neDeg2 + earthInfo.long_LongitudeEpoch + 360 * earthInfo.ecc_EccentricityOrbit * meDeg.ToRadians().Sine() / Math.PI; + var leDeg2 = leDeg1 - 360 * (leDeg1 / 360).Floor(); + var earthTrueAnomalyDeg = leDeg2 - earthInfo.peri_LongitudePerihelion; + var rAU2 = earthInfo.axis_AxisOrbit * (1 - Math.Pow(earthInfo.ecc_EccentricityOrbit, 2)) / (1 + earthInfo.ecc_EccentricityOrbit * earthTrueAnomalyDeg.ToRadians().Cosine()); + var lpNodeRad = (lpDeg2 - planetInfo.node_LongitudeAscendingNode).ToRadians(); + var psiRad = ((lpNodeRad).Sine() * planetInfo.incl_OrbitalInclination.ToRadians().Sine()).ASine(); + var y = lpNodeRad.Sine() * planetInfo.incl_OrbitalInclination.ToRadians().Cosine(); + var x = lpNodeRad.Cosine(); + var ldDeg = PAMacros.Degrees(y.AngleTangent2(x)) + planetInfo.node_LongitudeAscendingNode; + var rdAU = rAU * psiRad.Cosine(); + var leLdRad = (leDeg2 - ldDeg).ToRadians(); + var atan2Type1 = (rdAU * leLdRad.Sine()).AngleTangent2(rAU2 - rdAU * leLdRad.Cosine()); + var atan2Type2 = (rAU2 * (-leLdRad).Sine()).AngleTangent2(rdAU - rAU2 * leLdRad.Cosine()); + var aRad = (rdAU < 1) ? atan2Type1 : atan2Type2; + var lamdaDeg1 = (rdAU < 1) ? 180 + leDeg2 + PAMacros.Degrees(aRad) : PAMacros.Degrees(aRad) + ldDeg; + var lamdaDeg2 = lamdaDeg1 - 360 * (lamdaDeg1 / 360).Floor(); + var betaDeg = PAMacros.Degrees((rdAU * psiRad.Tangent() * ((lamdaDeg2 - ldDeg).ToRadians()).Sine() / (rAU2 * (-leLdRad).Sine())).AngleTangent()); + var raHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(lamdaDeg2, 0, 0, betaDeg, 0, 0, gdateDay, gdateMonth, gdateYear)); + var decDeg = PAMacros.EcDec(lamdaDeg2, 0, 0, betaDeg, 0, 0, gdateDay, gdateMonth, gdateYear); + + var planetRAHour = PAMacros.DecimalHoursHour(raHours); + var planetRAMin = PAMacros.DecimalHoursMinute(raHours); + var planetRASec = PAMacros.DecimalHoursSecond(raHours); + var planetDecDeg = PAMacros.DecimalDegreesDegrees(decDeg); + var planetDecMin = PAMacros.DecimalDegreesMinutes(decDeg); + var planetDecSec = PAMacros.DecimalDegreesSeconds(decDeg); + + return (planetRAHour, planetRAMin, planetRASec, planetDecDeg, planetDecMin, planetDecSec); + } + + /// + /// Calculate precise position of a planet. + /// + public (double planetRAHour, double planetRAMin, double planetRASec, double planetDecDeg, double planetDecMin, double planetDecSec) PrecisePositionOfPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var coordinateResults = PAMacros.PlanetCoordinates(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, planetName); + + var planetRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(coordinateResults.planetLongitude, 0, 0, coordinateResults.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear)); + var planetDecDeg1 = PAMacros.EcDec(coordinateResults.planetLongitude, 0, 0, coordinateResults.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear); + + var planetRAHour = PAMacros.DecimalHoursHour(planetRAHours); + var planetRAMin = PAMacros.DecimalHoursMinute(planetRAHours); + var planetRASec = PAMacros.DecimalHoursSecond(planetRAHours); + var planetDecDeg = PAMacros.DecimalDegreesDegrees(planetDecDeg1); + var planetDecMin = PAMacros.DecimalDegreesMinutes(planetDecDeg1); + var planetDecSec = PAMacros.DecimalDegreesSeconds(planetDecDeg1); + + return (planetRAHour, planetRAMin, planetRASec, planetDecDeg, planetDecMin, planetDecSec); + } + + /// + /// Calculate several visual aspects of a planet. /// - public class PAPlanet + /// + /// distance_au -- Planet's distance from Earth, in AU. + /// ang_dia_arcsec -- Angular diameter of the planet. + /// phase -- Illuminated fraction of the planet. + /// light_time_hour -- Light travel time from planet to Earth, hour part. + /// light_time_minutes -- Light travel time from planet to Earth, minutes part. + /// light_time_seconds -- Light travel time from planet to Earth, seconds part. + /// pos_angle_bright_limb_deg -- Position-angle of the bright limb. + /// approximate_magnitude -- Apparent brightness of the planet. + /// + public (double distanceAU, double angDiaArcsec, double phase, double lightTimeHour, double lightTimeMinutes, double lightTimeSeconds, double posAngleBrightLimbDeg, double approximateMagnitude) VisualAspectsOfAPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName) { - /// - /// Calculate approximate position of a planet. - /// - public (double planetRAHour, double planetRAMin, double planetRASec, double planetDecDeg, double planetDecMin, double planetDecSec) ApproximatePositionOfPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var planetInfo = PlanetInfo.GetPlanetInfo(planetName); - - var gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var utHours = PAMacros.LocalCivilTimeToUniversalTime(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var dDays = PAMacros.CivilDateToJulianDate(gdateDay + (utHours / 24), gdateMonth, gdateYear) - PAMacros.CivilDateToJulianDate(0, 1, 2010); - var npDeg1 = 360 * dDays / (365.242191 * planetInfo.tp_PeriodOrbit); - var npDeg2 = npDeg1 - 360 * (npDeg1 / 360).Floor(); - var mpDeg = npDeg2 + planetInfo.long_LongitudeEpoch - planetInfo.peri_LongitudePerihelion; - var lpDeg1 = npDeg2 + (360 * planetInfo.ecc_EccentricityOrbit * mpDeg.ToRadians().Sine() / Math.PI) + planetInfo.long_LongitudeEpoch; - var lpDeg2 = lpDeg1 - 360 * (lpDeg1 / 360).Floor(); - var planetTrueAnomalyDeg = lpDeg2 - planetInfo.peri_LongitudePerihelion; - var rAU = planetInfo.axis_AxisOrbit * (1 - Math.Pow(planetInfo.ecc_EccentricityOrbit, 2)) / (1 + planetInfo.ecc_EccentricityOrbit * planetTrueAnomalyDeg.ToRadians().Cosine()); - - var earthInfo = PlanetInfo.GetPlanetInfo("Earth"); - - var neDeg1 = 360 * dDays / (365.242191 * earthInfo.tp_PeriodOrbit); - var neDeg2 = neDeg1 - 360 * (neDeg1 / 360).Floor(); - var meDeg = neDeg2 + earthInfo.long_LongitudeEpoch - earthInfo.peri_LongitudePerihelion; - var leDeg1 = neDeg2 + earthInfo.long_LongitudeEpoch + 360 * earthInfo.ecc_EccentricityOrbit * meDeg.ToRadians().Sine() / Math.PI; - var leDeg2 = leDeg1 - 360 * (leDeg1 / 360).Floor(); - var earthTrueAnomalyDeg = leDeg2 - earthInfo.peri_LongitudePerihelion; - var rAU2 = earthInfo.axis_AxisOrbit * (1 - Math.Pow(earthInfo.ecc_EccentricityOrbit, 2)) / (1 + earthInfo.ecc_EccentricityOrbit * earthTrueAnomalyDeg.ToRadians().Cosine()); - var lpNodeRad = (lpDeg2 - planetInfo.node_LongitudeAscendingNode).ToRadians(); - var psiRad = ((lpNodeRad).Sine() * planetInfo.incl_OrbitalInclination.ToRadians().Sine()).ASine(); - var y = lpNodeRad.Sine() * planetInfo.incl_OrbitalInclination.ToRadians().Cosine(); - var x = lpNodeRad.Cosine(); - var ldDeg = PAMacros.Degrees(y.AngleTangent2(x)) + planetInfo.node_LongitudeAscendingNode; - var rdAU = rAU * psiRad.Cosine(); - var leLdRad = (leDeg2 - ldDeg).ToRadians(); - var atan2Type1 = (rdAU * leLdRad.Sine()).AngleTangent2(rAU2 - rdAU * leLdRad.Cosine()); - var atan2Type2 = (rAU2 * (-leLdRad).Sine()).AngleTangent2(rdAU - rAU2 * leLdRad.Cosine()); - var aRad = (rdAU < 1) ? atan2Type1 : atan2Type2; - var lamdaDeg1 = (rdAU < 1) ? 180 + leDeg2 + PAMacros.Degrees(aRad) : PAMacros.Degrees(aRad) + ldDeg; - var lamdaDeg2 = lamdaDeg1 - 360 * (lamdaDeg1 / 360).Floor(); - var betaDeg = PAMacros.Degrees((rdAU * psiRad.Tangent() * ((lamdaDeg2 - ldDeg).ToRadians()).Sine() / (rAU2 * (-leLdRad).Sine())).AngleTangent()); - var raHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(lamdaDeg2, 0, 0, betaDeg, 0, 0, gdateDay, gdateMonth, gdateYear)); - var decDeg = PAMacros.EcDec(lamdaDeg2, 0, 0, betaDeg, 0, 0, gdateDay, gdateMonth, gdateYear); - - var planetRAHour = PAMacros.DecimalHoursHour(raHours); - var planetRAMin = PAMacros.DecimalHoursMinute(raHours); - var planetRASec = PAMacros.DecimalHoursSecond(raHours); - var planetDecDeg = PAMacros.DecimalDegreesDegrees(decDeg); - var planetDecMin = PAMacros.DecimalDegreesMinutes(decDeg); - var planetDecSec = PAMacros.DecimalDegreesSeconds(decDeg); - - return (planetRAHour, planetRAMin, planetRASec, planetDecDeg, planetDecMin, planetDecSec); - } - - /// - /// Calculate precise position of a planet. - /// - public (double planetRAHour, double planetRAMin, double planetRASec, double planetDecDeg, double planetDecMin, double planetDecSec) PrecisePositionOfPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var coordinateResults = PAMacros.PlanetCoordinates(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, planetName); - - var planetRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(coordinateResults.planetLongitude, 0, 0, coordinateResults.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear)); - var planetDecDeg1 = PAMacros.EcDec(coordinateResults.planetLongitude, 0, 0, coordinateResults.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear); - - var planetRAHour = PAMacros.DecimalHoursHour(planetRAHours); - var planetRAMin = PAMacros.DecimalHoursMinute(planetRAHours); - var planetRASec = PAMacros.DecimalHoursSecond(planetRAHours); - var planetDecDeg = PAMacros.DecimalDegreesDegrees(planetDecDeg1); - var planetDecMin = PAMacros.DecimalDegreesMinutes(planetDecDeg1); - var planetDecSec = PAMacros.DecimalDegreesSeconds(planetDecDeg1); - - return (planetRAHour, planetRAMin, planetRASec, planetDecDeg, planetDecMin, planetDecSec); - } - - /// - /// Calculate several visual aspects of a planet. - /// - /// - /// distance_au -- Planet's distance from Earth, in AU. - /// ang_dia_arcsec -- Angular diameter of the planet. - /// phase -- Illuminated fraction of the planet. - /// light_time_hour -- Light travel time from planet to Earth, hour part. - /// light_time_minutes -- Light travel time from planet to Earth, minutes part. - /// light_time_seconds -- Light travel time from planet to Earth, seconds part. - /// pos_angle_bright_limb_deg -- Position-angle of the bright limb. - /// approximate_magnitude -- Apparent brightness of the planet. - /// - public (double distanceAU, double angDiaArcsec, double phase, double lightTimeHour, double lightTimeMinutes, double lightTimeSeconds, double posAngleBrightLimbDeg, double approximateMagnitude) VisualAspectsOfAPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - - var planetCoordInfo = PAMacros.PlanetCoordinates(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, planetName); - - var planetRARad = (PAMacros.EcRA(planetCoordInfo.planetLongitude, 0, 0, planetCoordInfo.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear)).ToRadians(); - var planetDecRad = (PAMacros.EcDec(planetCoordInfo.planetLongitude, 0, 0, planetCoordInfo.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear)).ToRadians(); - - var lightTravelTimeHours = planetCoordInfo.planetDistanceAU * 0.1386; - var planetInfo = PlanetInfo.GetPlanetInfo(planetName); - var angularDiameterArcsec = planetInfo.theta0_AngularDiameter / planetCoordInfo.planetDistanceAU; - var phase1 = 0.5 * (1.0 + ((planetCoordInfo.planetLongitude - planetCoordInfo.planetHLong1).ToRadians()).Cosine()); - - var sunEclLongDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); - var sunRARad = (PAMacros.EcRA(sunEclLongDeg, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)).ToRadians(); - var sunDecRad = (PAMacros.EcDec(sunEclLongDeg, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)).ToRadians(); - - var y = (sunDecRad).Cosine() * (sunRARad - planetRARad).Sine(); - var x = (planetDecRad).Cosine() * (sunDecRad).Sine() - (planetDecRad).Sine() * (sunDecRad).Cosine() * (sunRARad - planetRARad).Cosine(); - - var chiDeg = PAMacros.Degrees(y.AngleTangent2(x)); - var radiusVectorAU = planetCoordInfo.planetRVect; - var approximateMagnitude1 = 5.0 * (radiusVectorAU * planetCoordInfo.planetDistanceAU / (phase1).SquareRoot()).Log10() + planetInfo.v0_VisualMagnitude; - - var distanceAU = Math.Round(planetCoordInfo.planetDistanceAU, 5); - var angDiaArcsec = Math.Round(angularDiameterArcsec, 1); - var phase = Math.Round(phase1, 2); - var lightTimeHour = PAMacros.DecimalHoursHour(lightTravelTimeHours); - var lightTimeMinutes = PAMacros.DecimalHoursMinute(lightTravelTimeHours); - var lightTimeSeconds = PAMacros.DecimalHoursSecond(lightTravelTimeHours); - var posAngleBrightLimbDeg = Math.Round(chiDeg, 1); - var approximateMagnitude = Math.Round(approximateMagnitude1, 1); - - return (distanceAU, angDiaArcsec, phase, lightTimeHour, lightTimeMinutes, lightTimeSeconds, posAngleBrightLimbDeg, approximateMagnitude); - } + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + + var planetCoordInfo = PAMacros.PlanetCoordinates(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, planetName); + + var planetRARad = (PAMacros.EcRA(planetCoordInfo.planetLongitude, 0, 0, planetCoordInfo.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear)).ToRadians(); + var planetDecRad = (PAMacros.EcDec(planetCoordInfo.planetLongitude, 0, 0, planetCoordInfo.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear)).ToRadians(); + + var lightTravelTimeHours = planetCoordInfo.planetDistanceAU * 0.1386; + var planetInfo = PlanetInfo.GetPlanetInfo(planetName); + var angularDiameterArcsec = planetInfo.theta0_AngularDiameter / planetCoordInfo.planetDistanceAU; + var phase1 = 0.5 * (1.0 + ((planetCoordInfo.planetLongitude - planetCoordInfo.planetHLong1).ToRadians()).Cosine()); + + var sunEclLongDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear); + var sunRARad = (PAMacros.EcRA(sunEclLongDeg, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)).ToRadians(); + var sunDecRad = (PAMacros.EcDec(sunEclLongDeg, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear)).ToRadians(); + + var y = (sunDecRad).Cosine() * (sunRARad - planetRARad).Sine(); + var x = (planetDecRad).Cosine() * (sunDecRad).Sine() - (planetDecRad).Sine() * (sunDecRad).Cosine() * (sunRARad - planetRARad).Cosine(); + + var chiDeg = PAMacros.Degrees(y.AngleTangent2(x)); + var radiusVectorAU = planetCoordInfo.planetRVect; + var approximateMagnitude1 = 5.0 * (radiusVectorAU * planetCoordInfo.planetDistanceAU / (phase1).SquareRoot()).Log10() + planetInfo.v0_VisualMagnitude; + + var distanceAU = Math.Round(planetCoordInfo.planetDistanceAU, 5); + var angDiaArcsec = Math.Round(angularDiameterArcsec, 1); + var phase = Math.Round(phase1, 2); + var lightTimeHour = PAMacros.DecimalHoursHour(lightTravelTimeHours); + var lightTimeMinutes = PAMacros.DecimalHoursMinute(lightTravelTimeHours); + var lightTimeSeconds = PAMacros.DecimalHoursSecond(lightTravelTimeHours); + var posAngleBrightLimbDeg = Math.Round(chiDeg, 1); + var approximateMagnitude = Math.Round(approximateMagnitude1, 1); + + return (distanceAU, angDiaArcsec, phase, lightTimeHour, lightTimeMinutes, lightTimeSeconds, posAngleBrightLimbDeg, approximateMagnitude); } -} \ No newline at end of file +} diff --git a/PALib/PASun.cs b/PALib/PASun.cs index f40b09a..5c11192 100644 --- a/PALib/PASun.cs +++ b/PALib/PASun.cs @@ -1,240 +1,239 @@ using System; using PALib.Helpers; -namespace PALib +namespace PALib; + +/// +/// Sun calculations. +/// +public class PASun { /// - /// Sun calculations. + /// Calculate approximate position of the sun for a local date and time. + /// + /// Local civil time, in hours. + /// Local civil time, in minutes. + /// Local civil time, in seconds. + /// Local day, day part. + /// Local day, month part. + /// Local day, year part. + /// Is daylight savings in effect? + /// Time zone correction, in hours. + /// + /// sunRAHour -- Right Ascension of Sun, hour part + /// sunRAMin -- Right Ascension of Sun, minutes part + /// sunRASec -- Right Ascension of Sun, seconds part + /// sunDecDeg -- Declination of Sun, degrees part + /// sunDecMin -- Declination of Sun, minutes part + /// sunDecSec -- Declination of Sun, seconds part + /// + public (double sunRAHour, double sunRAMin, double sunRASec, double sunDecDeg, double sunDecMin, double sunDecSec) ApproximatePositionOfSun(double lctHours, double lctMinutes, double lctSeconds, double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection) + { + var daylightSaving = (isDaylightSaving == true) ? 1 : 0; + + var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var utHours = PAMacros.LocalCivilTimeToUniversalTime(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var utDays = utHours / 24; + var jdDays = PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) + utDays; + var dDays = jdDays - PAMacros.CivilDateToJulianDate(0, 1, 2010); + var nDeg = 360 * dDays / 365.242191; + var mDeg1 = nDeg + PAMacros.SunELong(0, 1, 2010) - PAMacros.SunPeri(0, 1, 2010); + var mDeg2 = mDeg1 - 360 * (mDeg1 / 360).Floor(); + var eCDeg = 360 * PAMacros.SunEcc(0, 1, 2010) * mDeg2.ToRadians().Sine() / Math.PI; + var lSDeg1 = nDeg + eCDeg + PAMacros.SunELong(0, 1, 2010); + var lSDeg2 = lSDeg1 - 360 * (lSDeg1 / 360).Floor(); + var raDeg = PAMacros.EcRA(lSDeg2, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); + var raHours = PAMacros.DecimalDegreesToDegreeHours(raDeg); + var decDeg = PAMacros.EcDec(lSDeg2, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); + + var sunRAHour = PAMacros.DecimalHoursHour(raHours); + var sunRAMin = PAMacros.DecimalHoursMinute(raHours); + var sunRASec = PAMacros.DecimalHoursSecond(raHours); + var sunDecDeg = PAMacros.DecimalDegreesDegrees(decDeg); + var sunDecMin = PAMacros.DecimalDegreesMinutes(decDeg); + var sunDecSec = PAMacros.DecimalDegreesSeconds(decDeg); + + return (sunRAHour, sunRAMin, sunRASec, sunDecDeg, sunDecMin, sunDecSec); + } + + /// + /// Calculate precise position of the sun for a local date and time. + /// + public (double sunRAHour, double sunRAMin, double sunRASec, double sunDecDeg, double sunDecMin, double sunDecSec) PrecisePositionOfSun(double lctHours, double lctMinutes, double lctSeconds, double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection) + { + var daylightSaving = (isDaylightSaving == true) ? 1 : 0; + + var gDay = PAMacros.LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var gMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var gYear = PAMacros.LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var sunEclipticLongitudeDeg = PAMacros.SunLong(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var raDeg = PAMacros.EcRA(sunEclipticLongitudeDeg, 0, 0, 0, 0, 0, gDay, gMonth, gYear); + var raHours = PAMacros.DecimalDegreesToDegreeHours(raDeg); + var decDeg = PAMacros.EcDec(sunEclipticLongitudeDeg, 0, 0, 0, 0, 0, gDay, gMonth, gYear); + + var sunRAHour = PAMacros.DecimalHoursHour(raHours); + var sunRAMin = PAMacros.DecimalHoursMinute(raHours); + var sunRASec = PAMacros.DecimalHoursSecond(raHours); + var sunDecDeg = PAMacros.DecimalDegreesDegrees(decDeg); + var sunDecMin = PAMacros.DecimalDegreesMinutes(decDeg); + var sunDecSec = PAMacros.DecimalDegreesSeconds(decDeg); + + return (sunRAHour, sunRAMin, sunRASec, sunDecDeg, sunDecMin, sunDecSec); + } + + /// + /// Calculate distance to the Sun (in km), and angular size. + /// + /// + /// sunDistKm -- Sun's distance, in kilometers + /// sunAngSizeDeg -- Sun's angular size (degrees part) + /// sunAngSizeMin -- Sun's angular size (minutes part) + /// sunAngSizeSec -- Sun's angular size (seconds part) + /// + public (double sunDistKm, double sunAngSizeDeg, double sunAngSizeMin, double sunAngSizeSec) SunDistanceAndAngularSize(double lctHours, double lctMinutes, double lctSeconds, double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var gDay = PAMacros.LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var gMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var gYear = PAMacros.LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var trueAnomalyDeg = PAMacros.SunTrueAnomaly(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); + var trueAnomalyRad = trueAnomalyDeg.ToRadians(); + var eccentricity = PAMacros.SunEcc(gDay, gMonth, gYear); + var f = (1 + eccentricity * trueAnomalyRad.Cosine()) / (1 - eccentricity * eccentricity); + var rKm = 149598500 / f; + var thetaDeg = f * 0.533128; + + var sunDistKm = Math.Round(rKm, 0); + var sunAngSizeDeg = PAMacros.DecimalDegreesDegrees(thetaDeg); + var sunAngSizeMin = PAMacros.DecimalDegreesMinutes(thetaDeg); + var sunAngSizeSec = PAMacros.DecimalDegreesSeconds(thetaDeg); + + return (sunDistKm, sunAngSizeDeg, sunAngSizeMin, sunAngSizeSec); + } + + /// + /// Calculate local sunrise and sunset. /// - public class PASun + /// + /// localSunriseHour -- Local sunrise, hour part + /// localSunriseMinute -- Local sunrise, minutes part + /// localSunsetHour -- Local sunset, hour part + /// localSunsetMinute -- Local sunset, minutes part + /// azimuthOfSunriseDeg -- Azimuth (horizon direction) of sunrise, in degrees + /// azimuthOfSunsetDeg -- Azimuth (horizon direction) of sunset, in degrees + /// status -- Calculation status + /// + public (double localSunriseHour, double localSunriseMinute, double localSunsetHour, double localSunsetMinute, double azimuthOfSunriseDeg, double azimuthOfSunsetDeg, string status) SunriseAndSunset(double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection, double geographicalLongDeg, double geographicalLatDeg) { - /// - /// Calculate approximate position of the sun for a local date and time. - /// - /// Local civil time, in hours. - /// Local civil time, in minutes. - /// Local civil time, in seconds. - /// Local day, day part. - /// Local day, month part. - /// Local day, year part. - /// Is daylight savings in effect? - /// Time zone correction, in hours. - /// - /// sunRAHour -- Right Ascension of Sun, hour part - /// sunRAMin -- Right Ascension of Sun, minutes part - /// sunRASec -- Right Ascension of Sun, seconds part - /// sunDecDeg -- Declination of Sun, degrees part - /// sunDecMin -- Declination of Sun, minutes part - /// sunDecSec -- Declination of Sun, seconds part - /// - public (double sunRAHour, double sunRAMin, double sunRASec, double sunDecDeg, double sunDecMin, double sunDecSec) ApproximatePositionOfSun(double lctHours, double lctMinutes, double lctSeconds, double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection) - { - var daylightSaving = (isDaylightSaving == true) ? 1 : 0; - - var greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var utHours = PAMacros.LocalCivilTimeToUniversalTime(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var utDays = utHours / 24; - var jdDays = PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) + utDays; - var dDays = jdDays - PAMacros.CivilDateToJulianDate(0, 1, 2010); - var nDeg = 360 * dDays / 365.242191; - var mDeg1 = nDeg + PAMacros.SunELong(0, 1, 2010) - PAMacros.SunPeri(0, 1, 2010); - var mDeg2 = mDeg1 - 360 * (mDeg1 / 360).Floor(); - var eCDeg = 360 * PAMacros.SunEcc(0, 1, 2010) * mDeg2.ToRadians().Sine() / Math.PI; - var lSDeg1 = nDeg + eCDeg + PAMacros.SunELong(0, 1, 2010); - var lSDeg2 = lSDeg1 - 360 * (lSDeg1 / 360).Floor(); - var raDeg = PAMacros.EcRA(lSDeg2, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); - var raHours = PAMacros.DecimalDegreesToDegreeHours(raDeg); - var decDeg = PAMacros.EcDec(lSDeg2, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear); - - var sunRAHour = PAMacros.DecimalHoursHour(raHours); - var sunRAMin = PAMacros.DecimalHoursMinute(raHours); - var sunRASec = PAMacros.DecimalHoursSecond(raHours); - var sunDecDeg = PAMacros.DecimalDegreesDegrees(decDeg); - var sunDecMin = PAMacros.DecimalDegreesMinutes(decDeg); - var sunDecSec = PAMacros.DecimalDegreesSeconds(decDeg); - - return (sunRAHour, sunRAMin, sunRASec, sunDecDeg, sunDecMin, sunDecSec); - } - - /// - /// Calculate precise position of the sun for a local date and time. - /// - public (double sunRAHour, double sunRAMin, double sunRASec, double sunDecDeg, double sunDecMin, double sunDecSec) PrecisePositionOfSun(double lctHours, double lctMinutes, double lctSeconds, double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection) - { - var daylightSaving = (isDaylightSaving == true) ? 1 : 0; - - var gDay = PAMacros.LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var gMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var gYear = PAMacros.LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var sunEclipticLongitudeDeg = PAMacros.SunLong(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var raDeg = PAMacros.EcRA(sunEclipticLongitudeDeg, 0, 0, 0, 0, 0, gDay, gMonth, gYear); - var raHours = PAMacros.DecimalDegreesToDegreeHours(raDeg); - var decDeg = PAMacros.EcDec(sunEclipticLongitudeDeg, 0, 0, 0, 0, 0, gDay, gMonth, gYear); - - var sunRAHour = PAMacros.DecimalHoursHour(raHours); - var sunRAMin = PAMacros.DecimalHoursMinute(raHours); - var sunRASec = PAMacros.DecimalHoursSecond(raHours); - var sunDecDeg = PAMacros.DecimalDegreesDegrees(decDeg); - var sunDecMin = PAMacros.DecimalDegreesMinutes(decDeg); - var sunDecSec = PAMacros.DecimalDegreesSeconds(decDeg); - - return (sunRAHour, sunRAMin, sunRASec, sunDecDeg, sunDecMin, sunDecSec); - } - - /// - /// Calculate distance to the Sun (in km), and angular size. - /// - /// - /// sunDistKm -- Sun's distance, in kilometers - /// sunAngSizeDeg -- Sun's angular size (degrees part) - /// sunAngSizeMin -- Sun's angular size (minutes part) - /// sunAngSizeSec -- Sun's angular size (seconds part) - /// - public (double sunDistKm, double sunAngSizeDeg, double sunAngSizeMin, double sunAngSizeSec) SunDistanceAndAngularSize(double lctHours, double lctMinutes, double lctSeconds, double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var gDay = PAMacros.LocalCivilTimeGreenwichDay(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var gMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var gYear = PAMacros.LocalCivilTimeGreenwichYear(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var trueAnomalyDeg = PAMacros.SunTrueAnomaly(lctHours, lctMinutes, lctSeconds, daylightSaving, zoneCorrection, localDay, localMonth, localYear); - var trueAnomalyRad = trueAnomalyDeg.ToRadians(); - var eccentricity = PAMacros.SunEcc(gDay, gMonth, gYear); - var f = (1 + eccentricity * trueAnomalyRad.Cosine()) / (1 - eccentricity * eccentricity); - var rKm = 149598500 / f; - var thetaDeg = f * 0.533128; - - var sunDistKm = Math.Round(rKm, 0); - var sunAngSizeDeg = PAMacros.DecimalDegreesDegrees(thetaDeg); - var sunAngSizeMin = PAMacros.DecimalDegreesMinutes(thetaDeg); - var sunAngSizeSec = PAMacros.DecimalDegreesSeconds(thetaDeg); - - return (sunDistKm, sunAngSizeDeg, sunAngSizeMin, sunAngSizeSec); - } - - /// - /// Calculate local sunrise and sunset. - /// - /// - /// localSunriseHour -- Local sunrise, hour part - /// localSunriseMinute -- Local sunrise, minutes part - /// localSunsetHour -- Local sunset, hour part - /// localSunsetMinute -- Local sunset, minutes part - /// azimuthOfSunriseDeg -- Azimuth (horizon direction) of sunrise, in degrees - /// azimuthOfSunsetDeg -- Azimuth (horizon direction) of sunset, in degrees - /// status -- Calculation status - /// - public (double localSunriseHour, double localSunriseMinute, double localSunsetHour, double localSunsetMinute, double azimuthOfSunriseDeg, double azimuthOfSunsetDeg, string status) SunriseAndSunset(double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection, double geographicalLongDeg, double geographicalLatDeg) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var localSunriseHours = PAMacros.SunriseLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); - var localSunsetHours = PAMacros.SunsetLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); - - var sunRiseSetStatus = PAMacros.ESunRS(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); - - var adjustedSunriseHours = localSunriseHours + 0.008333; - var adjustedSunsetHours = localSunsetHours + 0.008333; - - var azimuthOfSunriseDeg1 = PAMacros.SunriseAZ(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); - var azimuthOfSunsetDeg1 = PAMacros.SunsetAZ(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); - - var localSunriseHour = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedSunriseHours) : 0; - var localSunriseMinute = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedSunriseHours) : 0; - - var localSunsetHour = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedSunsetHours) : 0; - var localSunsetMinute = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedSunsetHours) : 0; - - var azimuthOfSunriseDeg = (sunRiseSetStatus.Equals("OK")) ? Math.Round(azimuthOfSunriseDeg1, 2) : 0; - var azimuthOfSunsetDeg = (sunRiseSetStatus.Equals("OK")) ? Math.Round(azimuthOfSunsetDeg1, 2) : 0; - - var status = sunRiseSetStatus; - - return (localSunriseHour, localSunriseMinute, localSunsetHour, localSunsetMinute, azimuthOfSunriseDeg, azimuthOfSunsetDeg, status); - } - - /// - /// Calculate times of morning and evening twilight. - /// - /// Local date, day part. - /// Local date, month part. - /// Local date, year part. - /// Is daylight savings in effect? - /// Time zone correction, in hours. - /// Geographical longitude, in degrees. - /// Geographical latitude, in degrees. - /// "C" (civil), "N" (nautical), or "A" (astronomical) - /// - /// amTwilightBeginsHour -- Beginning of AM twilight (hour part) - /// amTwilightBeginsMin -- Beginning of AM twilight (minutes part) - /// pmTwilightEndsHour -- Ending of PM twilight (hour part) - /// pmTwilightEndsMin -- Ending of PM twilight (minutes part) - /// status -- Calculation status - /// - public (double amTwilightBeginsHour, double amTwilightBeginsMin, double pmTwilightEndsHour, double pmTwilightEndsMin, string status) MorningAndEveningTwilight(double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection, double geographicalLongDeg, double geographicalLatDeg, PATwilightType twilightType) - { - var daylightSaving = (isDaylightSaving) ? 1 : 0; - - var startOfAMTwilightHours = PAMacros.TwilightAMLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg, twilightType); - - var endOfPMTwilightHours = PAMacros.TwilightPMLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg, twilightType); - - var twilightStatus = PAMacros.ETwilight(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg, twilightType); - - var adjustedAMStartTime = startOfAMTwilightHours + 0.008333; - var adjustedPMStartTime = endOfPMTwilightHours + 0.008333; - - double amTwilightBeginsHour = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedAMStartTime) : -99; - double amTwilightBeginsMin = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedAMStartTime) : -99; - - double pmTwilightEndsHour = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedPMStartTime) : -99; - double pmTwilightEndsMin = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedPMStartTime) : -99; - - var status = twilightStatus; - - return (amTwilightBeginsHour, amTwilightBeginsMin, pmTwilightEndsHour, pmTwilightEndsMin, status); - } - - /// - /// Calculate the equation of time. (The difference between the real Sun time and the mean Sun time.) - /// - /// Greenwich date (day part) - /// Greenwich date (month part) - /// Greenwich date (year part) - /// - /// equation_of_time_min -- equation of time (minute part) - /// equation_of_time_sec -- equation of time (seconds part) - /// - public (double equationOfTimeMin, double equationOfTimeSec) EquationOfTime(double gwdateDay, int gwdateMonth, int gwdateYear) - { - var sunLongitudeDeg = PAMacros.SunLong(12, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var sunRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)); - var equivalentUTHours = PAMacros.GreenwichSiderealTimeToUniversalTime(sunRAHours, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var equationOfTimeHours = equivalentUTHours - 12; - - var equationOfTimeMin = PAMacros.DecimalHoursMinute(equationOfTimeHours); - var equationOfTimeSec = PAMacros.DecimalHoursSecond(equationOfTimeHours); - - return (equationOfTimeMin, equationOfTimeSec); - } - - /// - /// Calculate solar elongation for a celestial body. - /// - /// - /// Solar elongation is the angle between the lines of sight from the Earth to the Sun and from the Earth to the celestial body. - /// - /// solarElongationDeg -- Solar elongation, in degrees - public double SolarElongation(double raHour, double raMin, double raSec, double decDeg, double decMin, double decSec, double gwdateDay, int gwdateMonth, int gwdateYear) - { - var sunLongitudeDeg = PAMacros.SunLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var sunRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)); - var sunDecDeg = PAMacros.EcDec(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); - var solarElongationDeg = PAMacros.Angle(sunRAHours, 0, 0, sunDecDeg, 0, 0, raHour, raMin, raSec, decDeg, decMin, decSec, PAAngleMeasure.Hours); - - return Math.Round(solarElongationDeg, 2); - } + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var localSunriseHours = PAMacros.SunriseLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); + var localSunsetHours = PAMacros.SunsetLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); + + var sunRiseSetStatus = PAMacros.ESunRS(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); + + var adjustedSunriseHours = localSunriseHours + 0.008333; + var adjustedSunsetHours = localSunsetHours + 0.008333; + + var azimuthOfSunriseDeg1 = PAMacros.SunriseAZ(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); + var azimuthOfSunsetDeg1 = PAMacros.SunsetAZ(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg); + + var localSunriseHour = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedSunriseHours) : 0; + var localSunriseMinute = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedSunriseHours) : 0; + + var localSunsetHour = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedSunsetHours) : 0; + var localSunsetMinute = (sunRiseSetStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedSunsetHours) : 0; + + var azimuthOfSunriseDeg = (sunRiseSetStatus.Equals("OK")) ? Math.Round(azimuthOfSunriseDeg1, 2) : 0; + var azimuthOfSunsetDeg = (sunRiseSetStatus.Equals("OK")) ? Math.Round(azimuthOfSunsetDeg1, 2) : 0; + + var status = sunRiseSetStatus; + + return (localSunriseHour, localSunriseMinute, localSunsetHour, localSunsetMinute, azimuthOfSunriseDeg, azimuthOfSunsetDeg, status); + } + + /// + /// Calculate times of morning and evening twilight. + /// + /// Local date, day part. + /// Local date, month part. + /// Local date, year part. + /// Is daylight savings in effect? + /// Time zone correction, in hours. + /// Geographical longitude, in degrees. + /// Geographical latitude, in degrees. + /// "C" (civil), "N" (nautical), or "A" (astronomical) + /// + /// amTwilightBeginsHour -- Beginning of AM twilight (hour part) + /// amTwilightBeginsMin -- Beginning of AM twilight (minutes part) + /// pmTwilightEndsHour -- Ending of PM twilight (hour part) + /// pmTwilightEndsMin -- Ending of PM twilight (minutes part) + /// status -- Calculation status + /// + public (double amTwilightBeginsHour, double amTwilightBeginsMin, double pmTwilightEndsHour, double pmTwilightEndsMin, string status) MorningAndEveningTwilight(double localDay, int localMonth, int localYear, bool isDaylightSaving, int zoneCorrection, double geographicalLongDeg, double geographicalLatDeg, PATwilightType twilightType) + { + var daylightSaving = (isDaylightSaving) ? 1 : 0; + + var startOfAMTwilightHours = PAMacros.TwilightAMLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg, twilightType); + + var endOfPMTwilightHours = PAMacros.TwilightPMLCT(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg, twilightType); + + var twilightStatus = PAMacros.ETwilight(localDay, localMonth, localYear, daylightSaving, zoneCorrection, geographicalLongDeg, geographicalLatDeg, twilightType); + + var adjustedAMStartTime = startOfAMTwilightHours + 0.008333; + var adjustedPMStartTime = endOfPMTwilightHours + 0.008333; + + double amTwilightBeginsHour = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedAMStartTime) : -99; + double amTwilightBeginsMin = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedAMStartTime) : -99; + + double pmTwilightEndsHour = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursHour(adjustedPMStartTime) : -99; + double pmTwilightEndsMin = (twilightStatus.Equals("OK")) ? PAMacros.DecimalHoursMinute(adjustedPMStartTime) : -99; + + var status = twilightStatus; + + return (amTwilightBeginsHour, amTwilightBeginsMin, pmTwilightEndsHour, pmTwilightEndsMin, status); + } + + /// + /// Calculate the equation of time. (The difference between the real Sun time and the mean Sun time.) + /// + /// Greenwich date (day part) + /// Greenwich date (month part) + /// Greenwich date (year part) + /// + /// equation_of_time_min -- equation of time (minute part) + /// equation_of_time_sec -- equation of time (seconds part) + /// + public (double equationOfTimeMin, double equationOfTimeSec) EquationOfTime(double gwdateDay, int gwdateMonth, int gwdateYear) + { + var sunLongitudeDeg = PAMacros.SunLong(12, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var sunRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)); + var equivalentUTHours = PAMacros.GreenwichSiderealTimeToUniversalTime(sunRAHours, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var equationOfTimeHours = equivalentUTHours - 12; + + var equationOfTimeMin = PAMacros.DecimalHoursMinute(equationOfTimeHours); + var equationOfTimeSec = PAMacros.DecimalHoursSecond(equationOfTimeHours); + + return (equationOfTimeMin, equationOfTimeSec); + } + + /// + /// Calculate solar elongation for a celestial body. + /// + /// + /// Solar elongation is the angle between the lines of sight from the Earth to the Sun and from the Earth to the celestial body. + /// + /// solarElongationDeg -- Solar elongation, in degrees + public double SolarElongation(double raHour, double raMin, double raSec, double decDeg, double decMin, double decSec, double gwdateDay, int gwdateMonth, int gwdateYear) + { + var sunLongitudeDeg = PAMacros.SunLong(0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var sunRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear)); + var sunDecDeg = PAMacros.EcDec(sunLongitudeDeg, 0, 0, 0, 0, 0, gwdateDay, gwdateMonth, gwdateYear); + var solarElongationDeg = PAMacros.Angle(sunRAHours, 0, 0, sunDecDeg, 0, 0, raHour, raMin, raSec, decDeg, decMin, decSec, PAAngleMeasure.Hours); + + return Math.Round(solarElongationDeg, 2); } -} \ No newline at end of file +} diff --git a/PALib/PATypes.cs b/PALib/PATypes.cs index ba71ba6..297ef7a 100644 --- a/PALib/PATypes.cs +++ b/PALib/PATypes.cs @@ -1,91 +1,91 @@ using System; -namespace PALib + +namespace PALib; + +/// +/// Coordinate types +/// +public enum PACoordinateType { /// - /// Coordinate types + /// Apparent (observer) /// - public enum PACoordinateType - { - /// - /// Apparent (observer) - /// - Apparent, + Apparent, - /// - /// Actual/real - /// - True - } + /// + /// Actual/real + /// + True +} +/// +/// Twilight type +/// +/// +/// Maps to degrees-below-horizon. +/// +public enum PATwilightType +{ /// - /// Twilight type + /// First period of twilight. /// - /// - /// Maps to degrees-below-horizon. - /// - public enum PATwilightType - { - /// - /// First period of twilight. - /// - Civil = 6, + Civil = 6, - /// - /// Second period of twilight. - /// - Nautical = 12, + /// + /// Second period of twilight. + /// + Nautical = 12, - /// - /// Second period of twilight. - /// - Astronomical = 18 - } + /// + /// Second period of twilight. + /// + Astronomical = 18 +} +/// +/// Angle measurement units. +/// +public enum PAAngleMeasure +{ /// - /// Angle measurement units. + /// Measurement by degrees. /// - public enum PAAngleMeasure - { - /// - /// Measurement by degrees. - /// - Degrees, + Degrees, - /// - /// Measurement by hours. - /// - Hours - } + /// + /// Measurement by hours. + /// + Hours +} +/// +/// Accuracy level of calculation. +/// +public enum PAAccuracyLevel +{ /// - /// Accuracy level of calculation. + /// Approximate value. /// - public enum PAAccuracyLevel - { - /// - /// Approximate value. - /// - Approximate, + Approximate, - /// - /// Precise value. - /// - Precise - } + /// + /// Precise value. + /// + Precise +} +/// +/// Warning flags for calculation results. +/// +public enum PAWarningFlag +{ /// - /// Warning flags for calculation results. + /// Calculation result is OK. /// - public enum PAWarningFlag - { - /// - /// Calculation result is OK. - /// - OK, + OK, - /// - /// Calculation result is invalid/inaccurate. - /// - Warning - } -} \ No newline at end of file + /// + /// Calculation result is invalid/inaccurate. + /// + Warning +} diff --git a/PALib/PAUtils.cs b/PALib/PAUtils.cs index a7c5f47..cae40b7 100644 --- a/PALib/PAUtils.cs +++ b/PALib/PAUtils.cs @@ -1,27 +1,27 @@ using System; -namespace PALib + +namespace PALib; + +/// +/// Utility methods. +/// +public static class PAUtils { /// - /// Utility methods. + /// Determine if year is a leap year. /// - public static class PAUtils + public static bool IsLeapYear(this int inputYear) { - /// - /// Determine if year is a leap year. - /// - public static bool IsLeapYear(this int inputYear) - { - double year = inputYear; + double year = inputYear; - if (year % 4 == 0) - { - if (year % 100 == 0) - return (year % 400 == 0) ? true : false; - else - return true; - } + if (year % 4 == 0) + { + if (year % 100 == 0) + return (year % 400 == 0) ? true : false; else - return false; + return true; } + else + return false; } -} \ No newline at end of file +}