[Kstars-devel] KDE/kdeedu/kstars/kstars
Jason Harris
kstars at 30doradus.org
Mon Aug 6 07:02:23 CEST 2007
SVN commit 696858 by harris:
replace atan() with atan2() wherever possible (sometimes atan() is
necessary due to a single value argument, rather than a y/x
expression), as suggested by James.
CCMAIL: kstars-devel at kde.org
M +2 -2 geolocation.cpp
M +3 -5 jupitermoons.cpp
M +5 -14 ksasteroid.cpp
M +3 -10 kscomet.cpp
M +2 -3 ksplanet.cpp
M +3 -3 ksplanetbase.cpp
M +1 -1 skycomponents/horizoncomponent.cpp
M +3 -17 skypoint.cpp
--- trunk/KDE/kdeedu/kstars/kstars/geolocation.cpp #696857:696858
@@ -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);
--- trunk/KDE/kdeedu/kstars/kstars/jupitermoons.cpp #696857:696858
@@ -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.
--- trunk/KDE/kdeedu/kstars/kstars/ksasteroid.cpp #696857:696858
@@ -66,11 +66,7 @@
double yv = a * sqrt( 1.0 - e*e ) * sinE;
//v is the true anomaly; r is the distance from the Sun
-
- double v = atan( yv/xv ) / dms::DegToRad;
- //resolve atan ambiguity
- if ( xv < 0.0 ) v += 180.0;
-
+ double v = atan2( yv, xv ) / dms::DegToRad;
double r = sqrt( xv*xv + yv*yv );
//vw is the sum of the true anomaly and the argument of perihelion
@@ -87,10 +83,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 +107,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 );
--- trunk/KDE/kdeedu/kstars/kstars/kscomet.cpp #696857:696858
@@ -106,11 +106,7 @@
double yv = a * sqrt( 1.0 - e*e ) * sinE;
//v is the true anomaly; r is the distance from the Sun
-
- v = atan( yv/xv ) / dms::DegToRad;
- //resolve atan ambiguity
- if ( xv < 0.0 ) v += 180.0;
-
+ v = atan2( yv, xv ) / dms::DegToRad;
r = sqrt( xv*xv + yv*yv );
}
@@ -142,12 +138,9 @@
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 );
--- trunk/KDE/kdeedu/kstars/kstars/ksplanet.cpp #696857:696858
@@ -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 );
--- trunk/KDE/kdeedu/kstars/kstars/ksplanetbase.cpp #696857:696858
@@ -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;
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/horizoncomponent.cpp #696857:696858
@@ -346,7 +346,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;
--- trunk/KDE/kdeedu/kstars/kstars/skypoint.cpp #696857:696858
@@ -145,10 +145,7 @@
tanDec = sinDec/cosDec;
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