Skip to content

Commit

Permalink
Fix Sun label is not shown when large FOV and with JPL emphem (fix #4076
Browse files Browse the repository at this point in the history
)
  • Loading branch information
henrysky authored Jan 14, 2025
1 parent 263ee4c commit 5feab4b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/core/StelCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3129,7 +3129,7 @@ Vec3d StelCore::getParallaxDiff(double JD) const {
Vec3d StelCore::calculateAberrationVec(double JD) const {
// Solar system barycentric velocity
Q_UNUSED(JD);
Vec3d vel = getCurrentPlanet()->getBarycentricEclipticVelocity();
Vec3d vel = getCurrentPlanet()->getBarycentricEclipticVelocity(JD);
vel = StelCore::matVsop87ToJ2000 * vel * (AU/(86400.0*SPEED_OF_LIGHT));
return vel;
}
Expand Down
56 changes: 46 additions & 10 deletions src/core/modules/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,17 +1779,35 @@ void Planet::computePosition(const StelObserver *observer, const double dateJDE,
if (isTransitioning && orbitPtr)
return;


if (fabs(dateJDE-lastJDE)>deltaJDE)
{
coordFunc(dateJDE, &eclipticPos[0], &eclipticVelocity[0], orbitPtr);
// if Sun, then position is always 0,0,0 because coordFunc is computing barycentric coordinates
if (this->getParent() == nullptr)
{
eclipticPos.set(0., 0., 0.);
eclipticVelocity.set(0., 0., 0.);
}
else
{
coordFunc(dateJDE, &eclipticPos[0], &eclipticVelocity[0], orbitPtr);
}
lastJDE = dateJDE;
}
this->aberrationPush=aberrationPush;
}

void Planet::computePosition(const double dateJDE, Vec3d &eclPosition, Vec3d &eclVelocity) const
{
coordFunc(dateJDE, &eclPosition[0], &eclVelocity[0], orbitPtr);
// if Sun, then position is always 0,0,0 because coordFunc is computing barycentric coordinates
if (this->getParent() == nullptr)
{
eclPosition.set(0., 0., 0.);
eclVelocity.set(0., 0., 0.);
}
else {
coordFunc(dateJDE, &eclPosition[0], &eclVelocity[0], orbitPtr);
}
}

// Compute the transformation matrix from the local Planet coordinate system to the parent Planet coordinate system.
Expand Down Expand Up @@ -2029,6 +2047,11 @@ double Planet::getMeanSolarDay() const
// This is only needed for orbit drawing.
Vec3d Planet::getEclipticPos(double dateJDE) const
{
// for the Sun
if (parent == Q_NULLPTR) // the Sun
{
return Vec3d(0., 0., 0.);
}
// Use current position if the time match.
if (fuzzyEquals(dateJDE, lastJDE))
return eclipticPos;
Expand All @@ -2050,6 +2073,7 @@ Vec3d Planet::getHeliocentricPos(Vec3d p) const
{
if (parent == Q_NULLPTR) // the Sun
{
p.set(0., 0., 0.);
return p;
}
// Note: using shared copies is too slow here. So we use direct access instead.
Expand Down Expand Up @@ -2093,13 +2117,19 @@ Vec3d Planet::getBarycentricEclipticPos(double dateJDE) const
{
while (true)
{
pos += pp->getEclipticPos(dateJDE);
pp = pp->parent.data();
// slightly different from getHeliocentricEclipticPos to finally add Sun barycentric position
if (pp == Q_NULLPTR)
if (pp->parent.data() == Q_NULLPTR)
{
Vec3d eclipticPosSun = Vec3d(0., 0., 0.);
Vec3d eclipticVelocitySun = Vec3d(0., 0., 0.);
pp->coordFunc(dateJDE, &eclipticPosSun[0], &eclipticVelocitySun[0], orbitPtr);
pos += eclipticPosSun;
break;
}
else{
pos += pp->getEclipticPos(dateJDE);
pp = pp->parent.data();
}
}
}
return pos;
Expand Down Expand Up @@ -2141,7 +2171,7 @@ Vec3d Planet::getHeliocentricEclipticVelocity() const
}

// Return barycentric velocity of planet.
Vec3d Planet::getBarycentricEclipticVelocity() const
Vec3d Planet::getBarycentricEclipticVelocity(double dateJDE) const
{
// Note: using shared copies is too slow here. So we use direct access instead.
Vec3d vel = eclipticVelocity;
Expand All @@ -2150,13 +2180,19 @@ Vec3d Planet::getBarycentricEclipticVelocity() const
{
while (true)
{
vel += pp->eclipticVelocity;
pp = pp->parent.data();
// slightly different from getHeliocentricEclipticVelocity to finally add Sun barycentric velocity
if (pp == Q_NULLPTR)
// slightly different from getHeliocentricEclipticPos to finally add Sun barycentric position
if (pp->parent.data() == Q_NULLPTR)
{
Vec3d eclipticPosSun = Vec3d(0., 0., 0.);
Vec3d eclipticVelocitySun = Vec3d(0., 0., 0.);
pp->coordFunc(dateJDE, &eclipticPosSun[0], &eclipticVelocitySun[0], orbitPtr);
vel += eclipticVelocitySun;
break;
}
else{
vel += pp->eclipticVelocity;
pp = pp->parent.data();
}
}
}
return vel;
Expand Down
4 changes: 3 additions & 1 deletion src/core/modules/Planet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,12 @@ class Planet : public StelObject
double getRotObliquity(double JDE) const;

//! Compute the position and orbital velocity in the parent Planet coordinate system and set aberrationPush
//! In case of the Sun, it is the heliocentric position and velocity so zeros are set
//! Does not compute new position when dateJDE is less than deltaJDE away from lastJDE
//! You can add the aberrationPush value according to Edot*lightTime in Explanatory Supplement (2013) formula 7.55.
virtual void computePosition(const StelObserver *observer, const double dateJDE, const Vec3d &aberrationPush);
//! Compute the position and orbital velocity in the parent Planet coordinate system, and return them in eclPosition and eclVelocity
//! In case of the Sun, it is the heliocentric position and velocity so zeros are set
//! These may be preferred when we want to avoid setting the actual position (e.g., RTS computation)
virtual void computePosition(const double dateJDE, Vec3d &eclPosition, Vec3d &eclVelocity) const;

Expand Down Expand Up @@ -493,7 +495,7 @@ class Planet : public StelObject
Vec3d getHeliocentricEclipticVelocity() const;

//! Return the barycentric ecliptical velocity in the solar system in ecliptical coordinates in AU/d. Required for aberration!
Vec3d getBarycentricEclipticVelocity() const;
Vec3d getBarycentricEclipticVelocity(double dateJDE) const;

//! Compute and return the distance to the given position in heliocentric ecliptical (J2000) coordinates (in AU)
//! Preserves result for later retrieval by getDistance()
Expand Down

0 comments on commit 5feab4b

Please sign in to comment.