Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Densely sampling orbit of parent planet if on its moon #4013

Merged
merged 5 commits into from
Dec 24, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions src/core/modules/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4876,9 +4876,12 @@ void Planet::drawOrbit(const StelCore* core)
if (!hasValidPositionalData(lastJDE, PositionQuality::OrbitPlotting))
return;
}

// Update the orbit positions to the current planet date.
computeOrbit();
bool fromMoonPerspective = false;
if (core->getCurrentPlanet()->pType == 2) // if I am a moon
alex-w marked this conversation as resolved.
Show resolved Hide resolved
{
// only if we are also drawing my parent
fromMoonPerspective = core->getCurrentPlanet()->getParent()->getID() == getID();
alex-w marked this conversation as resolved.
Show resolved Hide resolved
}

const StelProjectorP prj = core->getProjection(StelCore::FrameHeliocentricEclipticJ2000);
KeplerOrbit *keplerOrbit=static_cast<KeplerOrbit*>(orbitPtr);
Expand All @@ -4890,10 +4893,40 @@ void Planet::drawOrbit(const StelCore* core)

sPainter.setColor(getCurrentOrbitColor(), orbitFader.getInterstate());
Vec3d onscreen;

if (!fromMoonPerspective) {
alex-w marked this conversation as resolved.
Show resolved Hide resolved
// Update the orbit positions to the current planet date.
computeOrbit();
}
else {
double dateJDE = lastJDE;
double calc_date;

Vec3d myPos = core->getCurrentPlanet()->getHeliocentricEclipticPos(lastJDE);
Vec3d myparentPos = core->getCurrentPlanet()->getParent()->getHeliocentricEclipticPos(dateJDE);

// pretend they are on x-y plane
10110111 marked this conversation as resolved.
Show resolved Hide resolved
myPos[2] = 0;
myparentPos[2] = 0;

// angle between me and parent
double theta = atan2(myPos[1], myPos[0]) - atan2(myparentPos[1], myparentPos[0]);
theta = theta / M_PI * 180.; // should concentrate on this theta when sampling orbit

double f;
alex-w marked this conversation as resolved.
Show resolved Hide resolved
for(int d = 0; d < ORBIT_SEGMENTS; d++)
{
f = static_cast<double>(d - ORBIT_SEGMENTS/2.) / (ORBIT_SEGMENTS/2.);
alex-w marked this conversation as resolved.
Show resolved Hide resolved
// make sure only sample half of the orbit forward and half backward
// the sampling spacing is trial and error, but power of 13 seems to be good (i.e., densely sample around the current date)
calc_date = dateJDE + pow(f, 13)*deltaOrbitJDE*ORBIT_SEGMENTS/2. + theta/180.*deltaOrbitJDE*ORBIT_SEGMENTS/2;
orbit[d] = getEclipticPos(calc_date);
}
}
const Vec3d savePos = orbit[ORBIT_SEGMENTS/2];
if (closeOrbit)
{
if (!keplerOrbit || keplerOrbit->getEccentricity()<=0.3)
if ((!keplerOrbit || keplerOrbit->getEccentricity()<=0.3) && !fromMoonPerspective)
alex-w marked this conversation as resolved.
Show resolved Hide resolved
// special case - use current Planet position as center vertex so that draws
// on its orbit all the time (since orbit is shown as segmented rather than smooth curve)
orbit[ORBIT_SEGMENTS/2]=getHeliocentricEclipticPos()+aberrationPush;
Expand Down
Loading