[Kstars-devel] KDE/kdeedu/kstars/kstars

Akarsh Simha akarshsimha at gmail.com
Tue Jul 14 23:39:52 CEST 2009


SVN commit 996779 by asimha:

Adding General Relativity corrections due to the sun's gravity.

Only the backends are implemented now. Pressing 'R' toggles the
relativistic corrections.

To see the effect, zoom in near the rim of the sun and press 'R'.

CCMAIL: kstars-devel at kde.org
FEATURE: 170583



 M  +5 -0      kstars.kcfg  
 M  +3 -0      skymap.h  
 M  +16 -0     skymapevents.cpp  
 M  +69 -6     skyobjects/skypoint.cpp  
 M  +22 -0     skyobjects/skypoint.h  


--- trunk/KDE/kdeedu/kstars/kstars/kstars.kcfg #996778:996779
@@ -625,6 +625,11 @@
 			<whatsthis>Toggle whether object positions are corrected for the effects of atmospheric refraction (only applies when horizontal coordinates are used).</whatsthis>
 			<default>true</default>
 		</entry>
+		<entry name="UseRelativistic" type="Bool">
+		        <label>Apply relativistic corrections due to the bending of light in sun's gravitational field</label>
+			<whatsthis>Toggle whether corrections due to bending of light around the sun are taken into account</whatsthis>
+			<default>true</default>
+		</entry>
 		<entry name="UseAntialias" type="Bool">
 			<label>Use antialiasing when drawing the screen?</label>
 			<whatsthis>Toggle whether the sky is rendered using antialiasing.  Lines and shapes are smoother with antialiasing, but rendering the screen will take more time.</whatsthis>
--- trunk/KDE/kdeedu/kstars/kstars/skymap.h #996778:996779
@@ -518,6 +518,9 @@
     	*/
     void drawObjectLabels( QList<SkyObject*>& labelObjects, QPainter &psky );
 
+    // The truth value of this variable suppresses / expresses some debug messages
+    static bool debugmsg;
+
 public slots:
     //DEBUG_KIO_JOB
     void slotJobResult( KJob *j );
--- trunk/KDE/kdeedu/kstars/kstars/skymapevents.cpp #996778:996779
@@ -48,6 +48,8 @@
 #include "skycomponents/skylabeler.h"
 #include "skycomponents/starcomponent.h"
 
+bool SkyMap::debugmsg = false;
+
 void SkyMap::resizeEvent( QResizeEvent * )
 {
     computeSkymap = true; // skymap must be new computed
@@ -373,6 +375,20 @@
         }
         //END_TIMING
 
+    case Qt::Key_R:
+        {
+            // Toggle relativistic corrections
+            Options::setUseRelativistic( ! Options::useRelativistic() );
+            kDebug() << "Relativistc corrections: " << Options::useRelativistic();
+            forceUpdate();
+            break;
+        }
+
+    case Qt::Key_V:
+        {
+            debugmsg = !debugmsg;
+        }
+
     case Qt::Key_A:
         Options::setUseAntialias( ! Options::useAntialias() );
         kDebug() << "Use Antialiasing: " << Options::useAntialias();
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/skypoint.cpp #996778:996779
@@ -26,6 +26,9 @@
 #include "dms.h"
 #include "ksnumbers.h"
 #include "kstarsdatetime.h" //for J2000 define
+#include "kssun.h"
+#include "kstarsdata.h"
+#include "Options.h"
 
 void SkyPoint::set( const dms& r, const dms& d ) {
     RA0.set( r );
@@ -219,6 +222,68 @@
     }
 }
 
+SkyPoint SkyPoint::moveAway( SkyPoint &from, double dist ){
+    dms lat1, dtheta;
+
+    if( dist == 0.0 ) {
+        kDebug() << "moveThrough called with zero distance!";
+        return *this;
+    }
+
+    double dst = fabs( dist * dms::DegToRad / 3600.0 ); // In radian
+    
+    // Compute the bearing angle w.r.t. the RA axis ("latitude")
+    dms dRA( ra()->Degrees() - from.ra()->Degrees() );
+    dms dDec( dec()->Degrees() - from.dec()->Degrees() );
+    double bearing = atan2( dRA.sin() / dRA.cos(), dDec.sin() ); // Do not use dRA = PI / 2!!
+    //double bearing = atan2( dDec.radians() , dRA.radians() );
+    
+    double dir0 = (dist >= 0 ) ? bearing : bearing + dms::PI; // in radian
+    dist = fabs( dist ); // in radian
+
+
+    lat1.setRadians( asin( dec()->sin() * cos( dst ) +
+                           dec()->cos() * sin( dst ) * cos( dir0 ) ) );
+    dtheta.setRadians( atan2( sin( dir0 ) * sin( dst ) * dec()->cos(),
+                              cos( dst ) - dec()->sin() * lat1.sin() ) );
+    
+    dms finalRA( ra()->Degrees() + dtheta.Degrees() );
+    return SkyPoint( finalRA, lat1 );
+}
+
+bool SkyPoint::bendlight() {
+
+    // NOTE: This should be applied before aberration
+
+    // First see if we are close enough to the sun to bother about the
+    // effect. We correct for the effect at least till b = 10 solar
+    // radii, where the effect is only about 0.06".  Assuming
+    // min. sun-earth distance is 200 solar radii.
+
+    static KSSun* sun;
+    const dms maxAngle( 1.75 * ( 30.0 / 200.0) / dms::DegToRad );
+    SkyPoint sp;
+
+    if( !sun ) // Hope we don't destroy the sun before the program ends!
+        sun = (KSSun*) KStarsData::Instance()->skyComposite()->findByName( "Sun" );
+    //    kDebug() << "bendlight says maximum correctable angle is " << maxAngle.Degrees();
+
+    // TODO: We can make this code more efficient
+    sp = SkyPoint( sun->ra0(), sun->dec0() );
+    //    kDebug() << "The unaberrated sun is " << sp.angularDistanceTo( sun ).Degrees() << "deg away";
+    if( fabs( angularDistanceTo( &sp ).radians() ) <= maxAngle.radians() ) {
+        // We correct for GR effects
+        double corr_sec = 1.75 * sun->physicalSize() / ( sun->rearth() * AU_KM * angularDistanceTo( &sp ).sin() );
+        Q_ASSERT( corr_sec > 0 );
+        
+        sp = moveAway( sp, corr_sec );
+        setRA( *sp.ra() );
+        setDec( *sp.dec() );
+        return true;
+    }
+    return false;
+}
+
 void SkyPoint::aberrate(const KSNumbers *num) {
     double cosRA, sinRA, cosDec, sinDec;
     dms dRA2, dDec2;
@@ -252,11 +317,11 @@
     dms pRA, pDec;
     //Correct the catalog coordinates for the time-dependent effects
     //of precession, nutation and aberration
-
     precess(num);
     nutate(num);
+    if(Options::useRelativistic())
+        bendlight();
     aberrate(num);
-
     if ( lat || LST )
         kWarning() << i18n( "lat and LST parameters should only be used in KSPlanetBase objects." ) ;
 }
@@ -345,14 +410,12 @@
 }
 
 void SkyPoint::apparentCoord(long double jd0, long double jdf){
-
     precessFromAnyEpoch(jd0,jdf);
-
     KSNumbers *num = new KSNumbers (jdf);
-
     nutate(num);
+    if(Options::useRelativistic())
+        bendlight();
     aberrate(num);
-
     delete num;
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/skypoint.h #996778:996779
@@ -317,6 +317,18 @@
     	*/
     void nutate(const KSNumbers *num);
 
+    /**Correct for the effect of "bending" of light around the sun for
+     * positions near the sun.
+     *
+     * General Relativity tells us that a photon with an impact
+     * parameter b is deflected through an angle 1.75" (Rs / b) where
+     * Rs is the solar radius.
+     *
+     * @return: true if the light was bent, false otherwise
+     */
+    bool bendlight();
+
+
     /**Determine the effects of aberration for this SkyPoint.
     	*@param num pointer to KSNumbers object containing current values of
     	*time-dependent variables.
@@ -477,6 +489,16 @@
      **/
     double vTopoToVGeo(double vtopo, double vsite[3]);
 
+    /** Find the SkyPoint obtained by moving distance dist
+     * (arcseconds) away from the givenSkyPoint 
+     *
+     * @param dist Distance to move through in arcseconds
+     * @param p The SkyPoint to move away from
+     * @return a SkyPoint that is at the dist away from this SkyPoint in the direction specified by bearing
+     */
+    SkyPoint moveAway( SkyPoint &from, double dist );
+
+
     ////
     //// 5. Calculating Rise/Set/Transit data.
     //// =====================================


More information about the Kstars-devel mailing list