SkyPoint EquirectangularProjector::fromScreen(const QPointF& p, dms* LST, const dms* lat) const { SkyPoint result; //Convert pixel position to x and y offsets in radians double dx = (0.5*m_vp.width - p.x())/m_vp.zoomFactor; double dy = (0.5*m_vp.height - p.y())/m_vp.zoomFactor; if ( m_vp.useAltAz ) { dms az, alt; dx = -1.0*dx; //Azimuth goes in opposite direction compared to RA az.setRadians( dx + m_vp.focus->az().radians() ); alt.setRadians( dy + m_vp.focus->alt().radians() ); result.setAz( az.reduce() ); if ( m_vp.useRefraction ) alt = SkyPoint::unrefract( alt ); result.setAlt( alt ); result.HorizontalToEquatorial( LST, lat ); return result; } else { dms ra, dec; ra.setRadians( dx + m_vp.focus->ra().radians() ); dec.setRadians( dy + m_vp.focus->dec().radians() ); result.set( ra.reduce(), dec ); result.EquatorialToHorizontal( LST, lat ); return result; } }
void modCalcAltAz::slotCompute() { //Determine whether we are calculating Alt/Az coordinates from RA/Dec, //or vice versa. We calculate Alt/Az by default, unless the signal //was sent by changing the Az or Alt value. if ( sender()->objectName() == "Az" || sender()->objectName() == "Alt" ) { //Validate Az and Alt coordinates bool ok( false ); dms alt; dms az = Az->createDms( true, &ok ); if ( ok ) alt = Alt->createDms( true, &ok ); if ( ok ) { SkyPoint sp; sp.setAz( az ); sp.setAlt( alt ); sp.HorizontalToEquatorial( &LST, geoPlace->lat() ); RA->showInHours( sp.ra() ); Dec->showInDegrees( sp.dec() ); } } else { //Validate RA and Dec coordinates bool ok( false ); dms ra; dms dec = Dec->createDms( true, &ok ); if ( ok ) ra = RA->createDms( false, &ok ); if ( ok ) { SkyPoint sp( ra, dec ); sp.EquatorialToHorizontal( &LST, geoPlace->lat() ); Az->showInDegrees( sp.az() ); Alt->showInDegrees( sp.alt() ); } } }
SkyPoint Projector::pointAt(double az, KStarsData* data) { SkyPoint p; p.setAz( az ); p.setAlt( 0.0 ); p.HorizontalToEquatorial( data->lst(), data->geo()->lat() ); return p; }
SkyPoint modCalcAzel::getHorCoords (void) { dms azCoord, elCoord; azCoord = azBox->createDms(); elCoord = elBox->createDms(); SkyPoint sp = SkyPoint(); sp.setAz(azCoord); sp.setAlt(elCoord); return sp; }
SkyPoint Projector::fromScreen(const QPointF& p, dms* LST, const dms* lat) const { dms c; double sinc, cosc; /** N.B. We don't cache these sin/cos values in the inverse * projection because it causes 'shaking' when moving the sky. */ double sinY0, cosY0; //Convert pixel position to x and y offsets in radians double dx = (0.5*m_vp.width - p.x())/m_vp.zoomFactor; double dy = (0.5*m_vp.height - p.y())/m_vp.zoomFactor; double r = sqrt( dx*dx + dy*dy ); c.setRadians( projectionL(r) ); c.SinCos( sinc, cosc ); if( m_vp.useAltAz ) { dx = -1.0*dx; //Azimuth goes in opposite direction compared to RA m_vp.focus->alt().SinCos( sinY0, cosY0 ); } else { m_vp.focus->dec().SinCos( sinY0, cosY0 ); } double Y = asin( cosc*sinY0 + ( dy*sinc*cosY0 )/r ); double atop = dx*sinc; double abot = r*cosY0*cosc - dy*sinY0*sinc; double A = atan2( atop, abot ); SkyPoint result; if ( m_vp.useAltAz ) { dms alt, az; alt.setRadians( Y ); az.setRadians( A + m_vp.focus->az().radians() ); if ( m_vp.useRefraction ) alt = SkyPoint::unrefract( alt ); result.setAlt( alt ); result.setAz( az ); result.HorizontalToEquatorial( LST, lat ); } else { dms ra, dec; dec.setRadians( Y ); ra.setRadians( A + m_vp.focus->ra().radians() ); result.set( ra.reduce(), dec ); result.EquatorialToHorizontal( LST, lat ); } return result; }
HorizonComponent::HorizonComponent(SkyComposite *parent ) : PointListComponent( parent ) { KStarsData *data = KStarsData::Instance(); emitProgressText( i18n("Creating horizon" ) ); //Define Horizon for ( unsigned int i=0; i<NCIRCLE; ++i ) { SkyPoint *o = new SkyPoint(); o->setAz( i*360./NCIRCLE ); o->setAlt( 0.0 ); o->HorizontalToEquatorial( data->lst(), data->geo()->lat() ); pointList().append( o ); } }
void modCalcAzel::processLines( QTextStream &istream ) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputLineEditBatch->text(); QFile fOut( outputFileName ); fOut.open(IO_WriteOnly); QTextStream ostream(&fOut); QString line; QString space = " "; int i = 0; long double jd0, jdf; dms LST; SkyPoint sp; dms raB, decB, latB, longB, azB, elB; double epoch0B; QTime utB; ExtDate dtB; while ( ! istream.eof() ) { line = istream.readLine(); line.stripWhiteSpace(); //Go through the line, looking for parameters QStringList fields = QStringList::split( " ", line ); i = 0; // Read Ut and write in ostream if corresponds if(utCheckBatch->isChecked() ) { utB = QTime::fromString( fields[i] ); i++; } else utB = utBoxBatch->time(); if ( allRadioBatch->isChecked() ) ostream << utB.toString() << space; else if(utCheckBatch->isChecked() ) ostream << utB.toString() << space; // Read date and write in ostream if corresponds if(dateCheckBatch->isChecked() ) { dtB = ExtDate::fromString( fields[i] ); i++; } else dtB = dateBoxBatch->date(); if ( allRadioBatch->isChecked() ) ostream << dtB.toString().append(space); else if(dateCheckBatch->isChecked() ) ostream << dtB.toString().append(space); // Read Longitude and write in ostream if corresponds if (longCheckBatch->isChecked() ) { longB = dms::fromString( fields[i],TRUE); i++; } else longB = longBoxBatch->createDms(TRUE); if ( allRadioBatch->isChecked() ) ostream << longB.toDMSString() << space; else if (longCheckBatch->isChecked() ) ostream << longB.toDMSString() << space; // Read Latitude if (latCheckBatch->isChecked() ) { latB = dms::fromString( fields[i], TRUE); i++; } else latB = latBoxBatch->createDms(TRUE); if ( allRadioBatch->isChecked() ) ostream << latB.toDMSString() << space; else if (latCheckBatch->isChecked() ) ostream << latB.toDMSString() << space; // Read Epoch and write in ostream if corresponds if(epochCheckBatch->isChecked() ) { epoch0B = fields[i].toDouble(); i++; } else epoch0B = getEpoch( epochBoxBatch->text() ); if ( allRadioBatch->isChecked() ) ostream << epoch0B << space; else if(epochCheckBatch->isChecked() ) ostream << epoch0B << space; // We make the first calculations KStarsDateTime dt; dt.setFromEpoch( epoch0B ); jdf = KStarsDateTime(dtB,utB).djd(); jd0 = dt.djd(); LST = KStarsDateTime(dtB,utB).gst().Degrees() + longB.Degrees(); // Equatorial coordinates are the input coords. if (!horInputCoords) { // Read RA and write in ostream if corresponds if(raCheckBatch->isChecked() ) { raB = dms::fromString( fields[i],FALSE); i++; } else raB = raBoxBatch->createDms(FALSE); if ( allRadioBatch->isChecked() ) ostream << raB.toHMSString() << space; else if(raCheckBatch->isChecked() ) ostream << raB.toHMSString() << space; // Read DEC and write in ostream if corresponds if(decCheckBatch->isChecked() ) { decB = dms::fromString( fields[i], TRUE); i++; } else decB = decBoxBatch->createDms(); if ( allRadioBatch->isChecked() ) ostream << decB.toDMSString() << space; else if(decCheckBatch->isChecked() ) ostream << decB.toDMSString() << space; sp = SkyPoint (raB, decB); sp.apparentCoord(jd0, jdf); sp.EquatorialToHorizontal( &LST, &latB ); ostream << sp.az()->toDMSString() << space << sp.alt()->toDMSString() << endl; // Input coords are horizontal coordinates } else { if(azCheckBatch->isChecked() ) { azB = dms::fromString( fields[i],FALSE); i++; } else azB = azBoxBatch->createDms(); if ( allRadioBatch->isChecked() ) ostream << azB.toHMSString() << space; else if(raCheckBatch->isChecked() ) ostream << azB.toHMSString() << space; // Read DEC and write in ostream if corresponds if(elCheckBatch->isChecked() ) { elB = dms::fromString( fields[i], TRUE); i++; } else elB = decBoxBatch->createDms(); if ( allRadioBatch->isChecked() ) ostream << elB.toDMSString() << space; else if(elCheckBatch->isChecked() ) ostream << elB.toDMSString() << space; sp.setAz(azB); sp.setAlt(elB); sp.HorizontalToEquatorial( &LST, &latB ); ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl; } } fOut.close(); }
QVector< Vector2f > EquirectangularProjector::groundPoly(SkyPoint* labelpoint, bool* drawLabel) const { float x0 = m_vp.width/2.; float y0 = m_vp.width/2.; if( m_vp.useAltAz ) { float dX = m_vp.zoomFactor*M_PI; float dY = m_vp.zoomFactor*M_PI; SkyPoint belowFocus; belowFocus.setAz( m_vp.focus->az().Degrees() ); belowFocus.setAlt( 0.0 ); Vector2f obf = toScreenVec( &belowFocus, false ); //If the horizon is off the bottom edge of the screen, //we can return immediately if ( obf.y() > m_vp.height ) { if( drawLabel ) *drawLabel = false; return QVector<Vector2f>(); } //We can also return if the horizon is off the top edge, //as long as the ground poly is not being drawn if ( obf.y() < 0. && m_vp.fillGround == false ) { if( drawLabel ) *drawLabel = false; return QVector<Vector2f>(); } QVector<Vector2f> ground; //Construct the ground polygon, which is a simple rectangle in this case ground << Vector2f( x0 - dX, obf.y() ) << Vector2f( x0 + dX, obf.y() ) << Vector2f( x0 + dX, y0 + dY ) << Vector2f( x0 - dX, y0 + dY ); if( labelpoint ) { QPointF pLabel( x0 -dX -50., obf.y() ); KStarsData *data = KStarsData::Instance(); *labelpoint = fromScreen(pLabel, data->lst(), data->geo()->lat()); } if( drawLabel ) *drawLabel = true; return ground; } else { float dX = m_vp.zoomFactor*M_PI/2; float dY = m_vp.zoomFactor*M_PI/2; QVector<Vector2f> ground; static const QString horizonLabel = i18n("Horizon"); float marginLeft, marginRight, marginTop, marginBot; SkyLabeler::Instance()->getMargins( horizonLabel, &marginLeft, &marginRight, &marginTop, &marginBot ); double daz = 90.; double faz = m_vp.focus->az().Degrees(); double az1 = faz -daz; double az2 = faz +daz; bool allGround = true; bool allSky = true; double inc = 1.0; //Add points along horizon for(double az = az1; az <= az2 + inc; az += inc) { SkyPoint p = pointAt(az); bool visible = false; Vector2f o = toScreenVec(&p, false, &visible); if( visible ) { ground.append( o ); //Set the label point if this point is onscreen if ( labelpoint && o.x() < marginRight && o.y() > marginTop && o.y() < marginBot ) *labelpoint = p; if ( o.y() > 0. ) allGround = false; if ( o.y() < m_vp.height ) allSky = false; } } if( allSky ) { if( drawLabel) *drawLabel = false; return QVector<Vector2f>(); } if( allGround ) { ground.clear(); ground.append( Vector2f( x0 - dX, y0 - dY ) ); ground.append( Vector2f( x0 + dX, y0 - dY ) ); ground.append( Vector2f( x0 + dX, y0 + dY ) ); ground.append( Vector2f( x0 - dX, y0 + dY ) ); if( drawLabel) *drawLabel = false; return ground; } if( labelpoint ) { QPointF pLabel( x0 -dX -50., ground.last().y() ); KStarsData *data = KStarsData::Instance(); *labelpoint = fromScreen(pLabel, data->lst(), data->geo()->lat()); } if( drawLabel ) *drawLabel = true; //Now add points along the ground ground.append( Vector2f( x0 + dX, ground.last().y() ) ); ground.append( Vector2f( x0 + dX, y0 + dY ) ); ground.append( Vector2f( x0 - dX, y0 + dY ) ); ground.append( Vector2f( x0 - dX, ground.first().y() ) ); return ground; } }