diff --git a/lib/skein/include/skein/orbit.h b/lib/skein/include/skein/orbit.h index 1aa1c8c..377dd3c 100644 --- a/lib/skein/include/skein/orbit.h +++ b/lib/skein/include/skein/orbit.h @@ -53,4 +53,5 @@ private: double _meanAnomalyAtEpoch = 0; const double getEccentricAnomaly() const; + static void makeSafe(double& value); }; diff --git a/lib/skein/src/orbit.cpp b/lib/skein/src/orbit.cpp index 97224b5..594ffa2 100644 --- a/lib/skein/src/orbit.cpp +++ b/lib/skein/src/orbit.cpp @@ -11,6 +11,12 @@ Orbit::Orbit() _keplerianElements.resize(6); } +// some values cause singularities when they are zero. so, make them not zero +void Orbit::makeSafe(double& value) +{ + value = value == 0.0 ? 0.0000001 : value; +} + double Orbit::getSemiMajorAxis() const { return _keplerianElements[astro::semiMajorAxisIndex]; @@ -35,6 +41,7 @@ double Orbit::getInclination() const } void Orbit::setInclination(double inclination) { + makeSafe(inclination); _keplerianElements[astro::inclinationIndex] = inclination; } @@ -44,6 +51,7 @@ double Orbit::getArgumentOfPeriapsis() const } void Orbit::setArgumentOfPeriapsis(double argumentOfPeriapsis) { + makeSafe(argumentOfPeriapsis); _keplerianElements[astro::argumentOfPeriapsisIndex] = argumentOfPeriapsis; } @@ -53,6 +61,7 @@ double Orbit::getLongitudeOfAscendingNode() const } void Orbit::setLongitudeOfAscendingNode(double longitudeOfAscendingNode) { + makeSafe(longitudeOfAscendingNode); _keplerianElements[astro::longitudeOfAscendingNodeIndex] = longitudeOfAscendingNode; }