Skip to content

Commit

Permalink
use planet 3D position provided by stellarium directly
Browse files Browse the repository at this point in the history
  • Loading branch information
henrysky committed Dec 24, 2024
1 parent 26fd52b commit 1908f9f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/core/modules/Star.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,12 @@ struct Star
}

//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
inline void getPlxEffect(double plx, Vec3f& bS, double operiod, double oradius, double dyrs) const {
inline void getPlxEffect(double plx, Vec3f& bS, const Vec3d diffPos) const {
if (plx <= 0) return;
Vec3d bSd(bS[0], bS[1], bS[2]);
bSd.normalize();
bSd *= 1000./ plx;
// remainder of dt in dyrs divided by period
double dt = fmod(dyrs, operiod); // to get phase of the orbit
Vec3d b0Ecl(oradius * cos(2 * M_PI / operiod * dt), oradius * sin(2 * M_PI / operiod * dt), 0.);
bS = (bSd + b0Ecl * MAS2RAD * 1000.).toVec3f();
bS = (bSd + diffPos * MAS2RAD * 1000.).toVec3f();
}
};

Expand Down
25 changes: 18 additions & 7 deletions src/core/modules/StarMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "Planet.hpp"
#include "StelUtils.hpp"
#include "StelHealpix.hpp"
#include "SolarSystem.hpp"

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

Expand Down
4 changes: 2 additions & 2 deletions src/core/modules/ZoneArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ template<class Star>
void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsideViewport, const RCMag* rcmag_table,
int limitMagIndex, StelCore* core, int maxMagStarName, float names_brightness,
const QVector<SphericalCap> &boundingCaps,
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const
const bool withAberration, const Vec3f vel, const double withParallax, const Vec3d diffPos) const
{
StelSkyDrawer* drawer = core->getSkyDrawer();
Vec3f vf;
Expand Down Expand Up @@ -500,7 +500,7 @@ void SpecialZoneArray<Star>::draw(StelPainter* sPainter, int index, bool isInsid
}

if (withParallax) {
s->getPlxEffect(withParallax * Plx, vf, operiod, oradius, dyrs);
s->getPlxEffect(withParallax * Plx, vf, diffPos);
}

// Aberration: vf contains Equatorial J2000 position.
Expand Down
4 changes: 2 additions & 2 deletions src/core/modules/ZoneArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ZoneArray
const RCMag* rcmag_table, int limitMagIndex, StelCore* core,
int maxMagStarName, float names_brightness,
const QVector<SphericalCap>& boundingCaps,
const bool withAberration, const Vec3f vel, const double withParallax, double operiod, double oradius) const = 0;
const bool withAberration, const Vec3f vel, const double withParallax, const Vec3d diffPos) const = 0;

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

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

0 comments on commit 1908f9f

Please sign in to comment.