Skip to content

Commit 10d34e9

Browse files
committed
use planet 3D position provided by stellarium directly
1 parent 26fd52b commit 10d34e9

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/core/modules/Star.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,12 @@ struct Star
237237
}
238238

239239
//to get new 3D cartesian position for parallax effect given current star 3D cartesian position, planet orbital period and radius and current delta time from catalog epoch
240-
inline void getPlxEffect(double plx, Vec3f& bS, double operiod, double oradius, double dyrs) const {
240+
inline void getPlxEffect(double plx, Vec3f& bS, const Vec3d diffPos) const {
241241
if (plx <= 0) return;
242242
Vec3d bSd(bS[0], bS[1], bS[2]);
243243
bSd.normalize();
244244
bSd *= 1000./ plx;
245-
// remainder of dt in dyrs divided by period
246-
double dt = fmod(dyrs, operiod); // to get phase of the orbit
247-
Vec3d b0Ecl(oradius * cos(2 * M_PI / operiod * dt), oradius * sin(2 * M_PI / operiod * dt), 0.);
248-
bS = (bSd + b0Ecl * MAS2RAD * 1000.).toVec3f();
245+
bS = (bSd + diffPos * MAS2RAD * 1000.).toVec3f();
249246
}
250247
};
251248

src/core/modules/StarMgr.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "Planet.hpp"
4646
#include "StelUtils.hpp"
4747
#include "StelHealpix.hpp"
48+
#include "SolarSystem.hpp"
4849

4950
#include <QTextStream>
5051
#include <QFile>
@@ -1242,16 +1243,26 @@ void StarMgr::draw(StelCore* core)
12421243
maxMagStarName = x;
12431244
}
12441245
int zone;
1245-
const double withParallax = core->getUseParallax() * core->getParallaxFactor();
1246-
double orbital_period = core->getCurrentPlanet()->getSiderealPeriod() / 365.25; // in earth years
1247-
// get orbital_radius in AU using Kepler's third law
1248-
double orbital_radius = pow(orbital_period, 2.0/3.0);
1246+
double withParallax = core->getUseParallax() * core->getParallaxFactor();
1247+
Vec3d diffPos(0., 0., 0.);
1248+
if (withParallax) {
1249+
static SolarSystem *ssystem=GETSTELMODULE(SolarSystem);
1250+
const PlanetP earth = ssystem->getEarth();
1251+
// diff between earth location at STAR_CATALOG_JDEPOCH and current location
1252+
Vec3d earthPosCatalog = earth->getHeliocentricEclipticPos(STAR_CATALOG_JDEPOCH);
1253+
Vec3d PosNow = core->getCurrentPlanet()->getHeliocentricEclipticPos(core->getJDE());
1254+
double obliquity = earth->getRotObliquity(core->getJDE()); // need to always use Earth's obliquity because thats what the catalog is based on
1255+
// Transform from heliocentric ecliptic to equatorial coordinates
1256+
earthPosCatalog.set(earthPosCatalog[0], earthPosCatalog[1]*cos(obliquity)-earthPosCatalog[2]*sin(obliquity), earthPosCatalog[1]*sin(obliquity)+earthPosCatalog[2]*cos(obliquity));
1257+
PosNow.set(PosNow[0], PosNow[1]*cos(obliquity)-PosNow[2]*sin(obliquity), PosNow[1]*sin(obliquity)+PosNow[2]*cos(obliquity));
1258+
diffPos = earthPosCatalog - PosNow;
1259+
}
12491260
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1250-
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf, withParallax, orbital_period, orbital_radius);
1261+
z->draw(&sPainter, zone, true, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf, withParallax, diffPos);
12511262
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,z->level);(zone = it1.next()) >= 0;)
1252-
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, velf, withParallax, orbital_period, orbital_radius);
1263+
z->draw(&sPainter, zone, false, rcmag_table, limitMagIndex, core, maxMagStarName,names_brightness, viewportCaps, withAberration, velf, withParallax, diffPos);
12531264
// always check the last zone because it is a global zone
1254-
z->draw(&sPainter, (20<<(z->level<<1)), false, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf, withParallax, orbital_period, orbital_radius);
1265+
z->draw(&sPainter, (20<<(z->level<<1)), false, rcmag_table, limitMagIndex, core, maxMagStarName, names_brightness, viewportCaps, withAberration, velf, withParallax, diffPos);
12551266
}
12561267
exit_loop:
12571268

src/core/modules/ZoneArray.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ template<class Star>
425425
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsideViewport, const RCMag* rcmag_table,
426426
int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness,
427427
const QVector<SphericalCap> &boundingCaps,
428-
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const
428+
const bool withAberration, const Vec3f vel, const double withParallax, const Vec3d diffPos) const
429429
{
430430
StelSkyDrawer* drawer = core->getSkyDrawer();
431431
Vec3f vf;
@@ -500,7 +500,7 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
500500
}
501501

502502
if (withParallax) {
503-
s->getPlxEffect(withParallax * Plx, vf, operiod, oradius, dyrs);
503+
s->getPlxEffect(withParallax * Plx, vf, diffPos);
504504
}
505505

506506
// Aberration: vf contains Equatorial J2000 position.

src/core/modules/ZoneArray.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ZoneArray
110110
const RCMag* rcmag_table, int limitMagIndex, StelCore* core,
111111
int maxMagStarName, float names_brightness,
112112
const QVector<SphericalCap>& boundingCaps,
113-
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const = 0;
113+
const bool withAberration, const Vec3f vel, const double withParallax, const Vec3d diffPos) const = 0;
114114

115115
//! Get whether or not the catalog was successfully loaded.
116116
//! @return @c true if at least one zone was loaded, otherwise @c false
@@ -182,7 +182,7 @@ class SpecialZoneArray : public ZoneArray
182182
const RCMag *rcmag_table, int limitMagIndex, StelCore* core,
183183
int maxMagStarName, float names_brightness,
184184
const QVector<SphericalCap>& boundingCaps,
185-
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const override;
185+
const bool withAberration, const Vec3f vel, const double withParallax, const Vec3d diffPos) const override;
186186

187187
void searchAround(const StelCore* core, int index,const Vec3d &v,double cosLimFov,
188188
QList<StelObjectP > &result) override;

0 commit comments

Comments
 (0)