[Kstars-devel] branches/work/kdeedu_kstars_htm/kstars/kstars

James Bowlin bowlin at mindspring.com
Tue Aug 7 05:35:06 CEST 2007


SVN commit 697184 by jbowlin:

Ported Jason's atan2() changes to the htm branch.

CCMAIL: kstars-devel at kde.org


 M  +2 -2      geolocation.cpp  
 M  +3 -5      jupitermoons.cpp  
 M  +5 -10     ksasteroid.cpp  
 M  +3 -5      kscomet.cpp  
 M  +2 -3      ksplanet.cpp  
 M  +3 -3      ksplanetbase.cpp  
 M  +1 -1      skycomponents/horizoncomponent.cpp  
 M  +4 -18     skypoint.cpp  


--- branches/work/kdeedu_kstars_htm/kstars/kstars/geolocation.cpp #697183:697184
@@ -154,14 +154,14 @@
 	sqrtP2 = sqrt(PosCartX*PosCartX+PosCartY*PosCartY);
 
 	rpro = PosCartZ/sqrtP2;
-	latd = atan(rpro/(1-e2));
+	latd = atan2(rpro, (1-e2));
 	lat1 = 0.;
 
 	while ( fabs( latd-lat1 ) > RIT ) {
 		lat1 = latd;
 		s1 = sin(lat1);
 		xn = axis/(sqrt(1-e2*s1*s1));
-		latd = atan( rpro*(1+e2*xn*s1/PosCartZ) );
+		latd = atan2( rpro*(1+e2*xn*s1), PosCartZ );
 	}
 
 	sinl = sin(latd);
--- branches/work/kdeedu_kstars_htm/kstars/kstars/jupitermoons.cpp #697183:697184
@@ -94,9 +94,8 @@
 	Rj = sqrt(Xj*Xj +Yj*Yj + Zj*Zj );
 	tdelay = 0.0057755183*Rj;  //light travel delay, in days
 	
-	LAMBDA = atan(Yj/Xj);
-	if (Xj < 0) LAMBDA += dms::PI; //resolve atan ambiguity
-	ALPHA = atan( Zj/sqrt( Xj*Xj + Yj*Yj ) );
+	LAMBDA = atan2(Yj, Xj);
+	ALPHA = atan2( Zj, sqrt( Xj*Xj + Yj*Yj ) );
 	
 	//days since 10 Aug 1976 0h (minus light-travel delay)
 	t = num->julianDay() - 2443000.5 - tdelay;
@@ -479,8 +478,7 @@
 		*/
 	}
 	
-	D = atan( A6[4] / C6[4] );
-	if ( C6[4] < 0.0 ) D += dms::PI;
+	D = atan2( A6[4], C6[4] );
 	
 	//X and Y are now the rectangular coordinates of each satellite, 
 	//in units of Jupiter's Equatorial radius.
--- branches/work/kdeedu_kstars_htm/kstars/kstars/ksasteroid.cpp #697183:697184
@@ -67,7 +67,7 @@
 
 	//v is the true anomaly; r is the distance from the Sun
 
-	double v = atan( yv/xv ) / dms::DegToRad;
+	double v = atan2( yv, xv ) / dms::DegToRad;
 	//resolve atan ambiguity
 	if ( xv < 0.0 ) v += 180.0;
 
@@ -87,10 +87,8 @@
 	double zh = r * ( sinvw * sini );
 
 	//the spherical ecliptic coordinates:
-	double ELongRad = atan( yh/xh );
-	//resolve atan ambiguity
-	if ( xh < 0.0 ) ELongRad += dms::PI;
-	double ELatRad = atan( zh/r );  //(r can't possibly be negative, so no atan ambiguity)
+	double ELongRad = atan2( yh, xh );
+	double ELatRad = atan2( zh, r ); 
 
 	helEcPos.longitude.setRadians( ELongRad );
 	helEcPos.latitude.setRadians( ELatRad );
@@ -113,12 +111,9 @@
 	}
 
 	//the spherical geocentricecliptic coordinates:
-	ELongRad = atan( yh/xh );
-	//resolve atan ambiguity
-	if ( xh < 0.0 ) ELongRad += dms::PI;
-
+	ELongRad = atan2( yh, xh );
 	double rr = sqrt( xh*xh + yh*yh + zh*zh );
-	ELatRad = atan( zh/rr );  //(rr can't possibly be negative, so no atan ambiguity)
+	ELatRad = atan2( zh, rr );
 
 	ep.longitude.setRadians( ELongRad );
 	ep.latitude.setRadians( ELatRad );
--- branches/work/kdeedu_kstars_htm/kstars/kstars/kscomet.cpp #697183:697184
@@ -107,7 +107,7 @@
 
 		//v is the true anomaly; r is the distance from the Sun
 
-		v = atan( yv/xv ) / dms::DegToRad;
+		v = atan2( yv, xv ) / dms::DegToRad;
 		//resolve atan ambiguity
 		if ( xv < 0.0 ) v += 180.0;
 
@@ -142,12 +142,10 @@
 	zh -= ze;
 
 	//Finally, the spherical ecliptic coordinates:
-	double ELongRad = atan( yh/xh );
-	//resolve atan ambiguity
-	if ( xh < 0.0 ) ELongRad += dms::PI;
+	double ELongRad = atan2( yh, xh );
 
 	double rr = sqrt( xh*xh + yh*yh );
-	double ELatRad = atan( zh/rr );  //(rr can't possibly be negative, so no atan ambiguity)
+	double ELatRad = atan2( zh, rr );
 
 	ep.longitude.setRadians( ELongRad );
 	ep.latitude.setRadians( ELatRad );
--- branches/work/kdeedu_kstars_htm/kstars/kstars/ksplanet.cpp #697183:697184
@@ -236,9 +236,8 @@
 
 		}
 
-		ep.longitude.setRadians( atan( y/x ) );
-		if (x<0) ep.longitude.setD( ep.longitude.Degrees() + 180.0 ); //resolve atan ambiguity
-		ep.latitude.setRadians( atan( z/( sqrt( x*x + y*y ) ) ) );
+		ep.longitude.setRadians( atan2( y, x ) );
+		ep.latitude.setRadians( atan2( z, sqrt( x*x + y*y ) ) );
 		setRsun( trialpos.radius );
 		setRearth( dst );
 
--- branches/work/kdeedu_kstars_htm/kstars/kstars/ksplanetbase.cpp #697183:697184
@@ -112,14 +112,14 @@
 	HA.SinCos( sinHA, cosHA );
 	dec()->SinCos( sinDec, cosDec );
 
-	D = atan( ( rcosp*sinHA )/( r*cosDec/6378.14 - rcosp*cosHA ) );
+	D = atan2( rcosp*sinHA, r*cosDec/6378.14 - rcosp*cosHA );
 	dms temp;
 	temp.setRadians( ra()->radians() - D );
 	setRA( temp );
 
 	HA2.setD( LST->Degrees() - ra()->Degrees() );
 	cosHA2 = cos( HA2.radians() );
-	temp.setRadians( atan( cosHA2*( r*sinDec/6378.14 - rsinp )/( r*cosDec*cosHA/6378.14 - rcosp ) ) );
+	temp.setRadians( atan2( cosHA2*( r*sinDec/6378.14 - rsinp ), r*cosDec*cosHA/6378.14 - rcosp ) );
 	setDec( temp );
 
 	EquatorialToEcliptic( num->obliquity() );
@@ -180,7 +180,7 @@
 	double dy = dec()->Degrees() - test.dec()->Degrees();
 	double pa;
 	if ( dy ) {
-		pa = atan( dx/dy )*180.0/dms::PI;
+		pa = atan2( dx, dy )*180.0/dms::PI;
 	} else {
 		pa = 90.0;
 		if ( dx > 0 ) pa = -90.0;
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/horizoncomponent.cpp #697183:697184
@@ -351,7 +351,7 @@
 		float sy = o.y() - o2.y();
 		float angle;
 		if ( sx ) {
-			angle = atan( sy/sx )*180.0/dms::PI;
+			angle = atan2( sy, sx )*180.0/dms::PI;
 		} else {
 			angle = 90.0;
 			if ( sy < 0 ) angle = -90.0;
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skypoint.cpp #697183:697184
@@ -143,12 +143,9 @@
 	dec()->SinCos( sinDec, cosDec );
 	Obliquity->SinCos( sinOb, cosOb );
 
-	tanDec = sinDec/cosDec;
+	tanDec = sinDec/cosDec;                    // FIXME: -jbb div by zero?
 	double y = sinRA*cosOb + tanDec*sinOb;
-	double ELongRad = atan( y/cosRA );
-	//resolve atan ambiguity
-	if ( cosRA < 0 ) ELongRad += dms::PI;
-	if ( cosRA > 0 && y < 0 ) ELongRad += 2.0*dms::PI;
+	double ELongRad = atan2( y, cosRA );
 
 	EcLong.setRadians( ELongRad );
 	EcLat.setRadians( asin( sinDec*cosOb - cosDec*sinOb*sinRA ) );
@@ -163,12 +160,8 @@
 	double sinDec = sinLat*cosObliq + cosLat*sinObliq*sinLong;
 
 	double y = sinLong*cosObliq - (sinLat/cosLat)*sinObliq;
-	double RARad =  atan( y / cosLong );
+	double RARad =  atan2( y, cosLong );
 
-	//resolve ambiguity of atan:
-	if ( cosLong < 0 ) RARad += dms::PI;
-	if ( cosLong > 0 && y < 0 ) RARad += 2.0*dms::PI;
-
 	RA.setRadians( RARad );
 	Dec.setRadians( asin(sinDec) );
 }
@@ -192,15 +185,8 @@
 	}
 
 	//Extract RA, Dec from the vector:
-	RA.setRadians( atan( v[1]/v[0] ) );
+	RA.setRadians( atan2( v[1], v[0] ) );
 	Dec.setRadians( asin( v[2] ) );
-
-	//resolve ambiguity of atan()
-	if ( v[0] < 0.0 ) {
-		RA.setD( RA.Degrees() + 180.0 );
-	} else if( v[1] < 0.0 ) {
-		RA.setD( RA.Degrees() + 360.0 );
-	}
 }
 
 void SkyPoint::nutate(const KSNumbers *num) {


More information about the Kstars-devel mailing list