From ed3d90a95a2c7762832a40dda4d59a3d4fc6de53 Mon Sep 17 00:00:00 2001 From: Henry Leung Date: Fri, 20 Dec 2024 23:47:43 -0500 Subject: [PATCH 1/5] densely sampling orbit of parent planet if on its moon at the location where parent planet's orbit is at the closest to the present location of the moon --- src/core/modules/Planet.cpp | 46 +++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/core/modules/Planet.cpp b/src/core/modules/Planet.cpp index cb7625e681d4a..6bbe22b300c6c 100644 --- a/src/core/modules/Planet.cpp +++ b/src/core/modules/Planet.cpp @@ -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 + { + // only if we are also drawing my parent + fromMoonPerspective = core->getCurrentPlanet()->getParent()->getID() == getID(); + } const StelProjectorP prj = core->getProjection(StelCore::FrameHeliocentricEclipticJ2000); KeplerOrbit *keplerOrbit=static_cast(orbitPtr); @@ -4890,10 +4893,45 @@ void Planet::drawOrbit(const StelCore* core) sPainter.setColor(getCurrentOrbitColor(), orbitFader.getInterstate()); Vec3d onscreen; + + if (!fromMoonPerspective) { + // 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); + Vec3d parentPos = parent->getHeliocentricEclipticPos(dateJDE)+ parent->getAberrationPush(); // aberrationPush is not strictly correct, but helps a lot... + + // pretend they are on x-y plane + myPos[2] = 0; + myparentPos[2] = 0; + parentPos[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; + for(int d = 0; d < ORBIT_SEGMENTS; d++) + { + f = static_cast(d - ORBIT_SEGMENTS/2.) / (ORBIT_SEGMENTS/2.); + calc_date = dateJDE + pow(f, 13)*deltaOrbitJDE*ORBIT_SEGMENTS/2. + theta/180.*deltaOrbitJDE*ORBIT_SEGMENTS/2; + orbit[d] = getEclipticPos(calc_date) + parentPos; + } + Vec3d offsetPos = (getEclipticPos(dateJDE) + parentPos) - (getHeliocentricEclipticPos()+aberrationPush); + for(int d = 0; d < ORBIT_SEGMENTS; d++) + { + orbit[d] -= offsetPos; + } + } const Vec3d savePos = orbit[ORBIT_SEGMENTS/2]; if (closeOrbit) { - if (!keplerOrbit || keplerOrbit->getEccentricity()<=0.3) + if ((!keplerOrbit || keplerOrbit->getEccentricity()<=0.3) && !fromMoonPerspective) // 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; From 22ebe5b6112760cdb23794b111805498a406e703 Mon Sep 17 00:00:00 2001 From: Henry Leung Date: Sat, 21 Dec 2024 00:00:07 -0500 Subject: [PATCH 2/5] add comments and remove a few unused lines --- src/core/modules/Planet.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/core/modules/Planet.cpp b/src/core/modules/Planet.cpp index 6bbe22b300c6c..f982ddcd3c3f5 100644 --- a/src/core/modules/Planet.cpp +++ b/src/core/modules/Planet.cpp @@ -4904,12 +4904,10 @@ void Planet::drawOrbit(const StelCore* core) Vec3d myPos = core->getCurrentPlanet()->getHeliocentricEclipticPos(lastJDE); Vec3d myparentPos = core->getCurrentPlanet()->getParent()->getHeliocentricEclipticPos(dateJDE); - Vec3d parentPos = parent->getHeliocentricEclipticPos(dateJDE)+ parent->getAberrationPush(); // aberrationPush is not strictly correct, but helps a lot... // pretend they are on x-y plane myPos[2] = 0; myparentPos[2] = 0; - parentPos[2] = 0; // angle between me and parent double theta = atan2(myPos[1], myPos[0]) - atan2(myparentPos[1], myparentPos[0]); @@ -4919,13 +4917,10 @@ void Planet::drawOrbit(const StelCore* core) for(int d = 0; d < ORBIT_SEGMENTS; d++) { f = static_cast(d - ORBIT_SEGMENTS/2.) / (ORBIT_SEGMENTS/2.); + // 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) + parentPos; - } - Vec3d offsetPos = (getEclipticPos(dateJDE) + parentPos) - (getHeliocentricEclipticPos()+aberrationPush); - for(int d = 0; d < ORBIT_SEGMENTS; d++) - { - orbit[d] -= offsetPos; + orbit[d] = getEclipticPos(calc_date); } } const Vec3d savePos = orbit[ORBIT_SEGMENTS/2]; From c32e4c3adef431338c1c9530e6158b7949ceaa10 Mon Sep 17 00:00:00 2001 From: Henry Leung Date: Sun, 22 Dec 2024 00:00:24 -0500 Subject: [PATCH 3/5] fix various review comments --- src/core/modules/Planet.cpp | 41 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/core/modules/Planet.cpp b/src/core/modules/Planet.cpp index f982ddcd3c3f5..740f6502e5429 100644 --- a/src/core/modules/Planet.cpp +++ b/src/core/modules/Planet.cpp @@ -4877,10 +4877,10 @@ void Planet::drawOrbit(const StelCore* core) return; } bool fromMoonPerspective = false; - if (core->getCurrentPlanet()->pType == 2) // if I am a moon + if (core->getCurrentPlanet()->pType == isMoon || core->getCurrentPlanet()->pType == isObserver) // if I am a moon or observer of a planet { // only if we are also drawing my parent - fromMoonPerspective = core->getCurrentPlanet()->getParent()->getID() == getID(); + fromMoonPerspective = core->getCurrentPlanet()->getParent() == this; } const StelProjectorP prj = core->getProjection(StelCore::FrameHeliocentricEclipticJ2000); @@ -4894,42 +4894,43 @@ void Planet::drawOrbit(const StelCore* core) sPainter.setColor(getCurrentOrbitColor(), orbitFader.getInterstate()); Vec3d onscreen; - if (!fromMoonPerspective) { - // Update the orbit positions to the current planet date. - computeOrbit(); - } - else { + if (fromMoonPerspective) { 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 - 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 + Vec3d myPos = core->getCurrentPlanet()->getHeliocentricEclipticPos(dateJDE); + Vec3d myparentPos = getHeliocentricEclipticPos(dateJDE); + // orbital plane normal of parent planet, computed with the pos ~quarter of the orbit later + Vec3d orbitalNormal = myparentPos ^ getHeliocentricEclipticPos(dateJDE + deltaOrbitJDE*ORBIT_SEGMENTS/4); + orbitalNormal.normalize(); + // project myPos into the orbital plane of parent planet using the normal of orbital plane + Vec3d myPosProjected = myPos - myPos.dot(orbitalNormal) * orbitalNormal; + // angle between myPos already projected onto the orbital plane of parent planet and the plane + // we should concentrate on this theta when sampling orbit + double theta = (atan2((myparentPos ^ myPosProjected).dot(orbitalNormal), myparentPos.dot(myPosProjected))) / M_PI; double f; for(int d = 0; d < ORBIT_SEGMENTS; d++) { - f = static_cast(d - ORBIT_SEGMENTS/2.) / (ORBIT_SEGMENTS/2.); + f = (d - ORBIT_SEGMENTS/2.) / (ORBIT_SEGMENTS/2.); // 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; + calc_date = dateJDE + pow(f, 13)*deltaOrbitJDE*ORBIT_SEGMENTS/2. + theta*deltaOrbitJDE*ORBIT_SEGMENTS/2; orbit[d] = getEclipticPos(calc_date); } } + else { + // Update the orbit positions to the current planet date. + computeOrbit(); + } const Vec3d savePos = orbit[ORBIT_SEGMENTS/2]; if (closeOrbit) { - if ((!keplerOrbit || keplerOrbit->getEccentricity()<=0.3) && !fromMoonPerspective) + if ((!keplerOrbit || keplerOrbit->getEccentricity()<=0.3) && !fromMoonPerspective) { // 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; + } orbit[ORBIT_SEGMENTS]=orbit[0]; } int nbIter = closeOrbit ? ORBIT_SEGMENTS : ORBIT_SEGMENTS-1; From 0917ba2e8563f25a38ca56aa3c613cbc1b33741a Mon Sep 17 00:00:00 2001 From: Henry Leung Date: Mon, 23 Dec 2024 09:21:42 -0500 Subject: [PATCH 4/5] fix indentations and a minor comment --- src/core/modules/Planet.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/modules/Planet.cpp b/src/core/modules/Planet.cpp index 740f6502e5429..50d8a0e2390a8 100644 --- a/src/core/modules/Planet.cpp +++ b/src/core/modules/Planet.cpp @@ -4909,10 +4909,9 @@ void Planet::drawOrbit(const StelCore* core) // we should concentrate on this theta when sampling orbit double theta = (atan2((myparentPos ^ myPosProjected).dot(orbitalNormal), myparentPos.dot(myPosProjected))) / M_PI; - double f; for(int d = 0; d < ORBIT_SEGMENTS; d++) { - f = (d - ORBIT_SEGMENTS/2.) / (ORBIT_SEGMENTS/2.); + const double f = (d - ORBIT_SEGMENTS/2.) / (ORBIT_SEGMENTS/2.); // 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*deltaOrbitJDE*ORBIT_SEGMENTS/2; @@ -4922,7 +4921,7 @@ void Planet::drawOrbit(const StelCore* core) else { // Update the orbit positions to the current planet date. computeOrbit(); - } + } const Vec3d savePos = orbit[ORBIT_SEGMENTS/2]; if (closeOrbit) { @@ -4930,7 +4929,7 @@ void Planet::drawOrbit(const StelCore* core) // 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; - } + } orbit[ORBIT_SEGMENTS]=orbit[0]; } int nbIter = closeOrbit ? ORBIT_SEGMENTS : ORBIT_SEGMENTS-1; From 11b3fa3faea75b1aaf6542a61a47e5546023bc07 Mon Sep 17 00:00:00 2001 From: Henry Leung Date: Mon, 23 Dec 2024 19:15:35 -0500 Subject: [PATCH 5/5] fix coding style --- src/core/modules/Planet.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/modules/Planet.cpp b/src/core/modules/Planet.cpp index 50d8a0e2390a8..b8dcce93ee39f 100644 --- a/src/core/modules/Planet.cpp +++ b/src/core/modules/Planet.cpp @@ -4918,14 +4918,16 @@ void Planet::drawOrbit(const StelCore* core) orbit[d] = getEclipticPos(calc_date); } } - else { + else + { // Update the orbit positions to the current planet date. computeOrbit(); } const Vec3d savePos = orbit[ORBIT_SEGMENTS/2]; if (closeOrbit) { - if ((!keplerOrbit || keplerOrbit->getEccentricity()<=0.3) && !fromMoonPerspective) { + if ((!keplerOrbit || keplerOrbit->getEccentricity()<=0.3) && !fromMoonPerspective) + { // 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;