Skip to content

Commit 910b92f

Browse files
committed
gaia actually give barycentric RA/DEC and refactor my code
1 parent f067ac6 commit 910b92f

3 files changed

Lines changed: 31 additions & 45 deletions

File tree

src/core/StelCore.cpp

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,67 +3105,57 @@ Vec3d StelCore::getMouseJ2000Pos() const
31053105
return mousePosition;
31063106
}
31073107

3108-
Vec3d StelCore::calculateParallaxDiff(double JD) {
3109-
StelCore *core = StelApp::getInstance().getCore();
3110-
Vec3d diffPos(0., 0., 0.);
3111-
3112-
static SolarSystem *ssystem=GETSTELMODULE(SolarSystem);
3113-
const PlanetP earth = ssystem->getEarth();
3114-
// diff between earth's solar system bayrcentric location at STAR_CATALOG_JDEPOCH and current solar system bayrcentric location
3115-
Vec3d earthPosCatalog = earth->getBarycentricEclipticPos(STAR_CATALOG_JDEPOCH);
3116-
Vec3d PosNow = core->getCurrentPlanet()->getBarycentricEclipticPos(JD);
3108+
Vec3d StelCore::calculateParallaxDiff(double JD) const {
3109+
// ICRS coordinates are barycentric (Gaia gives barycentric RA/DEC coordinates)
3110+
// diff between solar system bayrcentric location at STAR_CATALOG_JDEPOCH and current solar system bayrcentric location
3111+
Vec3d PosNow = getCurrentPlanet()->getBarycentricEclipticPos(JD);
31173112
// Transform from heliocentric ecliptic to equatorial coordinates
3118-
earthPosCatalog = matVsop87ToJ2000.upper3x3() * earthPosCatalog;
3119-
PosNow = matVsop87ToJ2000.upper3x3() * PosNow;
3120-
diffPos = earthPosCatalog - PosNow;
3121-
3122-
return diffPos;
3113+
PosNow = matVsop87ToJ2000.upper3x3() * -1. * PosNow; // need to times -1 because technically it is doing (0,0,0) - PosNow
3114+
return PosNow;
31233115
}
31243116

3125-
const Vec3d StelCore::getParallaxDiff(double JD) {
3126-
StelCore *core = StelApp::getInstance().getCore();
3127-
if (fuzzyEquals(JD, cachedParallaxJD, JD_SECOND) && (core->getCurrentPlanet() == cachedParallaxPlanet))
3117+
Vec3d StelCore::getParallaxDiff(double JD) const {
3118+
if (fuzzyEquals(JD, cachedParallaxJD, JD_SECOND) && (getCurrentPlanet() == cachedParallaxPlanet))
31283119
{
31293120
return cachedParallaxDiff;
31303121
}
3131-
cachedParallaxDiff = StelCore::calculateParallaxDiff(JD);
3132-
cachedParallaxJD = JD;
3133-
cachedParallaxPlanet = core->getCurrentPlanet();
3122+
cachedParallaxDiff = calculateParallaxDiff(JD); // set the cache to the new value
3123+
cachedParallaxJD = JD; // set the cache to the new value
3124+
cachedParallaxPlanet = getCurrentPlanet();
31343125
return cachedParallaxDiff;
31353126
}
31363127

3137-
Vec3d StelCore::calculateAberrationVec(double JD) {
3138-
StelCore *core = StelApp::getInstance().getCore();
3128+
Vec3d StelCore::calculateAberrationVec(double JD) const {
31393129
// Solar system barycentric velocity
3140-
Vec3d vel = core->getCurrentPlanet()->getBarycentricEclipticVelocity();
3130+
Q_UNUSED(JD);
3131+
Vec3d vel = getCurrentPlanet()->getBarycentricEclipticVelocity();
31413132
vel = StelCore::matVsop87ToJ2000 * vel * (AU/(86400.0*SPEED_OF_LIGHT));
31423133
return vel;
31433134
}
31443135

3145-
const Vec3d StelCore::getAberrationVec(double JD) {
3146-
StelCore *core = StelApp::getInstance().getCore();
3136+
Vec3d StelCore::getAberrationVec(double JD) const {
31473137
// need to recompute the aberration vector if the JD has changed or the planet has changed
3148-
if (fuzzyEquals(JD, cachedAberrationJD, JD_SECOND) && (core->getCurrentPlanet() == cachedAberrationPlanet))
3138+
if (fuzzyEquals(JD, cachedAberrationJD, JD_SECOND) && (getCurrentPlanet() == cachedAberrationPlanet))
31493139
{
3150-
return core->getAberrationFactor() * cachedAberrationVec;
3140+
return getAberrationFactor() * cachedAberrationVec;
31513141
}
3152-
cachedAberrationVec = StelCore::calculateAberrationVec(JD);
3153-
cachedAberrationJD = JD;
3154-
cachedAberrationPlanet = core->getCurrentPlanet();
3155-
return core->getAberrationFactor() * cachedAberrationVec;
3142+
cachedAberrationVec = StelCore::calculateAberrationVec(JD); // set the cache to the new value
3143+
cachedAberrationJD = JD; // set the cache to the new value
3144+
cachedAberrationPlanet = getCurrentPlanet();
3145+
return getAberrationFactor() * cachedAberrationVec;
31563146
}
31573147

31583148
QByteArray StelCore::getAberrationShader() const
31593149
{
31603150
return 1+R"(
3161-
uniform vec3 STELCORE_currentPlanetHeliocentricEclipticVelocity;
3151+
uniform vec3 STELCORE_currentPlanetBarycentricEclipticVelocity;
31623152
// objectDir points to the object as viewed from its comoving frame.
31633153
// Return value represents the apparent direction to this object from a frame
31643154
// that moves with respect to the object at slightly relativistic speeds (v<0.1c).
31653155
// Relative error in aberration angle is about 0.5v/c.
31663156
vec3 applyAberrationToObject(vec3 objectDir)
31673157
{
3168-
vec3 velocity = STELCORE_currentPlanetHeliocentricEclipticVelocity;
3158+
vec3 velocity = STELCORE_currentPlanetBarycentricEclipticVelocity;
31693159
return normalize(objectDir + velocity);
31703160
}
31713161
// viewDir is the direction where the object appears to be when viewed from a
@@ -3174,7 +3164,7 @@ vec3 applyAberrationToObject(vec3 objectDir)
31743164
// Relative error in aberration angle is about 0.5v/c.
31753165
vec3 applyAberrationToViewDir(vec3 viewDir)
31763166
{
3177-
vec3 velocity = STELCORE_currentPlanetHeliocentricEclipticVelocity;
3167+
vec3 velocity = STELCORE_currentPlanetBarycentricEclipticVelocity;
31783168
return normalize(viewDir - velocity);
31793169
}
31803170
)";
@@ -3185,14 +3175,11 @@ void StelCore::setAberrationUniforms(QOpenGLShaderProgram& program) const
31853175
Vec3d velocity;
31863176
if(getUseAberration())
31873177
{
3188-
const auto p = getCurrentPlanet();
3189-
const auto hev = p->getHeliocentricEclipticVelocity();
3190-
velocity = StelCore::matVsop87ToJ2000 * hev;
3191-
velocity *= getAberrationFactor() * (AU/(86400.0*SPEED_OF_LIGHT));
3178+
velocity = cachedAberrationVec;
31923179
}
31933180
else
31943181
{
31953182
velocity = Vec3d(0,0,0);
31963183
}
3197-
program.setUniformValue("STELCORE_currentPlanetHeliocentricEclipticVelocity", velocity.toQVector());
3184+
program.setUniformValue("STELCORE_currentPlanetBarycentricEclipticVelocity", velocity.toQVector());
31983185
}

src/core/StelCore.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ class StelCore : public QObject
378378
Vec3d getMouseJ2000Pos(void) const;
379379

380380
//! get vector used to compute parallax effect
381-
static const Vec3d getParallaxDiff(double JD);
381+
Vec3d getParallaxDiff(double JD) const;
382382
//! get vector used to compute aberration effect
383-
static const Vec3d getAberrationVec(double JD);
383+
Vec3d getAberrationVec(double JD) const;
384384

385385
public slots:
386386
//! Smoothly move the observer to the given location
@@ -1015,12 +1015,12 @@ private slots:
10151015
static Vec3d cachedParallaxDiff;
10161016
static double cachedParallaxJD; // Cached Julian Date
10171017
static PlanetP cachedParallaxPlanet;
1018-
static Vec3d calculateParallaxDiff(double JD); // Actual calculation
1018+
Vec3d calculateParallaxDiff(double JD) const; // Actual calculation
10191019

10201020
// Variables for caching the aberration effect
10211021
static Vec3d cachedAberrationVec;
10221022
static double cachedAberrationJD;
10231023
static PlanetP cachedAberrationPlanet;
1024-
static Vec3d calculateAberrationVec(double JD); // Actual calculation
1024+
Vec3d calculateAberrationVec(double JD) const; // Actual calculation
10251025
};
10261026
#endif // STELCORE_HPP

src/core/modules/Nebula.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,7 @@ Vec3d Nebula::getJ2000EquatorialPos(const StelCore* core) const
16491649
Vec3d pos=XYZ;
16501650
Q_ASSERT_X(fabs(pos.normSquared()-1.0)<0.0001, "Nebula aberration", "vertex length not unity");
16511651
//pos.normalize(); // Yay - not required!
1652-
Vec3d vel=core->getCurrentPlanet()->getHeliocentricEclipticVelocity();
1653-
vel=StelCore::matVsop87ToJ2000*vel*core->getAberrationFactor()*(AU/(86400.0*SPEED_OF_LIGHT));
1652+
Vec3d vel=core->getAberrationVec(core->getJDE());
16541653
pos+=vel;
16551654
pos.normalize();
16561655
return pos;

0 commit comments

Comments
 (0)