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

Jason Harris kstars at 30doradus.org
Sun Aug 12 18:37:27 CEST 2007


SVN commit 699295 by harris:

Fixing a weird bug triggered by recent atan()-->atan2() migration.
First of all, atan2() returns angles in te range -180 to 180, whereas
we usually need 0 to 360.  Solved this by sprinkling dms::reduce()
where needed.

A more bizarre bug cropped up in the positions of some planets.  They
were given declination values >90, and requesting to center on these
objects caused KStars to slew *past* the north pole, into a strange
realm of the sky occupied only by constellation lines and these few
confused planets.

I tracked the problem down to KSPlanetBase::localizeCoords().
Basically, I need to re-express the coordinates when atan2() assigns a
Dec greater than 90 (or less than -90).  The weird part is, this
problem doesn't manifest itself when I use atan() instead of atan2().
However, instead of reverting to atan(), I just added a couple lines
of code to check for out-of-bounds dec values and deal with it.

I also removed EclipticToEquatorial() and its complement from
skypoint.h because these functions no longer exist in SkyPoint.

CCMAIL: kstars-devel at kde.org



 M  +1 -0      ksplanet.cpp  
 M  +12 -0     ksplanetbase.cpp  
 M  +3 -2      skypoint.cpp  
 M  +0 -9      skypoint.h  


--- trunk/KDE/kdeedu/kstars/kstars/ksplanet.cpp #699294:699295
@@ -237,6 +237,7 @@
 		}
 
 		ep.longitude.setRadians( atan2( y, x ) );
+		ep.longitude.reduce();
 		ep.latitude.setRadians( atan2( z, sqrt( x*x + y*y ) ) );
 		setRsun( trialpos.radius );
 		setRearth( dst );
--- trunk/KDE/kdeedu/kstars/kstars/ksplanetbase.cpp #699294:699295
@@ -122,6 +122,18 @@
 	temp.setRadians( atan2( cosHA2*( r*sinDec/6378.14 - rsinp ), r*cosDec*cosHA/6378.14 - rcosp ) );
 	setDec( temp );
 
+	//Make sure Dec is between -90 and +90
+	if ( dec()->Degrees() > 90.0 ) {
+		setDec( 180.0 - dec()->Degrees() );
+		setRA( ra()->Hours() + 12.0 );
+		ra()->reduce();
+	}
+	if ( dec()->Degrees() < -90.0 ) {
+		setDec( 180.0 + dec()->Degrees() );
+		setRA( ra()->Hours() + 12.0 );
+		ra()->reduce();
+	}
+
 	EquatorialToEcliptic( num->obliquity() );
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/skypoint.cpp #699294:699295
@@ -146,8 +146,8 @@
 	tanDec = sinDec/cosDec;
 	double y = sinRA*cosOb + tanDec*sinOb;
 	double ELongRad = atan2( y, cosRA );
-
 	EcLong.setRadians( ELongRad );
+	EcLong.reduce();
 	EcLat.setRadians( asin( sinDec*cosOb - cosDec*sinOb*sinRA ) );
 }
 
@@ -161,8 +161,8 @@
 
 	double y = sinLong*cosObliq - (sinLat/cosLat)*sinObliq;
 	double RARad =  atan2( y, cosLong );
-
 	RA.setRadians( RARad );
+	RA.reduce();
 	Dec.setRadians( asin(sinDec) );
 }
 
@@ -186,6 +186,7 @@
 
 	//Extract RA, Dec from the vector:
 	RA.setRadians( atan2( v[1], v[0] ) );
+	RA.reduce();
 	Dec.setRadians( asin( v[2] ) );
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/skypoint.h #699294:699295
@@ -248,15 +248,6 @@
 	*/
 	void HorizontalToEquatorial( const dms* LST, const dms* lat );
 
-	/**@short Convert Right Ascension/Declination to Ecliptic logitude/latitude.
-	*/
-	void EquatorialToEcliptic( const KSNumbers *num );
-
-	/**@short Convert Ecliptic logitude/latitude to Right Ascension/Declination.
-	*/
-
-	void EclipticToEquatorial( const KSNumbers *num );
-
 /**Determine the Ecliptic coordinates of the SkyPoint, given the Julian Date.
 	*The ecliptic coordinates are returned as reference arguments (since
 	*they are not stored internally)


More information about the Kstars-devel mailing list