chore: extract retrieving cartesian elements
This commit is contained in:
parent
68e26c64c9
commit
7749e5cda4
|
@ -45,11 +45,8 @@ void Orbit::setElements(Vector6 keplerianElements)
|
|||
regenerateVertices();
|
||||
}
|
||||
|
||||
// Interpolate a position around the orbit.
|
||||
// t is in range 0..1 and wraps.
|
||||
glm::vec3 Orbit::getPosition(const float meanAnomaly)
|
||||
float Orbit::getEccentricAnomaly(const float meanAnomaly)
|
||||
{
|
||||
// Get eccentric anomaly from elliptical mean anomaly
|
||||
const float eccentricity = _keplerianElements[astro::eccentricityIndex];
|
||||
float eccentricAnomaly = astro::convertEllipticalMeanAnomalyToEccentricAnomaly(
|
||||
eccentricity,
|
||||
|
@ -57,21 +54,36 @@ glm::vec3 Orbit::getPosition(const float meanAnomaly)
|
|||
(float)10e-3,
|
||||
100);
|
||||
|
||||
// Get true anomaly from eccentric anomaly
|
||||
float trueAnomaly = astro::convertEccentricAnomalyToTrueAnomaly(
|
||||
eccentricAnomaly,
|
||||
eccentricity);
|
||||
return eccentricAnomaly;
|
||||
}
|
||||
|
||||
std::vector<float> kepler(_keplerianElements);
|
||||
kepler[astro::trueAnomalyIndex] = trueAnomaly;
|
||||
|
||||
std::vector<float> cartesian = astro::convertKeplerianToCartesianElements(kepler, 1.0);
|
||||
// Interpolate a position around the orbit.
|
||||
// t is in range 0..1 and wraps.
|
||||
glm::vec3 Orbit::getPosition(const float meanAnomaly)
|
||||
{
|
||||
Vector6 cartesian = getCartesianCoordinates(meanAnomaly);
|
||||
return glm::vec3(
|
||||
cartesian[astro::xPositionIndex],
|
||||
cartesian[astro::yPositionIndex],
|
||||
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)
|
||||
{
|
||||
float epsilon = 0.01;
|
||||
|
|
|
@ -13,8 +13,9 @@ public:
|
|||
Orbit(Vector6 keplerianElements);
|
||||
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 getVelocity(const float meanAnomaly);
|
||||
glm::vec3 getTangent(const float meanAnomaly);
|
||||
|
||||
void setElements(Vector6 keplerianElements);
|
||||
|
@ -31,4 +32,8 @@ private:
|
|||
Vector6 _keplerianElements;
|
||||
|
||||
void regenerateVertices();
|
||||
|
||||
float getEccentricAnomaly(const float meanAnomaly);
|
||||
float getTrueAnomaly(const float meanAnomaly);
|
||||
Vector6 getCartesianCoordinates(const float meanAnomaly);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue