The calculation for the distance of the Earth to a planet is also based on the position calculation, but is a little bit simpler. To get all the information we need, we do not need the full position calculation, and it is enough to find the heliographical coordinates of the planet and the Earth.
Once we have these values, we can then find the distance between the two.
public static void CalcPlanetDistance(DateTime dEpoch, DateTime dDate, double fPOrbPeriod, double fPEcc, double fPEpochLong, double fPPeriLong, double fPSMA, double fPAscNode, double fPIncl, double fEOrbPeriod, double fEEcc, double fEEpochLong, double fEPeriLong, double fESMA, ref double fDistance) { double fD, fPN, fPM, fPL, fPV, fPR; double fEN, fEM, fEL, fEV, fER, fRho; fD = UraniaTime.GetDaysBetween(dDate, dEpoch); fPN = (360.0/365.242191) * (fD / fPOrbPeriod); fPN = Trig.PutIn360Deg(fPN); fPM = fPN + fPEpochLong - fPPeriLong; fPL = fPN + ((360.0 / Math.PI) * fPEcc * Math.Sin(Trig.DegToRad(fPM))) + fPEpochLong; fPL = Trig.PutIn360Deg(fPL); fPV = fPL - fPPeriLong; fPR = (fPSMA * (1 - (fPEcc * fPEcc))) / (1 + (fPEcc * Math.Cos(Trig.DegToRad(fPV)))); fEN = (360.0/365.242191) * (fD / fEOrbPeriod); fEN = Trig.PutIn360Deg(fEN); fEM = fEN + fEEpochLong - fEPeriLong; fEL = fEN + ((360.0 / Math.PI) * fEEcc * Math.Sin(Trig.DegToRad(fEM))) + fEEpochLong; fEL = Trig.PutIn360Deg(fEL); fEV = fEL - fEPeriLong; fER = ((1 - (fEEcc * fEEcc))) / (1 + (fEEcc * Math.Cos(Trig.DegToRad(fEV)))); fRho = Math.Sqrt((fER * fER) + (fPR * fPR) - (2.0 * fER * fPR * Math.Cos(Trig.DegToRad(fPL - fEL)))); fDistance = fRho; }
Comments