From kstars-devel Mon Jun 28 17:17:57 2010 From: Alexey Khudyakov Date: Mon, 28 Jun 2010 17:17:57 +0000 To: kstars-devel Subject: [Kstars-devel] KDE/kdeedu/kstars/kstars/skyobjects Message-Id: <20100628171757.CD962AC8E2 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kstars-devel&m=127774495123008 SVN commit 1143779 by khudyakov: Add functions to calculate refraction corrections to SkyPoint. Old code used lookup tables and linear interpolation to calculate corrections. Now code just calculate correctionusing formula. Optimizations could be added if needed. Correctted altitude is continous which means that gap will not appear. Reverce corrections are calculated by solving equation > h' = h + deltaH(h) iteratively This is acceptable from performance PoV. unrefract isn't called in loops. It's robust since it doesn't depend on details of refract implementation Also function which returns refracted altitude is added to SkyPoint CCMAIL: kstars-devel@kde.org M +37 -0 skypoint.cpp M +10 -1 skypoint.h --- trunk/KDE/kdeedu/kstars/kstars/skyobjects/skypoint.cpp #1143778:1143779 @@ -720,5 +720,42 @@ return fabs(dec().Degrees()) > (90 - fabs(gLat->Degrees())); } +dms SkyPoint::altRefracted() const { + if( Options::useRefraction() ) + return refract(Alt); + else + return Alt; +} +// Calculate refraction correction. Parameter and return value are in degrees +static double refractionCorr(double alt) { + return 1.02 / tan(dms::DegToRad * ( alt + 10.3/(alt + 5.11) )) / 60; +} +// Critical height. Below this height formula produce meaningless +// results and correction value is just interpolated +static const double altCrit = -1; +static const double corrCrit = refractionCorr( altCrit ); +dms SkyPoint::refract(dms h) { + const double alt = h.Degrees(); + if( alt > altCrit ) + return dms( alt + refractionCorr(alt) ); + else + return dms( alt + corrCrit * (alt + 90) / (altCrit + 90) ); +} + +// Found uncorrected value by solving equation. This is OK since +// unrefract is never called in loops. +// +// Convergence is quite fast just a few iterations. +dms SkyPoint::unrefract(dms h) { + const double alt = h.Degrees(); + + double h0 = alt; + double h1 = h0 - refractionCorr(h0); + while( fabs(h1 - h0) > 1e-4 ) { + h0 = h1; + h1 = h0 - refractionCorr(h0); + } + return dms(h1); +} --- trunk/KDE/kdeedu/kstars/kstars/skyobjects/skypoint.h #1143778:1143779 @@ -205,6 +205,11 @@ /**@return a pointer to the current Altitude. */ inline const dms& alt() const { return Alt; } + /**@return refracted altitude. This function uses + * Option::useRefraction to determine whether refraction + * correction should be aplied */ + dms altRefracted() const; + //XYZ inline const Quaternion& quat() const { return m_q; } void syncQuaternion(); @@ -463,12 +468,16 @@ */ SkyPoint moveAway( SkyPoint &from, double dist ); - /** * @short Check if this point is circumpolar at the given geographic latitude */ bool checkCircumpolar( const dms *gLat ); + /** Apply refraction correction to altitude. */ + static dms refract(dms h); + + /** Remove refraction correction. */ + static dms unrefract(dms h); protected: /**Precess this SkyPoint's catalog coordinates to the epoch described by the *given KSNumbers object. _______________________________________________ Kstars-devel mailing list Kstars-devel@kde.org https://mail.kde.org/mailman/listinfo/kstars-devel