From 919d809467739c9c4df832a363f35fd87af575bb Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Sat, 28 Sep 2024 20:15:29 +0100 Subject: [PATCH] fix: avoid singularities --- lib/skein/include/skein/orbit.h | 1 + lib/skein/src/orbit.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) 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; }