Practical Astronomy Algorithms in .NET/C#
Loading...
Searching...
No Matches
PAPlanet.cs
Go to the documentation of this file.
1using System;
2using PALib.Data;
3using PALib.Helpers;
4
5namespace PALib;
6
10public class PAPlanet
11{
15 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)
16 {
17 int daylightSaving = isDaylightSaving ? 1 : 0;
18
19 PlanetData planetInfo = PlanetInfo.GetPlanetInfo(planetName);
20
21 double gdateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
22 int gdateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
23 int gdateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
24
25 double utHours = PAMacros.LocalCivilTimeToUniversalTime(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
26 double dDays = PAMacros.CivilDateToJulianDate(gdateDay + (utHours / 24), gdateMonth, gdateYear) - PAMacros.CivilDateToJulianDate(0, 1, 2010);
27 double npDeg1 = 360 * dDays / (365.242191 * planetInfo.tp_PeriodOrbit);
28 double npDeg2 = npDeg1 - 360 * (npDeg1 / 360).Floor();
29 double mpDeg = npDeg2 + planetInfo.long_LongitudeEpoch - planetInfo.peri_LongitudePerihelion;
30 double lpDeg1 = npDeg2 + (360 * planetInfo.ecc_EccentricityOrbit * mpDeg.ToRadians().Sine() / Math.PI) + planetInfo.long_LongitudeEpoch;
31 double lpDeg2 = lpDeg1 - 360 * (lpDeg1 / 360).Floor();
32 double planetTrueAnomalyDeg = lpDeg2 - planetInfo.peri_LongitudePerihelion;
33 double rAU = planetInfo.axis_AxisOrbit * (1 - Math.Pow(planetInfo.ecc_EccentricityOrbit, 2)) / (1 + planetInfo.ecc_EccentricityOrbit * planetTrueAnomalyDeg.ToRadians().Cosine());
34
35 PlanetData earthInfo = PlanetInfo.GetPlanetInfo("Earth");
36
37 double neDeg1 = 360 * dDays / (365.242191 * earthInfo.tp_PeriodOrbit);
38 double neDeg2 = neDeg1 - 360 * (neDeg1 / 360).Floor();
39 double meDeg = neDeg2 + earthInfo.long_LongitudeEpoch - earthInfo.peri_LongitudePerihelion;
40 double leDeg1 = neDeg2 + earthInfo.long_LongitudeEpoch + 360 * earthInfo.ecc_EccentricityOrbit * meDeg.ToRadians().Sine() / Math.PI;
41 double leDeg2 = leDeg1 - 360 * (leDeg1 / 360).Floor();
42 double earthTrueAnomalyDeg = leDeg2 - earthInfo.peri_LongitudePerihelion;
43 double rAU2 = earthInfo.axis_AxisOrbit * (1 - Math.Pow(earthInfo.ecc_EccentricityOrbit, 2)) / (1 + earthInfo.ecc_EccentricityOrbit * earthTrueAnomalyDeg.ToRadians().Cosine());
44 double lpNodeRad = (lpDeg2 - planetInfo.node_LongitudeAscendingNode).ToRadians();
45 double psiRad = (lpNodeRad.Sine() * planetInfo.incl_OrbitalInclination.ToRadians().Sine()).ASine();
46 double y = lpNodeRad.Sine() * planetInfo.incl_OrbitalInclination.ToRadians().Cosine();
47 double x = lpNodeRad.Cosine();
48 double ldDeg = PAMacros.Degrees(y.AngleTangent2(x)) + planetInfo.node_LongitudeAscendingNode;
49 double rdAU = rAU * psiRad.Cosine();
50 double leLdRad = (leDeg2 - ldDeg).ToRadians();
51 double atan2Type1 = (rdAU * leLdRad.Sine()).AngleTangent2(rAU2 - rdAU * leLdRad.Cosine());
52 double atan2Type2 = (rAU2 * (-leLdRad).Sine()).AngleTangent2(rdAU - rAU2 * leLdRad.Cosine());
53 double aRad = (rdAU < 1) ? atan2Type1 : atan2Type2;
54 double lamdaDeg1 = (rdAU < 1) ? 180 + leDeg2 + PAMacros.Degrees(aRad) : PAMacros.Degrees(aRad) + ldDeg;
55 double lamdaDeg2 = lamdaDeg1 - 360 * (lamdaDeg1 / 360).Floor();
56 double betaDeg = PAMacros.Degrees((rdAU * psiRad.Tangent() * (lamdaDeg2 - ldDeg).ToRadians().Sine() / (rAU2 * (-leLdRad).Sine())).AngleTangent());
57 double raHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(lamdaDeg2, 0, 0, betaDeg, 0, 0, gdateDay, gdateMonth, gdateYear));
58 double decDeg = PAMacros.EcDec(lamdaDeg2, 0, 0, betaDeg, 0, 0, gdateDay, gdateMonth, gdateYear);
59
62 double planetRASec = PAMacros.DecimalHoursSecond(raHours);
65 double planetDecSec = PAMacros.DecimalDegreesSeconds(decDeg);
66
68 }
69
73 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)
74 {
75 int daylightSaving = isDaylightSaving ? 1 : 0;
76
77 (double planetLongitude, double planetLatitude, double planetDistanceAU, double planetHLong1, double planetHLong2, double planetHLat, double planetRVect) coordinateResults = PAMacros.PlanetCoordinates(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, planetName);
78
79 double planetRAHours = PAMacros.DecimalDegreesToDegreeHours(PAMacros.EcRA(coordinateResults.planetLongitude, 0, 0, coordinateResults.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear));
80 double planetDecDeg1 = PAMacros.EcDec(coordinateResults.planetLongitude, 0, 0, coordinateResults.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear);
81
82 int planetRAHour = PAMacros.DecimalHoursHour(planetRAHours);
83 int planetRAMin = PAMacros.DecimalHoursMinute(planetRAHours);
84 double planetRASec = PAMacros.DecimalHoursSecond(planetRAHours);
85 double planetDecDeg = PAMacros.DecimalDegreesDegrees(planetDecDeg1);
86 double planetDecMin = PAMacros.DecimalDegreesMinutes(planetDecDeg1);
87 double planetDecSec = PAMacros.DecimalDegreesSeconds(planetDecDeg1);
88
90 }
91
105 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)
106 {
107 int daylightSaving = isDaylightSaving ? 1 : 0;
108
109 double greenwichDateDay = PAMacros.LocalCivilTimeGreenwichDay(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
110 int greenwichDateMonth = PAMacros.LocalCivilTimeGreenwichMonth(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
111 int greenwichDateYear = PAMacros.LocalCivilTimeGreenwichYear(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
112
113 (double planetLongitude, double planetLatitude, double planetDistanceAU, double planetHLong1, double planetHLong2, double planetHLat, double planetRVect) planetCoordInfo = PAMacros.PlanetCoordinates(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear, planetName);
114
115 double planetRARad = PAMacros.EcRA(planetCoordInfo.planetLongitude, 0, 0, planetCoordInfo.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear).ToRadians();
116 double planetDecRad = PAMacros.EcDec(planetCoordInfo.planetLongitude, 0, 0, planetCoordInfo.planetLatitude, 0, 0, localDateDay, localDateMonth, localDateYear).ToRadians();
117
118 double lightTravelTimeHours = planetCoordInfo.planetDistanceAU * 0.1386;
119 PlanetData planetInfo = PlanetInfo.GetPlanetInfo(planetName);
120 double angularDiameterArcsec = planetInfo.theta0_AngularDiameter / planetCoordInfo.planetDistanceAU;
121 double phase1 = 0.5 * (1.0 + (planetCoordInfo.planetLongitude - planetCoordInfo.planetHLong1).ToRadians().Cosine());
122
123 double sunEclLongDeg = PAMacros.SunLong(lctHour, lctMin, lctSec, daylightSaving, zoneCorrectionHours, localDateDay, localDateMonth, localDateYear);
124 double sunRARad = PAMacros.EcRA(sunEclLongDeg, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear).ToRadians();
125 double sunDecRad = PAMacros.EcDec(sunEclLongDeg, 0, 0, 0, 0, 0, greenwichDateDay, greenwichDateMonth, greenwichDateYear).ToRadians();
126
127 double y = sunDecRad.Cosine() * (sunRARad - planetRARad).Sine();
128 double x = planetDecRad.Cosine() * sunDecRad.Sine() - planetDecRad.Sine() * sunDecRad.Cosine() * (sunRARad - planetRARad).Cosine();
129
130 double chiDeg = PAMacros.Degrees(y.AngleTangent2(x));
131 double radiusVectorAU = planetCoordInfo.planetRVect;
132 double approximateMagnitude1 = 5.0 * (radiusVectorAU * planetCoordInfo.planetDistanceAU / phase1.SquareRoot()).Log10() + planetInfo.v0_VisualMagnitude;
133
134 double distanceAU = Math.Round(planetCoordInfo.planetDistanceAU, 5);
135 double angDiaArcsec = Math.Round(angularDiameterArcsec, 1);
136 double phase = Math.Round(phase1, 2);
137 int lightTimeHour = PAMacros.DecimalHoursHour(lightTravelTimeHours);
138 int lightTimeMinutes = PAMacros.DecimalHoursMinute(lightTravelTimeHours);
139 double lightTimeSeconds = PAMacros.DecimalHoursSecond(lightTravelTimeHours);
140 double posAngleBrightLimbDeg = Math.Round(chiDeg, 1);
141 double approximateMagnitude = Math.Round(approximateMagnitude1, 1);
142
144 }
145}
Information about a planet.
Definition PlanetData.cs:10
double incl_OrbitalInclination
Orbital inclination.
Definition PlanetData.cs:68
double ecc_EccentricityOrbit
Eccentricity of the orbit.
Definition PlanetData.cs:50
double v0_VisualMagnitude
Visual magnitude at 1 AU.
Definition PlanetData.cs:95
double long_LongitudeEpoch
Longitude at the epoch.
Definition PlanetData.cs:32
double node_LongitudeAscendingNode
Longitude of the ascending node.
Definition PlanetData.cs:77
double peri_LongitudePerihelion
Longitude of the perihelion.
Definition PlanetData.cs:41
double tp_PeriodOrbit
Period of orbit.
Definition PlanetData.cs:23
Data manager for planets.
static PlanetData GetPlanetInfo(string name)
Get information about a planet.
Miscellaneous macro functions supporting the other classes.
Definition PAMacros.cs:13
static double double double double double double double planetRVect PlanetCoordinates(double lh, double lm, double ls, int ds, int zc, double dy, int mn, int yr, string s)
Definition PAMacros.cs:2253
static double LocalCivilTimeGreenwichDay(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear)
Determine Greenwich Day for Local Time.
Definition PAMacros.cs:323
static double CivilDateToJulianDate(double day, double month, double year)
Convert a Greenwich Date/Civil Date (day,month,year) to Julian Date.
Definition PAMacros.cs:87
static double Degrees(double w)
Convert W to Degrees.
Definition PAMacros.cs:463
static double EcDec(double eld, double elm, double els, double bd, double bm, double bs, double gd, int gm, int gy)
Ecliptic - Declination (degrees)
Definition PAMacros.cs:1551
static double DecimalDegreesToDegreeHours(double decimalDegrees)
Convert Decimal Degrees to Degree-Hours.
Definition PAMacros.cs:522
static double EcRA(double eld, double elm, double els, double bd, double bm, double bs, double gd, int gm, int gy)
Ecliptic - Right Ascension (degrees)
Definition PAMacros.cs:1567
static int DecimalHoursMinute(double decimalHours)
Return the minutes part of a Decimal Hours.
Definition PAMacros.cs:55
static double DecimalHoursSecond(double decimalHours)
Return the seconds part of a Decimal Hours.
Definition PAMacros.cs:71
static double DecimalDegreesSeconds(double decimalDegrees)
Return Seconds part of Decimal Degrees.
Definition PAMacros.cs:506
static int DecimalHoursHour(double decimalHours)
Return the hour part of a Decimal Hours.
Definition PAMacros.cs:39
static double SunLong(double lch, double lcm, double lcs, int ds, int zc, double ld, int lm, int ly)
Calculate Sun's ecliptic longitude.
Definition PAMacros.cs:760
static double LocalCivilTimeToUniversalTime(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear)
Convert Local Civil Time to Universal Time.
Definition PAMacros.cs:237
static double DecimalDegreesMinutes(double decimalDegrees)
Return Minutes part of Decimal Degrees.
Definition PAMacros.cs:490
static int LocalCivilTimeGreenwichMonth(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear)
Determine Greenwich Month for Local Time.
Definition PAMacros.cs:340
static double DecimalDegreesDegrees(double decimalDegrees)
Return Degrees part of Decimal Degrees.
Definition PAMacros.cs:474
static int LocalCivilTimeGreenwichYear(double lctHours, double lctMinutes, double lctSeconds, int daylightSaving, int zoneCorrection, double localDay, int localMonth, int localYear)
Determine Greenwich Year for Local Time.
Definition PAMacros.cs:356
Planet calculations.
Definition PAPlanet.cs:11
double double angDiaArcsec
Definition PAPlanet.cs:105
double double double double double planetDecMin
Definition PAPlanet.cs:15
double double double double double lightTimeMinutes
Definition PAPlanet.cs:105
double double double double double double double posAngleBrightLimbDeg
Definition PAPlanet.cs:105
double double double planetRASec
Definition PAPlanet.cs:15
double distanceAU
Calculate several visual aspects of a planet.
Definition PAPlanet.cs:105
double double double double double double lightTimeSeconds
Definition PAPlanet.cs:105
double double double double lightTimeHour
Definition PAPlanet.cs:105
double double double double planetDecDeg
Definition PAPlanet.cs:15
double double double double double double planetDecSec PrecisePositionOfPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName)
Definition PAPlanet.cs:73
double double planetRAMin
Definition PAPlanet.cs:15
double double double phase
Definition PAPlanet.cs:105
double double double double double double planetDecSec ApproximatePositionOfPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName)
Definition PAPlanet.cs:15
double double double double double double double double approximateMagnitude VisualAspectsOfAPlanet(double lctHour, double lctMin, double lctSec, bool isDaylightSaving, int zoneCorrectionHours, double localDateDay, int localDateMonth, int localDateYear, string planetName)
Definition PAPlanet.cs:105
double planetRAHour
Calculate approximate position of a planet.
Definition PAPlanet.cs:15