Tudat/Astrodynamics/TrajectoryDesign/exportTrajectory.cpp
//! Return a vector of positions and times corresponding to a trajectory at a certain epoch.
Return a vector of positions and times corresponding to a trajectory at a certain epoch.
Return a vector of positions and times corresponding to a trajectory at a certain epoch .
void returnTrajectory( Eigen::VectorXd initialCartesianState,
                       double centralBodyGravitationalParameter,
                       double duration,
                       double maximumTimeStep,
                       std::vector < Eigen::Vector3d >& positionVector,
                       std::vector < double >& timeVector,
                       double startingTime )
{
    int numberOfSteps = std::ceil( duration / maximumTimeStep );
    double timeStep = duration / numberOfSteps;
    positionVector.resize( numberOfSteps + 1 );
    timeVector.resize( numberOfSteps + 1 );
    Eigen::Vector6d cartesianElements ( 6 ), keplerianElements ( 6 );
    cartesianElements = initialCartesianState;
    double time = 0.0 + startingTime;
    positionVector[ 0 ] = cartesianElements.segment( 0, 3 );
    timeVector[ 0 ] = time;
    for ( int counter = 1; counter <= numberOfSteps; counter++ )
    {
        keplerianElements = orbital_element_conversions::convertCartesianToKeplerianElements(
                    cartesianElements, centralBodyGravitationalParameter );
        keplerianElements = orbital_element_conversions::propagateKeplerOrbit( keplerianElements,
                    timeStep, centralBodyGravitationalParameter );
        cartesianElements = orbital_element_conversions::convertKeplerianToCartesianElements(
                    keplerianElements, centralBodyGravitationalParameter );
        time += timeStep;
        positionVector[ counter ] = cartesianElements.segment( 0 , 3 );
        timeVector[ counter ] = time;
    }
}
void returnTrajectory ( Eigen :: VectorXd initialCartesianState , double centralBodyGravitationalParameter , double duration , double maximumTimeStep , std :: vector < Eigen :: Vector3d > & positionVector , std :: vector < double > & timeVector , double startingTime ) { int numberOfSteps = std :: ceil ( duration / maximumTimeStep ) ; double timeStep = duration / numberOfSteps ; positionVector . resize ( numberOfSteps + 1 ) ; timeVector . resize ( numberOfSteps + 1 ) ; Eigen :: Vector6d cartesianElements ( 6 ) , keplerianElements ( 6 ) ; cartesianElements = initialCartesianState ; double time = 0.0 + startingTime ; positionVector [ 0 ] = cartesianElements . segment ( 0 , 3 ) ; timeVector [ 0 ] = time ; for ( int counter = 1 ; counter <= numberOfSteps ; counter ++ ) { keplerianElements = orbital_element_conversions :: convertCartesianToKeplerianElements ( cartesianElements , centralBodyGravitationalParameter ) ; keplerianElements = orbital_element_conversions :: propagateKeplerOrbit ( keplerianElements , timeStep , centralBodyGravitationalParameter ) ; cartesianElements = orbital_element_conversions :: convertKeplerianToCartesianElements ( keplerianElements , centralBodyGravitationalParameter ) ; time += timeStep ; positionVector [ counter ] = cartesianElements . segment ( 0 , 3 ) ; timeVector [ counter ] = time ; } }
Return a vector of positions and times corresponding to a trajectory at a certain epoch.
Return a vector of positions and times corresponding to a trajectory at a certain epoch .
// Calculate the number of intermediate steps required and the corresponding time step. // Resize the position and time vectors. Note that the "+ 1" comes from the end points. // Initialize Cartesian and Keplerian coordinates vectors, for intermediate calculations. // Initiate the time variable. // Set the first position and time to that of the departure. // Calculate and set the intermediate points // Convert the cartesian elements into keplerian elements. // Propagate the keplerian elements with one timestep. // Convert the keplerian elements back into Cartesian elements. // Update the time. // Store the current time and position in their corresponding entry in their vector.