qtrocket/sim/SphericalGravityModel.cpp
Travis Hunter e6bf1fea9b
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc-13, g++-13, ubuntu-latest) (push) Has been cancelled
Revert "Merge pull request #20 from cthunter01/propagator"
This reverts commit 6280d9fb0184275843a8f4406c7293e41e65a639, reversing
changes made to 3c9c8b8c6a2b2e7430ff09efdc2cc0c1996b16ca.
2025-04-16 18:23:28 -06:00

51 lines
1.1 KiB
C++

/// \cond
// C headers
// C++ headers
#include <cmath>
// 3rd party headers
/// \endcond
// qtrocket headers
#include "sim/SphericalGravityModel.h"
#include "utils/math/Constants.h"
namespace sim
{
SphericalGravityModel::SphericalGravityModel()
{
}
SphericalGravityModel::~SphericalGravityModel()
{
}
Vector3 SphericalGravityModel::getAccel(double x, double y, double z)
{
// Convert x, y, z from meters to km. This is to avoid potential precision losses
// with using the earth's gravitation parameter in meters (14 digit number).
// GM in kilometers is much more manageable.
// An alternative is to use quadruple precision, but that may
// take a lot more computation time and I think this will be fine.
double x_km = x / 1000.0;
double y_km = y / 1000.0;
double z_km = z / 1000.0;
double r_km = std::sqrt(x_km * x_km + y_km * y_km + z_km * z_km);
double accelFactor = - utils::math::Constants::earthGM_km / std::sqrt(r_km * r_km * r_km);
double ax = accelFactor * x_km * 1000.0;
double ay = accelFactor * y_km * 1000.0;
double az = accelFactor * z_km * 1000.0;
return Vector3(ax, ay, az);
}
}