]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/world.cpp
real days
[blobs.git] / src / world / world.cpp
index 1758c5e431ea4ebfb862dde58b4290408b5dd0e5..525222f284b77c9c6bc57cd3a40df77849be5fd8 100644 (file)
@@ -115,6 +115,16 @@ double Body::RotationalPeriod() const noexcept {
        }
 }
 
+double Body::DayLength() const noexcept {
+       if (!HasParent()) {
+               return RotationalPeriod();
+       }
+       double year = OrbitalPeriod();
+       double sidereal = RotationalPeriod();
+       double grade = (angular < 0.0 ? -1.0 : 1.0) * (std::abs(axis_tilt.x) > PI * 0.5 ? -1.0 : 1.0);
+       return std::abs((year * sidereal) / ( year + (grade * sidereal)));
+}
+
 double Body::SphereOfInfluence() const noexcept {
        if (HasParent()) {
                return orbit.SemiMajorAxis() * std::pow(Mass() / Parent().Mass(), 2.0 / 5.0);