chore: extract retrieving cartesian elements

This commit is contained in:
ktyl 2023-10-13 23:28:46 +01:00
parent 68e26c64c9
commit 7749e5cda4
2 changed files with 30 additions and 13 deletions

View File

@ -45,11 +45,8 @@ void Orbit::setElements(Vector6 keplerianElements)
regenerateVertices(); regenerateVertices();
} }
// Interpolate a position around the orbit. float Orbit::getEccentricAnomaly(const float meanAnomaly)
// t is in range 0..1 and wraps.
glm::vec3 Orbit::getPosition(const float meanAnomaly)
{ {
// Get eccentric anomaly from elliptical mean anomaly
const float eccentricity = _keplerianElements[astro::eccentricityIndex]; const float eccentricity = _keplerianElements[astro::eccentricityIndex];
float eccentricAnomaly = astro::convertEllipticalMeanAnomalyToEccentricAnomaly( float eccentricAnomaly = astro::convertEllipticalMeanAnomalyToEccentricAnomaly(
eccentricity, eccentricity,
@ -57,21 +54,36 @@ glm::vec3 Orbit::getPosition(const float meanAnomaly)
(float)10e-3, (float)10e-3,
100); 100);
// Get true anomaly from eccentric anomaly return eccentricAnomaly;
float trueAnomaly = astro::convertEccentricAnomalyToTrueAnomaly( }
eccentricAnomaly,
eccentricity);
std::vector<float> kepler(_keplerianElements); // Interpolate a position around the orbit.
kepler[astro::trueAnomalyIndex] = trueAnomaly; // t is in range 0..1 and wraps.
glm::vec3 Orbit::getPosition(const float meanAnomaly)
std::vector<float> cartesian = astro::convertKeplerianToCartesianElements(kepler, 1.0); {
Vector6 cartesian = getCartesianCoordinates(meanAnomaly);
return glm::vec3( return glm::vec3(
cartesian[astro::xPositionIndex], cartesian[astro::xPositionIndex],
cartesian[astro::yPositionIndex], cartesian[astro::yPositionIndex],
cartesian[astro::zPositionIndex]); cartesian[astro::zPositionIndex]);
} }
float Orbit::getTrueAnomaly(const float meanAnomaly)
{
const float eccentricAnomaly = getEccentricAnomaly(meanAnomaly);
const float eccentricity = _keplerianElements[astro::eccentricityIndex];
return astro::convertEccentricAnomalyToTrueAnomaly(
eccentricAnomaly,
eccentricity);
}
Vector6 Orbit::getCartesianCoordinates(const float meanAnomaly)
{
Vector6 kepler(_keplerianElements);
kepler[astro::trueAnomalyIndex] = getTrueAnomaly(meanAnomaly);
return astro::convertKeplerianToCartesianElements(kepler, 1.0);
}
glm::vec3 Orbit::getTangent(const float meanAnomaly) glm::vec3 Orbit::getTangent(const float meanAnomaly)
{ {
float epsilon = 0.01; float epsilon = 0.01;

View File

@ -13,8 +13,9 @@ public:
Orbit(Vector6 keplerianElements); Orbit(Vector6 keplerianElements);
void render(); void render();
// TODO: meanAnomaly in all these arguments actually means eccentricMeanAnomaly,
// will have to change that when adding non-ellipctical orbits - don't get confused!
glm::vec3 getPosition(const float meanAnomaly); glm::vec3 getPosition(const float meanAnomaly);
glm::vec3 getVelocity(const float meanAnomaly);
glm::vec3 getTangent(const float meanAnomaly); glm::vec3 getTangent(const float meanAnomaly);
void setElements(Vector6 keplerianElements); void setElements(Vector6 keplerianElements);
@ -31,4 +32,8 @@ private:
Vector6 _keplerianElements; Vector6 _keplerianElements;
void regenerateVertices(); void regenerateVertices();
float getEccentricAnomaly(const float meanAnomaly);
float getTrueAnomaly(const float meanAnomaly);
Vector6 getCartesianCoordinates(const float meanAnomaly);
}; };