[Kstars-devel] KDE/kdeedu/kstars/kstars/skyobjects
Alexey Khudyakov
alexey.skladnoy at gmail.com
Wed Jun 24 15:16:26 CEST 2009
SVN commit 986289 by khudyakov:
Make function KSPlanetBase::findMagnitude virtual.
It more robust and simple. Also it's more natural to keep
code which calculate object magnitude in its class.
KSPlanetBase::findMagnitude now pure virtual function
CCMAIL: kstars-devel at kde.org
M +9 -0 ksasteroid.cpp
M +2 -0 ksasteroid.h
M +5 -0 kscomet.cpp
M +2 -0 kscomet.h
M +16 -0 ksmoon.cpp
M +2 -0 ksmoon.h
M +43 -0 ksplanet.cpp
M +2 -0 ksplanet.h
M +0 -83 ksplanetbase.cpp
M +1 -1 ksplanetbase.h
M +5 -0 kspluto.cpp
M +2 -0 kspluto.h
M +3 -0 kssun.cpp
M +2 -0 kssun.h
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksasteroid.cpp #986288:986289
@@ -129,6 +129,15 @@
return true;
}
+void KSAsteroid::findMagnitude(const KSNumbers*)
+{
+ double param = 5 * log10(rsun() * rearth() );
+ double phase_rad = phase().radians();
+ double phi1 = exp( -3.33 * pow( tan( phase_rad / 2 ), 0.63 ) );
+ double phi2 = exp( -1.87 * pow( tan( phase_rad / 2 ), 1.22 ) );
+
+ setMag( H + param - 2.5 * log( (1 - G) * phi1 + G * phi2 ) );
+}
//Unused virtual function from KSPlanetBase
bool KSAsteroid::loadData() { return false; }
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksasteroid.h #986288:986289
@@ -102,6 +102,8 @@
void setJD( long double jd ) { JD = jd; }
private:
+ virtual void findMagnitude(const KSNumbers*);
+
long double JD;
double a, e, P;
dms i, w, M, N;
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/kscomet.cpp #986288:986289
@@ -180,5 +180,10 @@
return true;
}
+void KSComet::findMagnitude(const KSNumbers*)
+{
+ setMag( H + 5.0 * log10( rearth() ) + 2.5 * G * log10( rsun() ) );
+}
+
//Unused virtual function from KSPlanetBase
bool KSComet::loadData() { return false; }
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/kscomet.h #986288:986289
@@ -133,6 +133,8 @@
private:
+ virtual void findMagnitude(const KSNumbers*);
+
long double JD, JDp;
double q, e, a, P;
double TailSize, TailAngSize, ComaSize, NuclearSize; // All in kilometres
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksmoon.cpp #986288:986289
@@ -203,6 +203,22 @@
return true;
}
+void KSMoon::findMagnitude(const KSNumbers*)
+{
+ // This block of code to compute Moon magnitude (and the
+ // relevant data put into ksplanetbase.h) was taken from
+ // SkyChart v3 Beta
+ int p = floor( phase().Degrees() );
+ if( p > 180 )
+ p = p - 360;
+ int i = p / 10;
+ int k = p % 10;
+ int j = (i + 1 > 18) ? 18 : i + 1;
+ i = 18 - abs(i);
+ j = 18 - abs(j);
+ setMag( KSMoon::MagArray[ i ] + ( ( KSMoon::MagArray[ j ] - KSMoon::MagArray[ i ] ) * k / 10 ) );
+}
+
void KSMoon::findPhase() {
KSSun *Sun = (KSSun*)KStarsData::Instance()->skyComposite()->findByName( "Sun" ); // TODO: Get rid of this ugly thing by making KSSun singleton.
Phase = ecLong()->Degrees() - Sun->ecLong()->Degrees();
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksmoon.h #986288:986289
@@ -98,6 +98,8 @@
virtual bool findGeocentricPosition( const KSNumbers *num, const KSPlanetBase* );
private:
+ virtual void findMagnitude(const KSNumbers*);
+
static bool data_loaded;
static int instance_count;
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanet.cpp #986288:986289
@@ -319,3 +319,46 @@
return true;
}
+
+void KSPlanet::findMagnitude(const KSNumbers* num)
+{
+ double cosDec, sinDec;
+ dec()->SinCos(cosDec, sinDec);
+
+ /* Computation of the visual magnitude (V band) of the planet.
+ * Algorithm provided by Pere Planesas (Observatorio Astronomico Nacional)
+ * It has some simmilarity to J. Meeus algorithm in Astronomical Algorithms, Chapter 40.
+ * */
+
+ // Initialized to the faintest magnitude observable with the HST
+ float magnitude = 30;
+
+ double param = 5 * log10(rsun() * rearth() );
+ double phase_rad = phase().radians();
+ double phase = this->phase().Degrees();
+ double f1 = phase/100.;
+
+ if( name() == i18n( "Mercury" ) ) {
+ if ( phase > 150. ) f1 = 1.5;
+ magnitude = -0.36 + param + 3.8*f1 - 2.73*f1*f1 + 2*f1*f1*f1;
+ } else if( name() == i18n( "Venus" ) ) {
+ magnitude = -4.29 + param + 0.09*f1 + 2.39*f1*f1 - 0.65*f1*f1*f1;
+ } else if( name() == i18n( "Mars" ) ) {
+ magnitude = -1.52 + param + 0.016*phase;
+ } else if( name() == i18n( "Jupiter" ) ) {
+ magnitude = -9.25 + param + 0.005*phase;
+ } else if( name() == i18n( "Saturn" ) ) {
+ double T = num->julianCenturies();
+ double a0 = (40.66-4.695*T)* dms::PI / 180.;
+ double d0 = (83.52+0.403*T)* dms::PI / 180.;
+ double sinx = -cos(d0)*cosDec*cos(a0 - ra()->radians());
+ sinx = fabs(sinx-sin(d0)*sinDec);
+ double rings = -2.6*sinx + 1.25*sinx*sinx;
+ magnitude = -8.88 + param + 0.044*phase + rings;
+ } else if( name() == i18n( "Uranus" ) ) {
+ magnitude = -7.19 + param + 0.0028*phase;
+ } else if( name() == i18n( "Neptune" ) ) {
+ magnitude = -6.87 + param;
+ }
+ setMag(magnitude);
+}
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanet.h #986288:986289
@@ -177,6 +177,8 @@
static OrbitDataManager odm;
+private:
+ virtual void findMagnitude(const KSNumbers*);
};
#endif
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanetbase.cpp #986288:986289
@@ -306,86 +306,3 @@
TODO: Switch to this if and when we make KSSun a singleton */
// Phase = ecLong()->Degrees() - Sun->ecLong()->Degrees();
}
-
-
-void KSPlanetBase::findMagnitude(const KSNumbers *num) {
- double cosDec, sinDec;
- dec()->SinCos(cosDec, sinDec);
-
- /* Computation of the visual magnitude (V band) of the planet.
- * Algorithm provided by Pere Planesas (Observatorio Astronomico Nacional)
- * It has some simmilarity to J. Meeus algorithm in Astronomical Algorithms, Chapter 40.
- * */
-
- // Initialized to the faintest magnitude observable with the HST
- float magnitude = 30;
-
- double param = 5 * log10(rsun() * rearth() );
- double phase_rad = phase().radians();
- double phase = this->phase().Degrees();
- double f1 = phase/100.;
-
- if( name() == "Moon" ) {
- // This block of code to compute Moon magnitude (and the
- // relevant data put into ksplanetbase.h) was taken from
- // SkyChart v3 Beta
- int p = (int)( floor( phase ) );
- if( p > 180 )
- p = p - 360;
- int i = p / 10;
- int k = p - 10 * i;
- int j = (i + 1 > 18) ? 18 : i + 1;
- i = 18 - abs(i);
- j = 18 - abs(j);
- magnitude = KSMoon::MagArray[ i ] + ( ( KSMoon::MagArray[ j ] - KSMoon::MagArray[ i ] ) * k / 10 );
- }
-
- if ( name() == i18n( "Mercury" ) ) {
- if ( phase > 150. ) f1 = 1.5;
- magnitude = -0.36 + param + 3.8*f1 - 2.73*f1*f1 + 2*f1*f1*f1;
- }
- if ( name() == i18n( "Venus" ) )
- magnitude = -4.29 + param + 0.09*f1 + 2.39*f1*f1 - 0.65*f1*f1*f1;
- if( name() == i18n( "Mars" ) )
- magnitude = -1.52 + param + 0.016*phase;
- if( name() == i18n( "Jupiter" ) )
- magnitude = -9.25 + param + 0.005*phase;
-
- if( name() == i18n( "Saturn" ) ) {
- double T = num->julianCenturies();
- double a0 = (40.66-4.695*T)* dms::PI / 180.;
- double d0 = (83.52+0.403*T)* dms::PI / 180.;
- double sinx = -cos(d0)*cosDec*cos(a0 - ra()->radians());
- sinx = fabs(sinx-sin(d0)*sinDec);
- double rings = -2.6*sinx + 1.25*sinx*sinx;
- magnitude = -8.88 + param + 0.044*phase + rings;
- }
-
- if( name() == i18n( "Uranus" ) )
- magnitude = -7.19 + param + 0.0028*phase;
- if( name() == i18n( "Neptune" ) )
- magnitude = -6.87 + param;
- if( name() == i18n( "Pluto" ) )
- magnitude = -1.01 + param + 0.041*phase;
-
- if( type() == SkyObject::ASTEROID ) {
- // Asteroid
- double H, G;
- double phi1 = exp( -3.33 * pow( tan( phase_rad / 2 ), 0.63 ) );
- double phi2 = exp( -1.87 * pow( tan( phase_rad / 2 ), 1.22 ) );
- KSAsteroid *me = (KSAsteroid *)this;
- H = me -> getAbsoluteMagnitude();
- G = me -> getSlopeParameter();
- magnitude = H + param - 2.5 * log( (1 - G) * phi1 + G * phi2 );
- }
-
- if( type() == SkyObject::COMET ) {
- // Comet
- double H, G;
- KSComet *me = (KSComet *)this;
- H = me -> getAbsoluteMagnitude();
- G = me -> getSlopeParameter();
- magnitude = H + 5.0 * log10( rearth() ) + 2.5 * G * log10( rsun() );
- }
- setMag(magnitude);
-}
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanetbase.h #986288:986289
@@ -333,7 +333,7 @@
*@param num pointer to a ksnumbers object. Needed for the saturn rings contribution to
* saturn's magnitude.
*/
- void findMagnitude(const KSNumbers *num);
+ virtual void findMagnitude(const KSNumbers *num) = 0;
QImage Image0, Image;
double PositionAngle, ImageAngle, AngularSize, PhysicalSize;
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/kspluto.cpp #986288:986289
@@ -79,3 +79,8 @@
return KSAsteroid::findGeocentricPosition( num, Earth );
}
+
+void KSPluto::findMagnitude(const KSNumbers*)
+{
+ setMag( -1.01 + 5*log10(rsun() * rearth()) + 0.041*phase().Degrees() );
+}
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/kspluto.h #986288:986289
@@ -66,6 +66,8 @@
virtual bool findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth=NULL );
private:
+ virtual void findMagnitude(const KSNumbers*);
+
//The base orbital elements for J2000 (these don't change with time)
double a0, e0;
dms i0, w0, M0, N0;
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/kssun.cpp #986288:986289
@@ -41,6 +41,9 @@
return (odm.loadData(odc, "earth") != 0);
}
+// We don't need to do anything here
+void KSSun::findMagnitude(const KSNumbers*) {}
+
bool KSSun::findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth ) {
if (Earth) {
//
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/kssun.h #986288:986289
@@ -57,6 +57,8 @@
*@p Earth pointer to earth object
*/
virtual bool findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth=NULL );
+private:
+ virtual void findMagnitude(const KSNumbers*);
};
long double equinox(int year, int d, int m, int angle);
More information about the Kstars-devel
mailing list