gSatWrapper.cpp   gSatWrapper.cpp 
skipping to change at line 59 skipping to change at line 59
// Also, the TLE library expects no more than 130 characters length input. We // Also, the TLE library expects no more than 130 characters length input. We
// shouldn't have sane input with a TLE longer than about 80, but ju st in case // shouldn't have sane input with a TLE longer than about 80, but ju st in case
// we have a mal-formed input, we will truncate here to be safe // we have a mal-formed input, we will truncate here to be safe
t1.truncate(130); t1.truncate(130);
t2.truncate(130); t2.truncate(130);
pSatellite = new gSatTEME(designation.toLatin1().data(), pSatellite = new gSatTEME(designation.toLatin1().data(),
t1.data(), t1.data(),
t2.data()); t2.data());
updateEpoch(); setEpoch(StelApp::getInstance().getCore()->getJD());
} }
gSatWrapper::~gSatWrapper() gSatWrapper::~gSatWrapper()
{ {
if (pSatellite != NULL) if (pSatellite != Q_NULLPTR)
delete pSatellite; delete pSatellite;
} }
Vec3d gSatWrapper::getTEMEPos() Vec3d gSatWrapper::getTEMEPos() const
{ {
gVector position;
Vec3d returnedVector; Vec3d returnedVector;
if (pSatellite != NULL) if (pSatellite != Q_NULLPTR)
{ {
position = pSatellite->getPos(); gVector position = pSatellite->getPos();
returnedVector.set(position[0], position[1], position[2]); returnedVector.set(position[0], position[1], position[2]);
} }
else else
qWarning() << "gSatWrapper::getTEMEPos Method called without pSatellite initialized"; qWarning() << "gSatWrapper::getTEMEPos Method called without pSatellite initialized";
return returnedVector; return returnedVector;
} }
Vec3d gSatWrapper::getTEMEVel() Vec3d gSatWrapper::getTEMEVel() const
{ {
gVector velocity;
Vec3d returnedVector; Vec3d returnedVector;
if (pSatellite != NULL) if (pSatellite != Q_NULLPTR)
{ {
velocity = pSatellite->getVel(); gVector velocity = pSatellite->getVel();
returnedVector.set(velocity[0], velocity[1], velocity[2]); returnedVector.set(velocity[0], velocity[1], velocity[2]);
} }
else else
qWarning() << "gSatWrapper::getTEMEVel Method called without pSatellite initialized"; qWarning() << "gSatWrapper::getTEMEVel Method called without pSatellite initialized";
return returnedVector; return returnedVector;
} }
Vec3d gSatWrapper::getSubPoint() Vec3d gSatWrapper::getSubPoint() const
{ {
gVector satelliteSubPoint;
Vec3d returnedVector; Vec3d returnedVector;
if (pSatellite != NULL) if (pSatellite != Q_NULLPTR)
{ {
satelliteSubPoint = pSatellite->getSubPoint(); gVector satelliteSubPoint = pSatellite->getSubPoint();
returnedVector.set(satelliteSubPoint[0], satelliteSubPoint[ 1], satelliteSubPoint[2]); returnedVector.set(satelliteSubPoint[0], satelliteSubPoint[ 1], satelliteSubPoint[2]);
} }
else else
qWarning() << "gSatWrapper::getTEMEVel Method called without pSatellite initialized"; qWarning() << "gSatWrapper::getTEMEVel Method called without pSatellite initialized";
return returnedVector; return returnedVector;
} }
void gSatWrapper::updateEpoch()
{
double jul_utc = StelApp::getInstance().getCore()->getJD();
epoch = jul_utc;
if (pSatellite)
pSatellite->setEpoch(epoch);
}
void gSatWrapper::setEpoch(double ai_julianDaysEpoch) void gSatWrapper::setEpoch(double ai_julianDaysEpoch)
{ {
epoch = ai_julianDaysEpoch; epoch = ai_julianDaysEpoch;
if (pSatellite) if (pSatellite)
pSatellite->setEpoch(ai_julianDaysEpoch); pSatellite->setEpoch(epoch);
} }
void gSatWrapper::calcObserverECIPosition(Vec3d& ao_position, Vec3d& ao_vel ocity) void gSatWrapper::calcObserverECIPosition(Vec3d& ao_position, Vec3d& ao_vel ocity)
{ {
StelLocation loc = StelApp::getInstance().getCore()->getCurrentLoc if (epoch != lastCalcObserverECIPosition)
ation(); {
StelLocation loc = StelApp::getInstance().getCore()->getCu
rrentLocation();
double radLatitude = loc.latitude * KDEG2RAD; double radLatitude = loc.latitude * KDEG2RAD;
double theta = epoch.toThetaLMST(loc.longitude * KDEG2RAD); double theta = epoch.toThetaLMST(loc.longitude * KDEG2
double r; RAD);
double c,sq; double r;
double c,sq;
/* Reference: Explanatory supplement to the Astronomical Almanac 19
92, page 209-210. */ /* Reference: Explanatory supplement to the Astronomical Al
/* Elipsoid earth model*/ manac 1992, page 209-210. */
/* c = Nlat/a */ /* Elipsoid earth model*/
c = 1/std::sqrt(1 + __f*(__f - 2)*Sqr(sin(radLatitude))); /* c = Nlat/a */
sq = Sqr(1 - __f)*c; c = 1/std::sqrt(1 + __f*(__f - 2)*Sqr(sin(radLatitude)));
sq = Sqr(1 - __f)*c;
r = (KEARTHRADIUS*c + (loc.altitude/1000))*cos(radLatitude);
ao_position[0] = r * cos(theta);/*kilometers*/ r = (KEARTHRADIUS*c + (loc.altitude/1000))*cos(radLatitude);
ao_position[1] = r * sin(theta); ao_position[0] = r * cos(theta);/*kilometers*/
ao_position[2] = (KEARTHRADIUS*sq + (loc.altitude/1000))*sin(radLati ao_position[1] = r * sin(theta);
tude); ao_position[2] = (KEARTHRADIUS*sq + (loc.altitude/1000))*sin
ao_velocity[0] = -KMFACTOR*ao_position[1];/*kilometers/second*/ (radLatitude);
ao_velocity[1] = KMFACTOR*ao_position[0]; ao_velocity[0] = -KMFACTOR*ao_position[1];/*kilometers/secon
ao_velocity[2] = 0; d*/
ao_velocity[1] = KMFACTOR*ao_position[0];
ao_velocity[2] = 0;
lastCalcObserverECIPosition=epoch;
}
} }
Vec3d gSatWrapper::getAltAz() Vec3d gSatWrapper::getAltAz() const
{ {
StelLocation loc = StelApp::getInstance().getCore()->getCurrentLoc ation(); StelLocation loc = StelApp::getInstance().getCore()->getCurrentLoc ation();
Vec3d topoSatPos; Vec3d topoSatPos;
Vec3d observerECIPos;
Vec3d observerECIVel;
double radLatitude = loc.latitude * KDEG2RAD; const double radLatitude = loc.latitude * KDEG2RAD;
double theta = epoch.toThetaLMST(loc.longitude * KDEG2RAD const double theta = epoch.toThetaLMST(loc.longitude * KDE
); G2RAD);
const double sinRadLatitude=sin(radLatitude);
const double cosRadLatitude=cos(radLatitude);
const double sinTheta=sin(theta);
const double cosTheta=cos(theta);
// This now only updates if required.
calcObserverECIPosition(observerECIPos, observerECIVel); calcObserverECIPosition(observerECIPos, observerECIVel);
Vec3d satECIPos = getTEMEPos(); Vec3d satECIPos = getTEMEPos();
Vec3d slantRange = satECIPos - observerECIPos; Vec3d slantRange = satECIPos - observerECIPos;
//top_s //top_s
topoSatPos[0] = (sin(radLatitude) * cos(theta)*slantRange[0] topoSatPos[0] = (sinRadLatitude * cosTheta*slantRange[0]
+ sin(radLatitude)* sin(theta)*slantRange[1] + sinRadLatitude* sinTheta*slantRange[1]
- cos(radLatitude)* slantRange[2]); - cosRadLatitude* slantRange[2]);
//top_e //top_e
topoSatPos[1] = ((-1.0)* sin(theta)*slantRange[0] topoSatPos[1] = ((-1.0)* sinTheta*slantRange[0]
+ cos(theta)*slantRange[1]); + cosTheta*slantRange[1]);
//top_z //top_z
topoSatPos[2] = (cos(radLatitude) * cos(theta)*slantRange[0] topoSatPos[2] = (cosRadLatitude * cosTheta*slantRange[0]
+ cos(radLatitude) * sin(theta)*slantRange[1] + cosRadLatitude * sinTheta*slantRange[1]
+ sin(radLatitude) *slantRange[2]); + sinRadLatitude *slantRange[2]);
return topoSatPos; return topoSatPos;
} }
void gSatWrapper::getSlantRange(double &ao_slantRange, double &ao_slantRan geRate) void gSatWrapper::getSlantRange(double &ao_slantRange, double &ao_slantRan geRate) const
{ {
//Vec3d observerECIPos;
Vec3d observerECIPos; //Vec3d observerECIVel;
Vec3d observerECIVel;
calcObserverECIPosition(observerECIPos, observerECIVel); calcObserverECIPosition(observerECIPos, observerECIVel);
Vec3d satECIPos = getTEMEPos(); Vec3d satECIPos = getTEMEPos();
Vec3d satECIVel = getTEMEVel(); Vec3d satECIVel = getTEMEVel();
Vec3d slantRange = satECIPos - observerECIPos; Vec3d slantRange = satECIPos - observerECIPos;
Vec3d slantRangeVelocity = satECIVel - observerECIVel; Vec3d slantRangeVelocity = satECIVel - observerECIVel;
ao_slantRange = slantRange.length(); ao_slantRange = slantRange.length();
ao_slantRangeRate = slantRange.dot(slantRangeVelocity)/ao_slantRang e; ao_slantRangeRate = slantRange.dot(slantRangeVelocity)/ao_slantRang e;
} }
Vec3d gSatWrapper::getSunECIPos() // Does the actual computation only if necessary (0.1s apart) and caches th
e result in a static variable.
void gSatWrapper::updateSunECIPos()
{ {
// All positions in ECI system are positions referenced in a StelCor e::EquinoxEq system centered in the earth centre // All positions in ECI system are positions referenced in a StelCor e::EquinoxEq system centered in the earth centre
Vec3d observerECIPos; //Vec3d observerECIPos;
Vec3d observerECIVel; //Vec3d observerECIVel;
Vec3d sunECIPos;
Vec3d sunEquinoxEqPos;
calcObserverECIPosition(observerECIPos, observerECIVel); calcObserverECIPosition(observerECIPos, observerECIVel);
SolarSystem *solsystem = (SolarSystem*)StelApp::getInstance().getMod static const SolarSystem *solsystem = (SolarSystem*)StelApp::getInst
uleMgr().getModule("SolarSystem"); ance().getModuleMgr().getModule("SolarSystem");
sunEquinoxEqPos = solsystem->getSun()->getEquinoxEquatorialPo Vec3d sunEquinoxEqPos = solsystem->getSun()->getEquinoxEquatorialPos
s(StelApp::getInstance().getCore()); (StelApp::getInstance().getCore());
//sunEquinoxEqPos is measured in AU. we need meassure it in Km //sunEquinoxEqPos is measured in AU. we need measure it in Km
//Vec3d sunECIPos;
sunECIPos.set(sunEquinoxEqPos[0]*AU, sunEquinoxEqPos[1]*AU, sunEquin oxEqPos[2]*AU); sunECIPos.set(sunEquinoxEqPos[0]*AU, sunEquinoxEqPos[1]*AU, sunEquin oxEqPos[2]*AU);
sunECIPos = sunECIPos + observerECIPos; //Change ref system centre sunECIPos = sunECIPos + observerECIPos; //Change ref system centre
}
Vec3d gSatWrapper::getSunECIPos()
{
if (epoch != lastSunECIepoch)
{
updateSunECIPos();
lastSunECIepoch=epoch;
}
return sunECIPos; return sunECIPos;
} }
// Operation getVisibilityPredict // Operation getVisibilityPredict
// @brief This operation predicts the satellite visibility contidions. // @brief This operation predicts the satellite visibility conditions.
int gSatWrapper::getVisibilityPredict() gSatWrapper::Visibility gSatWrapper::getVisibilityPredict()
{ {
Vec3d satECIPos; Vec3d satAltAzPos = getAltAz();
Vec3d satAltAzPos;
Vec3d sunECIPos;
Vec3d sunAltAzPos;
double sunSatAngle, Dist;
int visibility;
satAltAzPos = getAltAz();
if (satAltAzPos[2] > 0) if (satAltAzPos[2] > 0)
{ {
satECIPos = getTEMEPos(); Vec3d satECIPos = getTEMEPos();
SolarSystem *solsystem = (SolarSystem*)StelApp::getInstance( static const SolarSystem *solsystem = (SolarSystem*)StelApp:
).getModuleMgr().getModule("SolarSystem"); :getInstance().getModuleMgr().getModule("SolarSystem");
sunAltAzPos = solsystem->getSun()->getAltAzPosGeometr Vec3d sunAltAzPos = solsystem->getSun()->getAltAzPosGeometri
ic(StelApp::getInstance().getCore()); c(StelApp::getInstance().getCore());
Vec3d sunECIPos = getSunECIPos();
sunECIPos = getSunECIPos();
if (sunAltAzPos[2] > 0.0) if (sunAltAzPos[2] > 0.0)
{ {
visibility = RADAR_SUN; return RADAR_SUN;
} }
else else
{ {
sunSatAngle = sunECIPos.angle(satECIPos); double sunSatAngle = sunECIPos.angle(satECIPos);
Dist = satECIPos.length()*cos(sunSatAngle - (M_PI/2) double Dist = satECIPos.length()*cos(sunSatAngle - (
); M_PI/2));
if (Dist > KEARTHRADIUS) if (Dist > KEARTHRADIUS)
{ {
visibility = VISIBLE; return VISIBLE;
} }
else else
{ {
visibility = RADAR_NIGHT; return RADAR_NIGHT;
} }
} }
} }
else else
visibility = NOT_VISIBLE; return NOT_VISIBLE;
return visibility; //TODO: put correct return
} }
double gSatWrapper::getPhaseAngle() double gSatWrapper::getPhaseAngle() const
{ {
Vec3d sunECIPos = getSunECIPos(); Vec3d sunECIPos = getSunECIPos();
return sunECIPos.angle(getTEMEPos()); return sunECIPos.angle(getTEMEPos());
} }
gTime gSatWrapper::epoch;
gTime gSatWrapper::lastSunECIepoch=0.0; // store last time of computation t
o avoid all-1 computations.
gTime gSatWrapper::lastCalcObserverECIPosition;
Vec3d gSatWrapper::sunECIPos; // enough to have this once.
Vec3d gSatWrapper::observerECIPos;
Vec3d gSatWrapper::observerECIVel;
 End of changes. 43 change blocks. 
105 lines changed or deleted 98 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/