Commit fdf1cac2 authored by Akarsh Simha's avatar Akarsh Simha
Browse files

Experiment: Make Azimuth CachingDms

parent 4fd4a006
......@@ -151,6 +151,20 @@ public:
*/
void setUsing_acos( const double & cosine );
/**
* @short Sets angle and trigonometric values
*/
inline void setTrigonometric( double angleDegrees, double sine, double cosine ) {
D = angleDegrees;
m_sin = sine;
m_cos = cosine;
#ifdef COUNT_DMS_SINCOS_CALLS
if(!m_cacheUsed)
++cachingdms_bad_uses;
m_cacheUsed = false;
#endif
}
/**
* @short Get the sine and cosine together
* @note Re-implements dms::SinCos()
......
......@@ -24,6 +24,7 @@
#include "ksutils.h"
#include "kstarsdata.h"
#include "skycomponents/skylabeler.h"
#include "auxiliary/cachingdms.h"
namespace {
void toXYZ(const SkyPoint* p, double *x, double *y, double *z) {
......@@ -448,22 +449,22 @@ SkyPoint Projector::fromScreen(const QPointF& p, dms* LST, const dms* lat) const
Vector2f Projector::toScreenVec(const SkyPoint* o, bool oRefract, bool* onVisibleHemisphere) const
{
double Y, dX;
CachingDms Y, dX;
double sindX, cosdX, sinY, cosY;
oRefract &= m_vp.useRefraction;
if ( m_vp.useAltAz ) {
if ( oRefract )
Y = SkyPoint::refract( o->alt() ).radians(); //account for atmospheric refraction
Y = SkyPoint::refract( o->alt() ); //account for atmospheric refraction
else
Y = o->alt().radians();
dX = m_vp.focus->az().radians() - o->az().radians();
Y = o->alt();
dX = m_vp.focus->az() - o->az(); // CachingDms - operator
} else {
dX = o->ra().radians() - m_vp.focus->ra().radians();
Y = o->dec().radians();
dX = o->ra() - m_vp.focus->ra(); // CachingDms - operator
Y = o->dec();
}
if( !( std::isfinite( Y ) && std::isfinite( dX ) ) ) {
if( !( std::isfinite( Y.Degrees() ) && std::isfinite( dX.Degrees() ) ) ) {
qDebug() << "Assert in Projector::toScreenVec failed!";
qDebug() << "using AltAz?" << m_vp.useAltAz << " Refract? " << oRefract;
const SkyObject *obj;
......@@ -471,22 +472,18 @@ Vector2f Projector::toScreenVec(const SkyPoint* o, bool oRefract, bool* onVisibl
if ( (obj = dynamic_cast<const SkyObject *>(o) ) ) {
qDebug() << "Point is object with name = " << obj->name() << " longname = " << obj->longname();
}
qDebug() << "dX = " << dX << " and isfinite(dX) is" << std::isfinite(dX);
qDebug() << "Y = " << Y << " and isfinite(Y) is" << std::isfinite(Y);
qDebug() << "dX = " << dX.Degrees() << " and isfinite(dX) is" << std::isfinite(dX.Degrees());
qDebug() << "Y = " << Y.Degrees() << " and isfinite(Y) is" << std::isfinite(Y.Degrees());
return Vector2f(0,0);
//Q_ASSERT( false );
}
dX = KSUtils::reduceAngle(dX, -dms::PI, dms::PI);
// dX = KSUtils::reduceAngle(dX, -dms::PI, dms::PI);
dX.reduceToRange( dms::MINUSPI_TO_PI );
//Convert dX, Y coords to screen pixel coords, using GNU extension if available
#if ( __GLIBC__ >= 2 && __GLIBC_MINOR__ >=1 )
sincos( dX, &sindX, &cosdX );
sincos( Y, &sinY, &cosY );
#else
sindX = sin(dX); cosdX = cos(dX);
sinY = sin(Y); cosY = cos(Y);
#endif
dX.SinCos( sindX, cosdX );
Y.SinCos( sinY, cosY );
//c is the cosine of the angular distance from the center
double c = m_sinY0*sinY + m_cosY0*cosY*cosdX;
......
......@@ -72,7 +72,7 @@ void SkyPoint::EquatorialToHorizontal( const CachingDms *LST, const CachingDms *
std::clock_t start = std::clock();
#endif
//Uncomment for spherical trig version
double AltRad, AzRad;
double AltRad;
double sindec, cosdec, sinlat, coslat, sinHA, cosHA;
double sinAlt, cosAlt;
......@@ -89,14 +89,14 @@ void SkyPoint::EquatorialToHorizontal( const CachingDms *LST, const CachingDms *
cosAlt = sqrt( 1 - sinAlt * sinAlt ); // Avoid trigonometric function. Return value of asin is always in [-pi/2, pi/2] and in this domain cosine is always non-negative, so we can use this.
double arg = ( sindec - sinlat*sinAlt )/( coslat*cosAlt );
if ( arg <= -1.0 ) AzRad = dms::PI;
else if ( arg >= 1.0 ) AzRad = 0.0;
else AzRad = acos( arg );
if ( arg <= -1.0 ) Az.setTrigonometric( 180., 0., -1. );
else if ( arg >= 1.0 ) Az.setTrigonometric( 0., 0., 1. );
else Az.setUsing_acos( arg );
if ( sinHA > 0.0 ) AzRad = 2.0*dms::PI - AzRad; // resolve acos() ambiguity
if ( sinHA > 0.0 ) Az.setTrigonometric( 360. - Az.Degrees(), -Az.sin(), Az.cos() ); // resolve acos() ambiguity
Alt.setRadians( AltRad );
Az.setRadians( AzRad );
#ifdef PROFILE_COORDINATE_CONVERSION
std::clock_t stop = std::clock();
cpuTime_EqToHz += double( stop - start )/double( CLOCKS_PER_SEC ); // Accumulate time in seconds
......
......@@ -171,6 +171,8 @@ public:
*/
inline void setAz( dms az ) { Az = az; }
inline void setAz( const CachingDms &az ) { Az = az; }
/** Overloaded member function, provided for convenience.
*It behaves essentially like the above function.
*@param az Azimuth, expressed as a double.
......@@ -194,7 +196,7 @@ public:
inline const CachingDms& dec() const { return Dec; }
/** @return a pointer to the current Azimuth. */
inline const dms& az() const { return Az; }
inline const CachingDms& az() const { return Az; }
/** @return a pointer to the current Altitude. */
inline const dms& alt() const { return Alt; }
......@@ -575,7 +577,7 @@ protected:
private:
CachingDms RA0, Dec0; //catalog coordinates
CachingDms RA, Dec; //current true sky coordinates
dms Alt, Az;
CachingDms Az; dms Alt; // Altitude is dms because it undergoes refraction
static KSSun *m_Sun;
protected:
double lastPrecessJD; // JD at which the last coordinate update (see updateCoords) for this SkyPoint was done
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment