StelUtils.cpp   StelUtils.cpp 
skipping to change at line 242 skipping to change at line 242
rad = std::fmod(rad,2.0*M_PI); rad = std::fmod(rad,2.0*M_PI);
sign=true; sign=true;
if (rad<0) if (rad<0)
{ {
rad *= -1; rad *= -1;
sign = false; sign = false;
} }
deg = rad*180./M_PI; deg = rad*180./M_PI;
} }
QString radToDecDegStr(const double angle, const bool useD, const bool useC ) QString radToDecDegStr(const double angle, const int precision, const bool useD, const bool useC)
{ {
QChar degsign('d'); QChar degsign('d');
QString str; QString str;
if (!useD) if (!useD)
{ {
degsign = 0x00B0; degsign = 0x00B0;
} }
bool sign; bool sign;
double deg; double deg;
StelUtils::radToDecDeg(angle, sign, deg); StelUtils::radToDecDeg(angle, sign, deg);
str = QString("%1%2%3").arg((sign?"+":"-"), QString::number(deg, 'f' , 4), degsign); str = QString("%1%2%3").arg((sign?"+":"-"), QString::number(deg, 'f' , precision), degsign);
if (useC) if (useC)
{ {
if (!sign) if (!sign)
deg = 360. - deg; deg = 360. - deg;
str = QString("+%1%2").arg(QString::number(deg, 'f', 4), deg sign); str = QString("+%1%2").arg(QString::number(deg, 'f', precisi on), degsign);
} }
return str; return str;
} }
/************************************************************************* /*************************************************************************
Convert an angle in radian to a hms formatted string Convert an angle in radian to a hms formatted string
If the minute and second part are null are too small, don't print them If the minute and second part are null are too small, don't print them
*************************************************************************/ *************************************************************************/
QString radToHmsStrAdapt(const double angle) QString radToHmsStrAdapt(const double angle)
skipping to change at line 314 skipping to change at line 314
*************************************************************************/ *************************************************************************/
QString radToHmsStr(const double angle, const bool decimal) QString radToHmsStr(const double angle, const bool decimal)
{ {
unsigned int h,m; unsigned int h,m;
double s; double s;
StelUtils::radToHms(angle+0.005*M_PI/12/(60*60), h, m, s); StelUtils::radToHms(angle+0.005*M_PI/12/(60*60), h, m, s);
int width, precision; int width, precision;
QString carry; QString carry;
if (decimal) if (decimal)
{ {
width=4; width=5;
precision=1; precision=2;
carry="60.0"; carry="60.00";
} }
else else
{ {
width=2; width=4;
precision=0; precision=1;
carry="60"; carry="60.0";
} }
// handle carry case (when seconds are rounded up) // handle carry case (when seconds are rounded up)
if (QString("%1").arg(s, 0, 'f', precision) == carry) if (QString("%1").arg(s, 0, 'f', precision) == carry)
{ {
s=0; s=0;
m+=1; m+=1;
} }
if (m==60) if (m==60)
{ {
skipping to change at line 548 skipping to change at line 548
*lng = atan2(v[1],v[0]); *lng = atan2(v[1],v[0]);
} }
void rectToSphe(double *lng, double *lat, const Vec3f& v) void rectToSphe(double *lng, double *lat, const Vec3f& v)
{ {
double r = v.length(); double r = v.length();
*lat = asin(v[2]/r); *lat = asin(v[2]/r);
*lng = atan2(v[1],v[0]); *lng = atan2(v[1],v[0]);
} }
// GZ: some additions. I need those just for quick conversions for text dis play.
void ctRadec2Ecl(const double raRad, const double decRad, const double eclR ad, double *lambdaRad, double *betaRad) void ctRadec2Ecl(const double raRad, const double decRad, const double eclR ad, double *lambdaRad, double *betaRad)
{ {
*lambdaRad=std::atan2(std::sin(raRad)*std::cos(eclRad)+std::tan(decR ad)*std::sin(eclRad), std::cos(raRad)); *lambdaRad=std::atan2(std::sin(raRad)*std::cos(eclRad)+std::tan(decR ad)*std::sin(eclRad), std::cos(raRad));
*betaRad=std::asin(std::sin(decRad)*std::cos(eclRad)-std::cos(decRad )*std::sin(eclRad)*std::sin(raRad)); *betaRad=std::asin(std::sin(decRad)*std::cos(eclRad)-std::cos(decRad )*std::sin(eclRad)*std::sin(raRad));
} }
// GZ: done
double getDecAngle(const QString& str) double getDecAngle(const QString& str)
{ {
QRegExp re1("^\\s*([\\+\\-])?\\s*(\\d+)\\s*([hHDd\xBA])\\s*(\\d+)\\s *['Mm]\\s*(\\d+(\\.\\d+)?)\\s*[\"Ss]\\s*([NSEWnsew])?\\s*$"); // DMS/HMS QRegExp re1("^\\s*([\\+\\-])?\\s*(\\d+)\\s*([hHDd\xBA])\\s*(\\d+)\\s *['Mm]\\s*(\\d+(\\.\\d+)?)\\s*[\"Ss]\\s*([NSEWnsew])?\\s*$"); // DMS/HMS
QRegExp re2("^\\s*([\\+\\-])?\\s*(\\d+(\\.\\d+)?).?([NSEWnsew])?\\s* $"); // Decimal QRegExp re2("^\\s*([\\+\\-])?\\s*(\\d+(\\.\\d+)?).?([NSEWnsew])?\\s* $"); // Decimal
QRegExp re3("([+-]?[\\d.]+)°(?:([\\d.]+)')?(?:([\\d.]+)\")?"); // DM S like +121°33'38.28"
if (re1.exactMatch(str)) if (re1.exactMatch(str))
{ {
bool neg = (re1.capturedTexts().at(1) == "-"); bool neg = (re1.capturedTexts().at(1) == "-");
float d = re1.capturedTexts().at(2).toFloat(); float d = re1.capturedTexts().at(2).toFloat();
float m = re1.capturedTexts().at(4).toFloat(); float m = re1.capturedTexts().at(4).toFloat();
double s = re1.capturedTexts().at(5).toDouble(); double s = re1.capturedTexts().at(5).toDouble();
if (re1.capturedTexts().at(3).toUpper() == "H") if (re1.capturedTexts().at(3).toUpper() == "H")
{ {
d *= 15; d *= 15;
skipping to change at line 588 skipping to change at line 587
} }
else if (re2.exactMatch(str)) else if (re2.exactMatch(str))
{ {
bool neg = (re2.capturedTexts().at(1) == "-"); bool neg = (re2.capturedTexts().at(1) == "-");
double deg = re2.capturedTexts().at(2).toDouble(); double deg = re2.capturedTexts().at(2).toDouble();
QString cardinal = re2.capturedTexts().at(4); QString cardinal = re2.capturedTexts().at(4);
if (cardinal.toLower() == "s" || cardinal.toLower() == "w" | | neg) if (cardinal.toLower() == "s" || cardinal.toLower() == "w" | | neg)
deg *= -1.; deg *= -1.;
return (deg * 2 * M_PI / 360.); return (deg * 2 * M_PI / 360.);
} }
else if (re3.exactMatch(str))
{
float deg = re3.capturedTexts()[1].toFloat();
float min = re3.capturedTexts()[2].isEmpty()? 0 : re3.captur
edTexts()[2].toFloat();
float sec = re3.capturedTexts()[3].isEmpty()? 0 : re3.captur
edTexts()[3].toFloat();
float r = qAbs(deg) + min / 60 + sec / 3600;
if (deg<0)
r *= -1.;
return (r * 2 * M_PI / 360.);
}
qDebug() << "getDecAngle failed to parse angle string:" << str; qDebug() << "getDecAngle failed to parse angle string:" << str;
return -0.0; return -0.0;
} }
// Check if a number is a power of 2 // Check if a number is a power of 2
bool isPowerOfTwo(const int value) bool isPowerOfTwo(const int value)
{ {
return (value & -value) == value; return (value & -value) == value;
} }
skipping to change at line 1236 skipping to change at line 1245
double a = AU*1000*SemiMajorAxis; double a = AU*1000*SemiMajorAxis;
// Calculate orbital period in seconds // Calculate orbital period in seconds
// Here 1.32712440018e20 is heliocentric gravitational constant // Here 1.32712440018e20 is heliocentric gravitational constant
double period = 2*M_PI*std::sqrt(a*a*a/1.32712440018e20); double period = 2*M_PI*std::sqrt(a*a*a/1.32712440018e20);
return period/86400; // return period in days return period/86400; // return period in days
} }
QString hoursToHmsStr(const double hours) QString hoursToHmsStr(const double hours)
{ {
int h = (int)hours; int h = (int)hours;
int m = (int)((std::abs(hours)-std::abs(double(h)))*60); int m = (int)((qAbs(hours)-qAbs(double(h)))*60);
float s = (((std::abs(hours)-std::abs(double(h)))*60)-m)*60; float s = (((qAbs(hours)-qAbs(double(h)))*60)-m)*60;
return QString("%1h%2m%3s").arg(h).arg(m).arg(QString::number(s, 'f' , 1)); return QString("%1h%2m%3s").arg(h).arg(m).arg(QString::number(s, 'f' , 1));
} }
/* /////////////////// DELTA T VARIANTS /* /////////////////// DELTA T VARIANTS
// For the standard epochs for many formulae, we use // For the standard epochs for many formulae, we use
// J2000.0=2000-jan-1.5=2451545.0, // J2000.0=2000-jan-1.5=2451545.0,
// 1900.0=1900-jan-0.5=2415020.0 // 1900.0=1900-jan-0.5=2415020.0
// 1820.0=1820-jan-0.5=2385800.0 // 1820.0=1820-jan-0.5=2385800.0
// 1810.0=1810-jan-0.5=2382148.0 // 1810.0=1810-jan-0.5=2382148.0
skipping to change at line 1263 skipping to change at line 1272
// Implementation of algorithm by Espenak & Meeus (2006) for DeltaT computa tion // Implementation of algorithm by Espenak & Meeus (2006) for DeltaT computa tion
double getDeltaTByEspenakMeeus(const double jDay) double getDeltaTByEspenakMeeus(const double jDay)
{ {
int year, month, day; int year, month, day;
getDateFromJulianDay(jDay, &year, &month, &day); getDateFromJulianDay(jDay, &year, &month, &day);
// Note: the method here is adapted from // Note: the method here is adapted from
// "Five Millennium Canon of Solar Eclipses" [Espenak and Meeus, 200 6] // "Five Millennium Canon of Solar Eclipses" [Espenak and Meeus, 200 6]
// A summary is described here: // A summary is described here:
// http://eclipse.gsfc.nasa.gov/SEhelp/deltatpoly2004.html // http://eclipse.gsfc.nasa.gov/SEhelp/deltatpoly2004.html
// GZ: I replaced the std::pow() calls by Horner's scheme with rever
sed factors, it's more accurate and efficient.
// Old code left for readability, but can also be deleted.
double y = year+((month-1)*30.5+day/31*30.5)/366; double y = year+((month-1)*30.5+day/31*30.5)/366;
// set the default value for Delta T // set the default value for Delta T
double u = (y-1820)/100.; double u = (y-1820)/100.;
double r = (-20 + 32 * u * u); double r = (-20 + 32 * u * u);
if (y < -500) if (y < -500)
{ {
// values are equal to defaults! // values are equal to defaults!
skipping to change at line 1530 skipping to change at line 1537
if (-391 < year && year <= 948) if (-391 < year && year <= 948)
deltaT = (42.4*u +495.0)*u + 2177.0; deltaT = (42.4*u +495.0)*u + 2177.0;
if (948 < year && year <= 1600) if (948 < year && year <= 1600)
deltaT = (23.6*u +100.0)*u + 102.0; deltaT = (23.6*u +100.0)*u + 102.0;
return deltaT; return deltaT;
} }
// Implementation of algorithm by JPL Horizons for DeltaT computation // Implementation of algorithm by JPL Horizons for DeltaT computation
double getDeltaTByJPLHorizons(const double jDay) double getDeltaTByJPLHorizons(const double jDay)
{ // GZ: TODO: FIXME! It does not make sense to have zeros after 1620 in a JPL Horizons compatible implementation! { // FIXME: It does not make sense to have zeros after 1620 in a JPL Horizo ns compatible implementation!
int year, month, day; int year, month, day;
double u; double u;
double deltaT = 0.; double deltaT = 0.;
getDateFromJulianDay(jDay, &year, &month, &day); getDateFromJulianDay(jDay, &year, &month, &day);
if (-2999 < year && year < 948) if (-2999 < year && year < 948)
{ {
u=(jDay-2385800.0)/36525.0; // (1820-jan-1.5) u=(jDay-2385800.0)/36525.0; // (1820-jan-1.5)
deltaT = 31.0*u*u; deltaT = 31.0*u*u;
} }
skipping to change at line 1714 skipping to change at line 1721
{ {
u = 0.05 + ub; u = 0.05 + ub;
//deltaT = +60.8 + 82.0*u - 188.0*std::pow(u,2) - 5034.0*std ::pow(u,3); //deltaT = +60.8 + 82.0*u - 188.0*std::pow(u,2) - 5034.0*std ::pow(u,3);
deltaT = ((-5034.0*u -188.0)*u +82.0)*u +60.8; deltaT = ((-5034.0*u -188.0)*u +82.0)*u +60.8;
} }
return deltaT; return deltaT;
} }
// Implementation of algorithm by Reingold & Dershowitz (Cal. Calc. 1997, 2 001, 2007, Cal. Tab. 2002) for DeltaT computation. // Implementation of algorithm by Reingold & Dershowitz (Cal. Calc. 1997, 2 001, 2007, Cal. Tab. 2002) for DeltaT computation.
// GZ: Created as yet another multi-segment polynomial fit through the tabl // Created as yet another multi-segment polynomial fit through the table in
e in Meeus: Astronomical Algorithms (1991). Meeus: Astronomical Algorithms (1991).
// GZ: Note that only the Third edition (2007) adds the 1700-1799 term. // Note that only the Third edition (2007) adds the 1700-1799 term.
// GZ: More efficient reimplementation with stricter adherence to the sourc // More efficient reimplementation with stricter adherence to the source.
e.
double getDeltaTByReingoldDershowitz(const double jDay) double getDeltaTByReingoldDershowitz(const double jDay)
{ {
int year, month, day; int year, month, day;
getDateFromJulianDay(jDay, &year, &month, &day); getDateFromJulianDay(jDay, &year, &month, &day);
// GZ: R&D don't use a float-fraction year, but explicitly only the // R&D don't use a float-fraction year, but explicitly only the inte
integer year! And R&D use a proleptic Gregorian year before 1582. ger year! And R&D use a proleptic Gregorian year before 1582.
// GZ: We cannot do that, but the difference is negligible. // We cannot do that, but the difference is negligible.
// GZ: FIXME: why are displayed values so far off the computed value // FIXME: why are displayed values so far off the computed values? I
s? It seems currently broken! t seems currently broken!
double deltaT=0.0; // If it returns 0, there is a bug! double deltaT=0.0; // If it returns 0, there is a bug!
if ((year >= 2019) || (year < 1620)) if ((year >= 2019) || (year < 1620))
{ {
double jdYear_0; getJDFromDate(&jdYear_0, year, 1, 1, 0, 0, 0); double jdYear_0; getJDFromDate(&jdYear_0, year, 1, 1, 0, 0, 0);
double jd1810_0; getJDFromDate(&jd1810_0, 1810, 1, 1, 0, 0, 0); double jd1810_0; getJDFromDate(&jd1810_0, 1810, 1, 1, 0, 0, 0);
double x = (jdYear_0-jd1810_0+0.5); double x = (jdYear_0-jd1810_0+0.5);
deltaT = x*x/41048480.0 - 15.0; deltaT = x*x/41048480.0 - 15.0;
} }
else if (year >= 1988) else if (year >= 1988)
skipping to change at line 1844 skipping to change at line 1851
double getMoonSecularAcceleration(const double jDay, const double nd) double getMoonSecularAcceleration(const double jDay, const double nd)
{ {
int year, month, day; int year, month, day;
getDateFromJulianDay(jDay, &year, &month, &day); getDateFromJulianDay(jDay, &year, &month, &day);
double yeardec=year+((month-1)*30.5+day/31*30.5)/366.0; double yeardec=year+((month-1)*30.5+day/31*30.5)/366.0;
double t = (yeardec-1955.5)/100.0; double t = (yeardec-1955.5)/100.0;
// n.dot for secular acceleration of the Moon in ELP2000-82B // n.dot for secular acceleration of the Moon in ELP2000-82B
// have value -23.8946 "/cy/cy // have value -23.8946 "/cy/cy
return -0.91072 * (-23.8946 + std::abs(nd))*t*t; return -0.91072 * (-23.8946 + qAbs(nd))*t*t;
} }
double getDeltaTStandardError(const double jDay) double getDeltaTStandardError(const double jDay)
{ {
int year, month, day; int year, month, day;
getDateFromJulianDay(jDay, &year, &month, &day); getDateFromJulianDay(jDay, &year, &month, &day);
//double yeardec=year+((month-1)*30.5+day/31*30.5)/366; //double yeardec=year+((month-1)*30.5+day/31*30.5)/366;
double sigma = -1.; double sigma = -1.;
skipping to change at line 1942 skipping to change at line 1949
*--cos_sin_rev = cos_sin[-1]; *--cos_sin_rev = cos_sin[-1];
*--cos_sin_rev = -cos_sin[-2]; *--cos_sin_rev = -cos_sin[-2];
} }
return cos_sin_rho; return cos_sin_rho;
} }
//! Compute cosines and sines around part of a circle (from top to bottom) which is split in "segments" parts. //! Compute cosines and sines around part of a circle (from top to bottom) which is split in "segments" parts.
//! Values are stored in the global static array cos_sin_rho. //! Values are stored in the global static array cos_sin_rho.
//! Used for the sin/cos values along a meridian. //! Used for the sin/cos values along a meridian.
//! GZ: allow leaving away pole caps. The array now contains values for the region minAngle+segments*phi //! This allows leaving away pole caps. The array now contains values for t he region minAngle+segments*phi
//! @param dRho a difference angle between the stops //! @param dRho a difference angle between the stops
//! @param segments number of segments //! @param segments number of segments
//! @param minAngle start angle inside the half-circle. maxAngle=minAngle+s egments*phi //! @param minAngle start angle inside the half-circle. maxAngle=minAngle+s egments*phi
float *ComputeCosSinRhoZone(const float dRho, const int segments, const flo at minAngle) float *ComputeCosSinRhoZone(const float dRho, const int segments, const flo at minAngle)
{ {
float *cos_sin = cos_sin_rho; float *cos_sin = cos_sin_rho;
const float c = cos(dRho); const float c = cos(dRho);
const float s = sin(dRho); const float s = sin(dRho);
*cos_sin++ = cos(minAngle); *cos_sin++ = cos(minAngle);
*cos_sin++ = sin(minAngle); *cos_sin++ = sin(minAngle);
 End of changes. 16 change blocks. 
29 lines changed or deleted 36 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/