Tudat/Astrodynamics/Ephemerides/approximatePlanetPositions.cpp
//! Get keplerian state from ephemeris.
Get keplerian state from ephemeris.
Get keplerian state from ephemeris .
Eigen::Vector6d ApproximatePlanetPositions::getKeplerianStateFromEphemeris(
        const double secondsSinceEpoch )
{
    using std::pow;
    using std::sin;
    using std::cos;
    using namespace orbital_element_conversions;
    julianDate_ = basic_astrodynamics::convertSecondsSinceEpochToJulianDay(
                secondsSinceEpoch, referenceJulianDate_ );
    numberOfCenturiesPastJ2000_ = ( julianDate_ - 2451545.0 ) / 36525.0;
    planetKeplerianElementsAtGivenJulianDate_( semiMajorAxisIndex )
            = approximatePlanetPositionsDataContainer_.semiMajorAxis_
            + ( approximatePlanetPositionsDataContainer_
                .rateOfChangeOfSemiMajorAxis_ * numberOfCenturiesPastJ2000_ );
    planetKeplerianElementsAtGivenJulianDate_( eccentricityIndex )
            = approximatePlanetPositionsDataContainer_.eccentricity_
            + ( approximatePlanetPositionsDataContainer_
                .rateOfChangeOfEccentricity_ * numberOfCenturiesPastJ2000_ );
    planetKeplerianElementsAtGivenJulianDate_( inclinationIndex )
            = approximatePlanetPositionsDataContainer_.inclination_
            + ( approximatePlanetPositionsDataContainer_
                .rateOfChangeOfInclination_ * numberOfCenturiesPastJ2000_ );
    planetKeplerianElementsAtGivenJulianDate_( longitudeOfAscendingNodeIndex )
            = approximatePlanetPositionsDataContainer_.longitudeOfAscendingNode_
            + ( approximatePlanetPositionsDataContainer_
                .rateOfChangeOfLongitudeOfAscendingNode_ * numberOfCenturiesPastJ2000_ );
    longitudeOfPerihelionAtGivenJulianDate_
            = approximatePlanetPositionsDataContainer_.longitudeOfPerihelion_
            + ( approximatePlanetPositionsDataContainer_.rateOfChangeOfLongitudeOfPerihelion_
                * numberOfCenturiesPastJ2000_ );
    planetKeplerianElementsAtGivenJulianDate_( argumentOfPeriapsisIndex )
            = longitudeOfPerihelionAtGivenJulianDate_
            - planetKeplerianElementsAtGivenJulianDate_( longitudeOfAscendingNodeIndex );
    meanLongitudeAtGivenJulianDate_ = approximatePlanetPositionsDataContainer_.meanLongitude_
            + ( approximatePlanetPositionsDataContainer_.rateOfChangeOfMeanLongitude_
                * numberOfCenturiesPastJ2000_ );
    meanAnomalyAtGivenJulianDate_ = meanLongitudeAtGivenJulianDate_
            - longitudeOfPerihelionAtGivenJulianDate_
            + ( approximatePlanetPositionsDataContainer_.additionalTermB_
                * pow( numberOfCenturiesPastJ2000_, 2.0 ) )
            + ( approximatePlanetPositionsDataContainer_.additionalTermC_
                * cos( unit_conversions::convertDegreesToRadians(approximatePlanetPositionsDataContainer_.additionalTermF_ *
                       numberOfCenturiesPastJ2000_ )) )
            + ( approximatePlanetPositionsDataContainer_.additionalTermS_
                * sin( unit_conversions::convertDegreesToRadians(approximatePlanetPositionsDataContainer_.additionalTermF_ *
                       numberOfCenturiesPastJ2000_) ) );
    meanAnomalyAtGivenJulianDate_ = basic_mathematics::computeModulo(
                meanAnomalyAtGivenJulianDate_, 360.0 );
    if ( meanAnomalyAtGivenJulianDate_ > 180.0 )
    {
        meanAnomalyAtGivenJulianDate_ -= 360.0;
    }
    eccentricAnomalyAtGivenJulianDate_ = convertMeanAnomalyToEccentricAnomaly(
                planetKeplerianElementsAtGivenJulianDate_( eccentricityIndex ),
                unit_conversions::convertDegreesToRadians(
                    meanAnomalyAtGivenJulianDate_ ) );
    trueAnomalyAtGivenJulianData_
            = orbital_element_conversions::convertEccentricAnomalyToTrueAnomaly(
                eccentricAnomalyAtGivenJulianDate_,
                planetKeplerianElementsAtGivenJulianDate_( eccentricityIndex ) );
    planetKeplerianElementsAtGivenJulianDate_( trueAnomalyIndex )
            = trueAnomalyAtGivenJulianData_;
    planetKeplerianElementsAtGivenJulianDate_( semiMajorAxisIndex )
            = unit_conversions::convertAstronomicalUnitsToMeters(
                planetKeplerianElementsAtGivenJulianDate_( semiMajorAxisIndex ) );
    planetKeplerianElementsAtGivenJulianDate_( inclinationIndex )
            = unit_conversions::convertDegreesToRadians(
                planetKeplerianElementsAtGivenJulianDate_( inclinationIndex ) );
    planetKeplerianElementsAtGivenJulianDate_( longitudeOfAscendingNodeIndex )
            = unit_conversions::convertDegreesToRadians(
                planetKeplerianElementsAtGivenJulianDate_( longitudeOfAscendingNodeIndex ) );
    planetKeplerianElementsAtGivenJulianDate_( argumentOfPeriapsisIndex )
            = unit_conversions::convertDegreesToRadians(
                planetKeplerianElementsAtGivenJulianDate_( argumentOfPeriapsisIndex ) );
    return planetKeplerianElementsAtGivenJulianDate_;
}
Eigen :: Vector6d ApproximatePlanetPositions :: getKeplerianStateFromEphemeris ( const double secondsSinceEpoch ) { using std :: pow ; using std :: sin ; using std :: cos ; using namespace orbital_element_conversions ; julianDate_ = basic_astrodynamics :: convertSecondsSinceEpochToJulianDay ( secondsSinceEpoch , referenceJulianDate_ ) ; numberOfCenturiesPastJ2000_ = ( julianDate_ - 2451545.0 ) / 36525.0 ; planetKeplerianElementsAtGivenJulianDate_ ( semiMajorAxisIndex ) = approximatePlanetPositionsDataContainer_ . semiMajorAxis_ + ( approximatePlanetPositionsDataContainer_ . rateOfChangeOfSemiMajorAxis_ * numberOfCenturiesPastJ2000_ ) ; planetKeplerianElementsAtGivenJulianDate_ ( eccentricityIndex ) = approximatePlanetPositionsDataContainer_ . eccentricity_ + ( approximatePlanetPositionsDataContainer_ . rateOfChangeOfEccentricity_ * numberOfCenturiesPastJ2000_ ) ; planetKeplerianElementsAtGivenJulianDate_ ( inclinationIndex ) = approximatePlanetPositionsDataContainer_ . inclination_ + ( approximatePlanetPositionsDataContainer_ . rateOfChangeOfInclination_ * numberOfCenturiesPastJ2000_ ) ; planetKeplerianElementsAtGivenJulianDate_ ( longitudeOfAscendingNodeIndex ) = approximatePlanetPositionsDataContainer_ . longitudeOfAscendingNode_ + ( approximatePlanetPositionsDataContainer_ . rateOfChangeOfLongitudeOfAscendingNode_ * numberOfCenturiesPastJ2000_ ) ; longitudeOfPerihelionAtGivenJulianDate_ = approximatePlanetPositionsDataContainer_ . longitudeOfPerihelion_ + ( approximatePlanetPositionsDataContainer_ . rateOfChangeOfLongitudeOfPerihelion_ * numberOfCenturiesPastJ2000_ ) ; planetKeplerianElementsAtGivenJulianDate_ ( argumentOfPeriapsisIndex ) = longitudeOfPerihelionAtGivenJulianDate_ - planetKeplerianElementsAtGivenJulianDate_ ( longitudeOfAscendingNodeIndex ) ; meanLongitudeAtGivenJulianDate_ = approximatePlanetPositionsDataContainer_ . meanLongitude_ + ( approximatePlanetPositionsDataContainer_ . rateOfChangeOfMeanLongitude_ * numberOfCenturiesPastJ2000_ ) ; meanAnomalyAtGivenJulianDate_ = meanLongitudeAtGivenJulianDate_ - longitudeOfPerihelionAtGivenJulianDate_ + ( approximatePlanetPositionsDataContainer_ . additionalTermB_ * pow ( numberOfCenturiesPastJ2000_ , 2.0 ) ) + ( approximatePlanetPositionsDataContainer_ . additionalTermC_ * cos ( unit_conversions :: convertDegreesToRadians ( approximatePlanetPositionsDataContainer_ . additionalTermF_ * numberOfCenturiesPastJ2000_ ) ) ) + ( approximatePlanetPositionsDataContainer_ . additionalTermS_ * sin ( unit_conversions :: convertDegreesToRadians ( approximatePlanetPositionsDataContainer_ . additionalTermF_ * numberOfCenturiesPastJ2000_ ) ) ) ; meanAnomalyAtGivenJulianDate_ = basic_mathematics :: computeModulo ( meanAnomalyAtGivenJulianDate_ , 360.0 ) ; if ( meanAnomalyAtGivenJulianDate_ > 180.0 ) { meanAnomalyAtGivenJulianDate_ -= 360.0 ; } eccentricAnomalyAtGivenJulianDate_ = convertMeanAnomalyToEccentricAnomaly ( planetKeplerianElementsAtGivenJulianDate_ ( eccentricityIndex ) , unit_conversions :: convertDegreesToRadians ( meanAnomalyAtGivenJulianDate_ ) ) ; trueAnomalyAtGivenJulianData_ = orbital_element_conversions :: convertEccentricAnomalyToTrueAnomaly ( eccentricAnomalyAtGivenJulianDate_ , planetKeplerianElementsAtGivenJulianDate_ ( eccentricityIndex ) ) ; planetKeplerianElementsAtGivenJulianDate_ ( trueAnomalyIndex ) = trueAnomalyAtGivenJulianData_ ; planetKeplerianElementsAtGivenJulianDate_ ( semiMajorAxisIndex ) = unit_conversions :: convertAstronomicalUnitsToMeters ( planetKeplerianElementsAtGivenJulianDate_ ( semiMajorAxisIndex ) ) ; planetKeplerianElementsAtGivenJulianDate_ ( inclinationIndex ) = unit_conversions :: convertDegreesToRadians ( planetKeplerianElementsAtGivenJulianDate_ ( inclinationIndex ) ) ; planetKeplerianElementsAtGivenJulianDate_ ( longitudeOfAscendingNodeIndex ) = unit_conversions :: convertDegreesToRadians ( planetKeplerianElementsAtGivenJulianDate_ ( longitudeOfAscendingNodeIndex ) ) ; planetKeplerianElementsAtGivenJulianDate_ ( argumentOfPeriapsisIndex ) = unit_conversions :: convertDegreesToRadians ( planetKeplerianElementsAtGivenJulianDate_ ( argumentOfPeriapsisIndex ) ) ; return planetKeplerianElementsAtGivenJulianDate_ ; }
Get keplerian state from ephemeris.
Get keplerian state from ephemeris .
// Set Julian date. // Compute number of centuries past J2000. // Compute and set semi-major axis of planet at given Julian date. // Compute and set eccentricity of planet at given Julian date. // Compute and set inclination of planet at given Julian date. // Compute and set longitude of ascending node of planet at given Julian date. // Compute longitude of perihelion of planet at given Julian date. // Compute and set argument of periapsis of planet at given Julian date. // Compute mean longitude of planet at given Julian date. // Compute mean anomaly of planet at given Julian date. // Compute modulo of mean anomaly for interval : // 0 <= meanAnomalyAtGivenJulianDate_ < 360. // Translate mean anomaly to: // -180 < meanAnomalyAtGivenJulianDate_ <= 180 bounds. // Convert mean anomaly to eccentric anomaly. // Convert eccentric anomaly to true anomaly and set in planet elements. // Convert Keplerian elements to standard units. // Convert semi-major axis from AU to meters. // Convert inclination from degrees to radians. // Convert longitude of ascending node from degrees to radians. // Convert argument of periapsis from degrees to radians.