fix: avoid singularities

This commit is contained in:
Cat Flynn 2024-09-28 20:15:29 +01:00
parent c30a4e5e22
commit 919d809467
2 changed files with 10 additions and 0 deletions

View File

@ -53,4 +53,5 @@ private:
double _meanAnomalyAtEpoch = 0;
const double getEccentricAnomaly() const;
static void makeSafe(double& value);
};

View File

@ -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;
}