Skip to content

Commit

Permalink
Feature/improve celestialbody info (#146)
Browse files Browse the repository at this point in the history
* Refactor test methods and improve celestial body data handling

Refactored existing test methods in APITests.cpp to include more explicit assertion on individual attributes, in order to increase granularity of test failure reports. Added more test methods to evaluate body information with and without J parameters, thereby extending the test coverage. Made changes to CelestialBody.cpp and CelestialBody.h to enable handling of J parameters. These changes provide a better grasp of where errors may occur, especially in handling precision-based data calculations. The updates will also allow for a more comprehensive validation of celestial body data and its processing.

* Update assertions to use ASSERT_NEAR instead of ASSERT_DOUBLE_EQ

Changed the test assertions to use ASSERT_NEAR instead of ASSERT_DOUBLE_EQ for comparing double numbers in astrodynamics tests. The ASSERT_NEAR function allows us to specify a tolerance within which the two compared numbers should fall, this caters to scenarios where there can be minor variations in calculation outcomes due to intricacies in floating-point arithmetic. The test still ensures that numerically significant deviations are not ignored by this change. Adjustments have also been made to some key calculated values for correctness.
  • Loading branch information
sylvain-guillet committed Nov 25, 2023
1 parent 407293c commit 4ab9b3c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 53 deletions.
28 changes: 24 additions & 4 deletions IO.Astrodynamics.Tests/APITests.cpp
Expand Up @@ -49,12 +49,12 @@ TEST(API, SitePropagation)

PropagateSiteProxy(windowTDBDto, site);

LoadKernelsProxy((sitePath+"/S134").c_str());
LoadKernelsProxy((sitePath + "/S134").c_str());


IO::Astrodynamics::API::DTO::StateVectorDTO sv[25];
ReadEphemerisProxy(windowTDBDto, 399, 399134, "J2000", "NONE", 3600, sv);
UnloadKernelsProxy((sitePath+"/S134").c_str());
UnloadKernelsProxy((sitePath + "/S134").c_str());

ASSERT_DOUBLE_EQ(4054782.9648194457, sv[0].position.x);
ASSERT_DOUBLE_EQ(-4799280.7521664528, sv[0].position.y);
Expand Down Expand Up @@ -155,8 +155,8 @@ TEST(API, SpacecraftPropagation)
scenario.Spacecraft.orbitalPlaneChangingManeuvers[0].engines[0] = "eng1";
scenario.Spacecraft.orbitalPlaneChangingManeuvers[0].maneuverOrder = 0;

scenario.Spacecraft.progradeAttitudes[0].maneuverOrder=1;
scenario.Spacecraft.progradeAttitudes[0].engines[0]="eng1";
scenario.Spacecraft.progradeAttitudes[0].maneuverOrder = 1;
scenario.Spacecraft.progradeAttitudes[0].engines[0] = "eng1";


//Execute propagation
Expand Down Expand Up @@ -448,6 +448,26 @@ TEST(API, GetBodyInformation)
ASSERT_DOUBLE_EQ(6378136.5999999998, res.Radii.x);
ASSERT_DOUBLE_EQ(6378136.5999999998, res.Radii.y);
ASSERT_DOUBLE_EQ(6356751.9000000002, res.Radii.z);
ASSERT_DOUBLE_EQ(0.001082616, res.J2);
ASSERT_DOUBLE_EQ(-2.5388099999999996e-06, res.J3);
ASSERT_DOUBLE_EQ(-1.6559699999999999e-06, res.J4);
}

TEST(API, GetBodyInformationWithoutJ)
{
auto res = GetCelestialBodyInfoProxy(301);
ASSERT_EQ(301, res.Id);
ASSERT_EQ(399, res.CenterOfMotionId);
ASSERT_STREQ("MOON", res.Name);
ASSERT_EQ(31001, res.FrameId);
ASSERT_STREQ("MOON_ME", res.FrameName);
ASSERT_DOUBLE_EQ(4902800066163.7959, res.GM);
ASSERT_DOUBLE_EQ(1737400, res.Radii.x);
ASSERT_DOUBLE_EQ(1737400, res.Radii.y);
ASSERT_DOUBLE_EQ(1737400, res.Radii.z);
ASSERT_TRUE(std::isnan(res.J2));
ASSERT_TRUE(std::isnan(res.J3));
ASSERT_TRUE(std::isnan(res.J4));
}

TEST(API, GetBodyInformationInvalidId)
Expand Down
34 changes: 17 additions & 17 deletions IO.Astrodynamics.Tests/ConicOrbitalElementsTests.cpp
Expand Up @@ -288,13 +288,13 @@ TEST(ConicOrbitalElements, CreateHelioSynchronousOrbit)
IO::Astrodynamics::Time::TDB epoch("2021-Jan-01 00:00:00.0000 TDB");
auto sun = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(10);
auto earth = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(399, sun);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth,7080636.3, 0.0001724, epoch);
ASSERT_DOUBLE_EQ(7080636.3000000147, res->GetSemiMajorAxis());
ASSERT_DOUBLE_EQ(98.1923322636721, res->GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth, 7080636.3, 0.0001724, epoch);
ASSERT_NEAR(7080636.3000000147, res->GetSemiMajorAxis(), 1E-03);
ASSERT_NEAR(98.1923322636721, res->GetInclination() * IO::Astrodynamics::Constants::RAD_DEG, 1E-03);
ASSERT_DOUBLE_EQ(0.0001724, res->GetEccentricity());
ASSERT_DOUBLE_EQ(0.19913424941575958, res->GetRightAscendingNodeLongitude());
ASSERT_NEAR(11.457444465360757, res->GetRightAscendingNodeLongitude() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_DOUBLE_EQ(270.0, res->GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(270.0, res->GetTrueAnomaly() * IO::Astrodynamics::Constants::RAD_DEG, 6);
ASSERT_NEAR(270.0, res->GetTrueAnomaly() * IO::Astrodynamics::Constants::RAD_DEG, 1E-06);
ASSERT_DOUBLE_EQ(epoch.GetSecondsFromJ2000().count(), res->GetEpoch().GetSecondsFromJ2000().count());
//Moon's geophysical properties doesn't exist by default
auto moon = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(301);
Expand All @@ -308,11 +308,11 @@ TEST(ConicOrbitalElements, CreateHelioSynchronousOrbitMarch)
IO::Astrodynamics::Time::TDB epoch("2021-MAR-22 00:00:00.0000 TDB");
auto sun = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(10);
auto earth = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(399, sun);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth,7080636.3, 0.0001724, epoch);
ASSERT_DOUBLE_EQ(7080636.3000000101, res->GetSemiMajorAxis());
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth, 7080636.3, 0.0001724, epoch);
ASSERT_NEAR(7080636.3000000101, res->GetSemiMajorAxis(),1E-03);
ASSERT_DOUBLE_EQ(98.1923322636721, res->GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(0.0001724, res->GetEccentricity());
ASSERT_DOUBLE_EQ(4.7331352670103488, res->GetRightAscendingNodeLongitude());
ASSERT_NEAR(4.7331352670103488, res->GetRightAscendingNodeLongitude(),1E-03);
ASSERT_DOUBLE_EQ(270.0, res->GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(270.0, res->GetTrueAnomaly() * IO::Astrodynamics::Constants::RAD_DEG, 6);
ASSERT_DOUBLE_EQ(epoch.GetSecondsFromJ2000().count(), res->GetEpoch().GetSecondsFromJ2000().count());
Expand All @@ -328,11 +328,11 @@ TEST(ConicOrbitalElements, CreateHelioSynchronousOrbitApril)
IO::Astrodynamics::Time::TDB epoch("2021-APR-22 00:00:00.0000 TDB");
auto sun = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(10);
auto earth = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(399, sun);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth,7080636.3, 0.0001724, epoch);
ASSERT_NEAR(7080636.299999997, res->GetSemiMajorAxis(),6);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth, 7080636.3, 0.0001724, epoch);
ASSERT_NEAR(7080636.299999997, res->GetSemiMajorAxis(), 6);
ASSERT_DOUBLE_EQ(98.1923322636721, res->GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(0.0001724, res->GetEccentricity());
ASSERT_DOUBLE_EQ(5.229578833367329, res->GetRightAscendingNodeLongitude());
ASSERT_NEAR(5.229578833367329, res->GetRightAscendingNodeLongitude(),1E-03);
ASSERT_DOUBLE_EQ(270.0, res->GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(270.0, res->GetTrueAnomaly() * IO::Astrodynamics::Constants::RAD_DEG, 6);
ASSERT_DOUBLE_EQ(epoch.GetSecondsFromJ2000().count(), res->GetEpoch().GetSecondsFromJ2000().count());
Expand All @@ -348,11 +348,11 @@ TEST(ConicOrbitalElements, CreateHelioSynchronousOrbitAugust)
IO::Astrodynamics::Time::TDB epoch("2021-AUG-22 00:00:00.0000 TDB");
auto sun = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(10);
auto earth = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(399, sun);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth,7080636.3, 0.0001724, epoch);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth, 7080636.3, 0.0001724, epoch);
ASSERT_NEAR(7080636.3000000054, res->GetSemiMajorAxis(), 6);
ASSERT_DOUBLE_EQ(98.1923322636721, res->GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(0.0001724, res->GetEccentricity());
ASSERT_DOUBLE_EQ(1.0642024373543861, res->GetRightAscendingNodeLongitude());
ASSERT_NEAR(1.0642024373543861, res->GetRightAscendingNodeLongitude(),1E-03);
ASSERT_DOUBLE_EQ(270.0, res->GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(270.0, res->GetTrueAnomaly() * IO::Astrodynamics::Constants::RAD_DEG, 6);
ASSERT_DOUBLE_EQ(epoch.GetSecondsFromJ2000().count(), res->GetEpoch().GetSecondsFromJ2000().count());
Expand All @@ -368,11 +368,11 @@ TEST(ConicOrbitalElements, CreateHelioSynchronousOrbitNovember)
IO::Astrodynamics::Time::TDB epoch("2021-Nov-22 00:00:00.0000 TDB");
auto sun = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(10);
auto earth = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(399, sun);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth,7080636.3, 0.0001724, epoch);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchronousOrbit(earth, 7080636.3, 0.0001724, epoch);
ASSERT_NEAR(7080636.3000000054, res->GetSemiMajorAxis(), 6);
ASSERT_DOUBLE_EQ(98.1923322636721, res->GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(0.0001724, res->GetEccentricity());
ASSERT_DOUBLE_EQ(5.7140833665781239, res->GetRightAscendingNodeLongitude());
ASSERT_NEAR(5.7140833665781239, res->GetRightAscendingNodeLongitude(),1E-03);
ASSERT_DOUBLE_EQ(270.0, res->GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(270.0, res->GetTrueAnomaly() * IO::Astrodynamics::Constants::RAD_DEG, 6);
ASSERT_DOUBLE_EQ(epoch.GetSecondsFromJ2000().count(), res->GetEpoch().GetSecondsFromJ2000().count());
Expand All @@ -388,11 +388,11 @@ TEST(ConicOrbitalElements, CreatePhasedHelioSynchronousOrbit)
IO::Astrodynamics::Time::TDB epoch("2021-Nov-22 00:00:00.0000 TDB");
auto sun = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(10);
auto earth = std::make_shared<IO::Astrodynamics::Body::CelestialBody>(399, sun);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthPhasedHelioSynchronousOrbit(earth,0.0001724, epoch,14);
auto res = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthPhasedHelioSynchronousOrbit(earth, 0.0001724, epoch, 14);
ASSERT_NEAR(7272221.8759850441, res->GetSemiMajorAxis(), 6);
ASSERT_DOUBLE_EQ(99.00111990363385, res->GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(0.0001724, res->GetEccentricity());
ASSERT_DOUBLE_EQ(5.7140833665781239, res->GetRightAscendingNodeLongitude());
ASSERT_NEAR(5.7140833665781239, res->GetRightAscendingNodeLongitude(),1E-03);
ASSERT_DOUBLE_EQ(270.0, res->GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(270.0, res->GetTrueAnomaly() * IO::Astrodynamics::Constants::RAD_DEG, 6);
ASSERT_DOUBLE_EQ(epoch.GetSecondsFromJ2000().count(), res->GetEpoch().GetSecondsFromJ2000().count());
Expand Down
22 changes: 11 additions & 11 deletions IO.Astrodynamics.Tests/PropagatorTests.cpp
Expand Up @@ -345,23 +345,23 @@ TEST(Propagator, NodePrecession)
auto sv1 = spc.ReadEphemeris(IO::Astrodynamics::Frames::InertialFrames::ICRF(), IO::Astrodynamics::AberrationsEnum::None, epoch,
*earth);

ASSERT_DOUBLE_EQ(7080636.3000000259, sv1.GetSemiMajorAxis());
ASSERT_DOUBLE_EQ(0.00017239999999989656, sv1.GetEccentricity());
ASSERT_NEAR(7080636.3000000259, sv1.GetSemiMajorAxis(),1E-03);
ASSERT_NEAR(0.00017239999999989656, sv1.GetEccentricity(),1E-06);
ASSERT_DOUBLE_EQ(98.192332263672071, sv1.GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(11.409552048028507, sv1.GetRightAscendingNodeLongitude() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(269.99999999926399, sv1.GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(270.0197555854142, sv1.GetMeanAnomaly() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(11.457444465360759, sv1.GetRightAscendingNodeLongitude() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_NEAR(269.99999999926399, sv1.GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_NEAR(270.0197555854142, sv1.GetMeanAnomaly() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_DOUBLE_EQ(662731200.0, sv1.GetEpoch().GetSecondsFromJ2000().count());

//Read ephemeris
auto sv2 = spc.ReadEphemeris(IO::Astrodynamics::Frames::InertialFrames::ICRF(), IO::Astrodynamics::AberrationsEnum::None, epoch + (step * 86400.0 * 2.0) - step,
*earth);
ASSERT_DOUBLE_EQ(7067118.6922611883, sv2.GetSemiMajorAxis());
ASSERT_DOUBLE_EQ(0.061058116709275446, sv2.GetEccentricity());
ASSERT_DOUBLE_EQ(98.328721713635034, sv2.GetInclination() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(13.182937015734543, sv2.GetRightAscendingNodeLongitude() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(117.17940166935723, sv2.GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_DOUBLE_EQ(125.54397178728212, sv2.GetMeanAnomaly() * IO::Astrodynamics::Constants::RAD_DEG);
ASSERT_NEAR(7067115.6397116547, sv2.GetSemiMajorAxis(),1E-03);
ASSERT_NEAR(0.061151770321037829, sv2.GetEccentricity(),1E-03);
ASSERT_NEAR(98.328672105613478, sv2.GetInclination() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_NEAR(13.230478085368484, sv2.GetRightAscendingNodeLongitude() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_NEAR(117.13501897544079, sv2.GetPeriapsisArgument() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_NEAR(125.5993464910642, sv2.GetMeanAnomaly() * IO::Astrodynamics::Constants::RAD_DEG,1E-03);
ASSERT_DOUBLE_EQ(662903999.0, sv2.GetEpoch().GetSecondsFromJ2000().count());
}

Expand Down
3 changes: 3 additions & 0 deletions IO.Astrodynamics/API/DTO/CelestialBodyDTO.h
Expand Up @@ -17,6 +17,9 @@ namespace IO::Astrodynamics::API::DTO
const char *FrameName{};
int FrameId{};
const char *Error{};
double J2{};
double J3{};
double J4{};
};
}
#endif //IOSDK_CELESTIALBODYDTO_H
5 changes: 5 additions & 0 deletions IO.Astrodynamics/API/Proxy.cpp
Expand Up @@ -548,6 +548,11 @@ IO::Astrodynamics::API::DTO::CelestialBodyDTO GetCelestialBodyInfoProxy(int body
// Search CelestialItem's mass
res.GM = IO::Astrodynamics::Body::CelestialBody::ReadGM(bodyId);

//Read J Parameters
res.J2 = IO::Astrodynamics::Body::CelestialBody::ReadJ2(bodyId);
res.J3 = IO::Astrodynamics::Body::CelestialBody::ReadJ3(bodyId);
res.J4 = IO::Astrodynamics::Body::CelestialBody::ReadJ4(bodyId);

// Search frame
if (!IO::Astrodynamics::Body::CelestialBody::IsBarycenter(bodyId))
{
Expand Down
22 changes: 11 additions & 11 deletions IO.Astrodynamics/Body/CelestialBody.cpp
Expand Up @@ -22,7 +22,7 @@ IO::Astrodynamics::Body::CelestialBody::CelestialBody(const int id, std::shared_
IO::Astrodynamics::Constants::G,
centerOfMotion),
m_BodyFixedFrame{""},
m_J2{ReadJ2()}, m_J3{ReadJ3()}, m_J4{ReadJ4()}
m_J2{ReadJ2(id)}, m_J3{ReadJ3(id)}, m_J4{ReadJ4(id)}
{
const_cast<double &>(m_sphereOfInfluence) = IO::Astrodynamics::Body::SphereOfInfluence(m_orbitalParametersAtEpoch->GetSemiMajorAxis(),
m_orbitalParametersAtEpoch->GetCenterOfMotion()->GetMu(), m_mu);
Expand Down Expand Up @@ -54,7 +54,7 @@ IO::Astrodynamics::Body::CelestialBody::CelestialBody(const int id, std::shared_

IO::Astrodynamics::Body::CelestialBody::CelestialBody(const int id) : IO::Astrodynamics::Body::CelestialItem(id, "", ReadGM(id) / IO::Astrodynamics::Constants::G),
m_BodyFixedFrame{""},
m_J2{ReadJ2()}, m_J3{ReadJ3()}, m_J4{ReadJ4()}
m_J2{ReadJ2(id)}, m_J3{ReadJ3(id)}, m_J4{ReadJ4(id)}
{
SpiceBoolean found;
SpiceChar name[32];
Expand Down Expand Up @@ -263,30 +263,30 @@ bool IO::Astrodynamics::Body::CelestialBody::IsLagrangePoint(int celestialBodyId
return celestialBodyId == 391 || celestialBodyId == 392 || celestialBodyId == 393 || celestialBodyId == 394;
}

double IO::Astrodynamics::Body::CelestialBody::ReadJ2() const
double IO::Astrodynamics::Body::CelestialBody::ReadJ2(int bodyId)
{
return ReadJValue("J2");
return ReadJValue(bodyId, "J2");
}

double IO::Astrodynamics::Body::CelestialBody::ReadJ3() const
double IO::Astrodynamics::Body::CelestialBody::ReadJ3(int bodyId)
{
return ReadJValue("J3");
return ReadJValue(bodyId, "J3");
}

double IO::Astrodynamics::Body::CelestialBody::ReadJ4() const
double IO::Astrodynamics::Body::CelestialBody::ReadJ4(int bodyId)
{
return ReadJValue("J4");
return ReadJValue(bodyId, "J4");
}

double IO::Astrodynamics::Body::CelestialBody::ReadJValue(const char *valueName) const
double IO::Astrodynamics::Body::CelestialBody::ReadJValue(int bodyId, const char *valueName)
{
if (!bodfnd_c(m_id, valueName))
if (!bodfnd_c(bodyId, valueName))
{
return std::numeric_limits<double>::quiet_NaN();
}
SpiceInt dim;
SpiceDouble res[1];
bodvcd_c(m_id, valueName, 1, &dim, res);
bodvcd_c(bodyId, valueName, 1, &dim, res);
if (dim == 0)
{
return std::numeric_limits<double>::quiet_NaN();
Expand Down
16 changes: 8 additions & 8 deletions IO.Astrodynamics/Body/CelestialBody.h
Expand Up @@ -46,14 +46,6 @@ namespace IO::Astrodynamics::Body
const double m_J3{};
const double m_J4{};

double ReadJValue(const char *valueName) const;

double ReadJ2() const;

double ReadJ3() const;

double ReadJ4() const;


public:
/**
Expand Down Expand Up @@ -377,6 +369,14 @@ namespace IO::Astrodynamics::Body
*/

IO::Astrodynamics::Math::Vector3D GetBodyFixedPosition(double longitude, double latitude, const IO::Astrodynamics::Time::TDB &epoch) const;

static double ReadJValue(int bodyId, const char *valueName);

static double ReadJ2(int bodyId);

static double ReadJ3(int bodyId);

static double ReadJ4(int bodyId);
};

/**
Expand Down
6 changes: 4 additions & 2 deletions IO.Astrodynamics/OrbitalParameters/OrbitalParameters.cpp
Expand Up @@ -266,11 +266,13 @@ IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchro
double e22 = (1 - e2) * (1 - e2);
double sqrtGM = std::sqrt(earth->GetMu());
double re2 = eqRadius * eqRadius;
double m0=earth->GetOrbitalParametersAtEpoch()->GetMeanMotion();
double i = std::acos((2 * a72 * e22 * earth->GetOrbitalParametersAtEpoch()->GetMeanMotion()) / (3 * sqrtGM * -earth->GetJ2() * re2));

//Compute longitude of ascending node to orient orbit toward the sun
IO::Astrodynamics::Math::Vector3D sunVector = earth->ReadEphemeris(Frames::InertialFrames::ICRF(), AberrationsEnum::LT, epochAtDescendingNode, *earth->GetOrbitalParametersAtEpoch()->GetCenterOfMotion()).GetPosition().Reverse();
IO::Astrodynamics::Math::Plane sunPlane{IO::Astrodynamics::Math::Vector3D::VectorZ.CrossProduct(sunVector), 0.0};
auto zIcrf=earth->GetBodyFixedFrame().TransformVector(Frames::InertialFrames::ICRF(),Math::Vector3D::VectorZ,epochAtDescendingNode);
IO::Astrodynamics::Math::Plane sunPlane{zIcrf.CrossProduct(sunVector), 0.0};
double raanLongitude = sunPlane.GetAngle(IO::Astrodynamics::Math::Vector3D::VectorY);

if (sunVector.GetY() > 0.0)
Expand All @@ -285,7 +287,7 @@ IO::Astrodynamics::OrbitalParameters::OrbitalParameters::CreateEarthHelioSynchro
}

//Compute mean anomaly at ascending node
double m = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::ConvertTrueAnomalyToMeanAnomaly(Constants::PI2 + Constants::_2PI, eccentricity);
double m = IO::Astrodynamics::OrbitalParameters::OrbitalParameters::ConvertTrueAnomalyToMeanAnomaly(Constants::PI + Constants::PI2, eccentricity);
return std::make_unique<IO::Astrodynamics::OrbitalParameters::ConicOrbitalElements>(earth, p, eccentricity, i, raanLongitude, Constants::PI + Constants::PI2, m,
epochAtDescendingNode,
IO::Astrodynamics::Frames::InertialFrames::ICRF());
Expand Down

0 comments on commit 4ab9b3c

Please sign in to comment.