• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • skyobjects
skypoint.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  skypoint.cpp - K Desktop Planetarium
3  -------------------
4  begin : Sun Feb 11 2001
5  copyright : (C) 2001-2005 by Jason Harris
6  email : jharris@30doradus.org
7  copyright : (C) 2004-2005 by Pablo de Vicente
8  email : p.devicente@wanadoo.es
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #include "skypoint.h"
21 
22 #include <kdebug.h>
23 #include <klocale.h>
24 
25 #include "skyobject.h"
26 #include "dms.h"
27 #include "ksnumbers.h"
28 #include "kstarsdatetime.h" //for J2000 define
29 #include "kssun.h"
30 #include "kstarsdata.h"
31 #include "Options.h"
32 #include "skycomponents/skymapcomposite.h"
33 
34 KSSun *SkyPoint::m_Sun = 0;
35 const double SkyPoint::altCrit = -1.0;
36 
37 SkyPoint::SkyPoint() {
38  // Default constructor. Set nonsense values
39  RA0.setD(-1); // RA >= 0 always :-)
40  Dec0.setD(180); // Dec is between -90 and 90 Degrees :-)
41  RA = RA0;
42  Dec = Dec0;
43  lastPrecessJD = J2000; // By convention, we use J2000 coordinates
44 }
45 
46 void SkyPoint::set( const dms& r, const dms& d ) {
47  RA0 = RA = r;
48  Dec0 = Dec = d;
49  lastPrecessJD = J2000; // By convention, we use J2000 coordinates
50 }
51 
52 SkyPoint::~SkyPoint(){
53 }
54 
55 void SkyPoint::EquatorialToHorizontal( const dms *LST, const dms *lat ) {
56  //Uncomment for spherical trig version
57  double AltRad, AzRad;
58  double sindec, cosdec, sinlat, coslat, sinHA, cosHA;
59  double sinAlt, cosAlt;
60 
61  dms HourAngle = (*LST) - ra();
62 
63  lat->SinCos( sinlat, coslat );
64  dec().SinCos( sindec, cosdec );
65  HourAngle.SinCos( sinHA, cosHA );
66 
67  sinAlt = sindec*sinlat + cosdec*coslat*cosHA;
68  AltRad = asin( sinAlt );
69  cosAlt = cos( AltRad );
70 
71  double arg = ( sindec - sinlat*sinAlt )/( coslat*cosAlt );
72  if ( arg <= -1.0 ) AzRad = dms::PI;
73  else if ( arg >= 1.0 ) AzRad = 0.0;
74  else AzRad = acos( arg );
75 
76  if ( sinHA > 0.0 ) AzRad = 2.0*dms::PI - AzRad; // resolve acos() ambiguity
77 
78  Alt.setRadians( AltRad );
79  Az.setRadians( AzRad );
80 
81  // //Uncomment for XYZ version
82  // double xr, yr, zr, xr1, zr1, sa, ca;
83  // //Z-axis rotation by -LST
84  // dms a = dms( -1.0*LST->Degrees() );
85  // a.SinCos( sa, ca );
86  // xr1 = m_X*ca + m_Y*sa;
87  // yr = -1.0*m_X*sa + m_Y*ca;
88  // zr1 = m_Z;
89  //
90  // //Y-axis rotation by lat - 90.
91  // a = dms( lat->Degrees() - 90.0 );
92  // a.SinCos( sa, ca );
93  // xr = xr1*ca - zr1*sa;
94  // zr = xr1*sa + zr1*ca;
95  //
96  // //FIXME: eventually, we will work with XYZ directly
97  // Alt.setRadians( asin( zr ) );
98  // Az.setRadians( atan2( yr, xr ) );
99 
100 }
101 
102 void SkyPoint::HorizontalToEquatorial( const dms *LST, const dms *lat ) {
103  double HARad, DecRad;
104  double sinlat, coslat, sinAlt, cosAlt, sinAz, cosAz;
105  double sinDec, cosDec;
106 
107  lat->SinCos( sinlat, coslat );
108  alt().SinCos( sinAlt, cosAlt );
109  Az.SinCos( sinAz, cosAz );
110 
111  sinDec = sinAlt*sinlat + cosAlt*coslat*cosAz;
112  DecRad = asin( sinDec );
113  cosDec = cos( DecRad );
114  Dec.setRadians( DecRad );
115 
116  double x = ( sinAlt - sinlat*sinDec )/( coslat*cosDec );
117 
118  //Under certain circumstances, x can be very slightly less than -1.0000, or slightly
119  //greater than 1.0000, leading to a crash on acos(x). However, the value isn't
120  //*really* out of range; it's a kind of roundoff error.
121  if ( x < -1.0 && x > -1.000001 ) HARad = dms::PI;
122  else if ( x > 1.0 && x < 1.000001 ) HARad = 0.0;
123  else if ( x < -1.0 ) {
124  kWarning() << i18n( "Coordinate out of range." ) << endl;
125  HARad = dms::PI;
126  } else if ( x > 1.0 ) {
127  kWarning() << i18n( "Coordinate out of range." ) << endl;
128  HARad = 0.0;
129  } else HARad = acos( x );
130 
131  if ( sinAz > 0.0 ) HARad = 2.0*dms::PI - HARad; // resolve acos() ambiguity
132 
133  RA.setRadians( LST->radians() - HARad );
134  RA.setD( RA.reduce().Degrees() ); // 0 <= RA < 24
135 }
136 
137 void SkyPoint::findEcliptic( const dms *Obliquity, dms &EcLong, dms &EcLat ) {
138  double sinRA, cosRA, sinOb, cosOb, sinDec, cosDec, tanDec;
139  ra().SinCos( sinRA, cosRA );
140  dec().SinCos( sinDec, cosDec );
141  Obliquity->SinCos( sinOb, cosOb );
142 
143  tanDec = sinDec/cosDec; // FIXME: -jbb div by zero?
144  double y = sinRA*cosOb + tanDec*sinOb;
145  double ELongRad = atan2( y, cosRA );
146  EcLong.setRadians( ELongRad );
147  EcLong.reduce();
148  EcLat.setRadians( asin( sinDec*cosOb - cosDec*sinOb*sinRA ) );
149 }
150 
151 void SkyPoint::setFromEcliptic( const dms *Obliquity, const dms& EcLong, const dms& EcLat ) {
152  double sinLong, cosLong, sinLat, cosLat, sinObliq, cosObliq;
153  EcLong.SinCos( sinLong, cosLong );
154  EcLat.SinCos( sinLat, cosLat );
155  Obliquity->SinCos( sinObliq, cosObliq );
156 
157  double sinDec = sinLat*cosObliq + cosLat*sinObliq*sinLong;
158 
159  double y = sinLong*cosObliq - (sinLat/cosLat)*sinObliq;
160  double RARad = atan2( y, cosLong );
161  RA.setRadians( RARad );
162  RA.reduce();
163  Dec.setRadians( asin(sinDec) );
164 }
165 
166 void SkyPoint::precess( const KSNumbers *num) {
167  double cosRA0, sinRA0, cosDec0, sinDec0;
168  double v[3], s[3];
169 
170  RA0.SinCos( sinRA0, cosRA0 );
171  Dec0.SinCos( sinDec0, cosDec0 );
172 
173  s[0] = cosRA0*cosDec0;
174  s[1] = sinRA0*cosDec0;
175  s[2] = sinDec0;
176  //Multiply P2 and s to get v, the vector representing the new coords.
177  for ( unsigned int i=0; i<3; ++i ) {
178  v[i] = 0.0;
179  for (uint j=0; j< 3; ++j) {
180  v[i] += num->p2( j, i )*s[j];
181  }
182  }
183 
184  //Extract RA, Dec from the vector:
185  RA.setRadians( atan2( v[1], v[0] ) );
186  RA.reduce();
187  Dec.setRadians( asin( v[2] ) );
188 }
189 
190 SkyPoint SkyPoint::deprecess( const KSNumbers *num, long double epoch ) {
191  SkyPoint p1( RA, Dec );
192  long double now = num->julianDay();
193  p1.precessFromAnyEpoch( now, epoch );
194  if( RA0.Degrees() < 0.0 || Dec0.Degrees() > 90.0 ) {
195  // We have invalid RA0 and Dec0, so set them.
196  RA0 = p1.ra();
197  Dec0 = p1.dec();
198  }
199  return p1;
200 }
201 
202 void SkyPoint::nutate(const KSNumbers *num) {
203  double cosRA, sinRA, cosDec, sinDec, tanDec;
204  double cosOb, sinOb;
205 
206  RA.SinCos( sinRA, cosRA );
207  Dec.SinCos( sinDec, cosDec );
208 
209  num->obliquity()->SinCos( sinOb, cosOb );
210 
211  //Step 2: Nutation
212  if ( fabs( Dec.Degrees() ) < 80.0 ) { //approximate method
213  tanDec = sinDec/cosDec;
214 
215  double dRA = num->dEcLong()*( cosOb + sinOb*sinRA*tanDec ) - num->dObliq()*cosRA*tanDec;
216  double dDec = num->dEcLong()*( sinOb*cosRA ) + num->dObliq()*sinRA;
217 
218  RA.setD( RA.Degrees() + dRA );
219  Dec.setD( Dec.Degrees() + dDec );
220  } else { //exact method
221  dms EcLong, EcLat;
222  findEcliptic( num->obliquity(), EcLong, EcLat );
223 
224  //Add dEcLong to the Ecliptic Longitude
225  dms newLong( EcLong.Degrees() + num->dEcLong() );
226  setFromEcliptic( num->obliquity(), newLong, EcLat );
227  }
228 }
229 
230 SkyPoint SkyPoint::moveAway( const SkyPoint &from, double dist ){
231  dms lat1, dtheta;
232 
233  if( dist == 0.0 ) {
234  kDebug() << "moveThrough called with zero distance!";
235  return *this;
236  }
237 
238  double dst = fabs( dist * dms::DegToRad / 3600.0 ); // In radian
239 
240  // Compute the bearing angle w.r.t. the RA axis ("latitude")
241  dms dRA( ra() - from.ra() );
242  dms dDec( dec() - from.dec() );
243  double bearing = atan2( dRA.sin() / dRA.cos(), dDec.sin() ); // Do not use dRA = PI / 2!!
244  //double bearing = atan2( dDec.radians() , dRA.radians() );
245 
246  double dir0 = (dist >= 0 ) ? bearing : bearing + dms::PI; // in radian
247  dist = fabs( dist ); // in radian
248 
249 
250  lat1.setRadians( asin( dec().sin() * cos( dst ) +
251  dec().cos() * sin( dst ) * cos( dir0 ) ) );
252  dtheta.setRadians( atan2( sin( dir0 ) * sin( dst ) * dec().cos(),
253  cos( dst ) - dec().sin() * lat1.sin() ) );
254 
255  return SkyPoint( ra() + dtheta, lat1 );
256 }
257 
258 bool SkyPoint::checkBendLight() {
259  // First see if we are close enough to the sun to bother about the
260  // gravitational lensing effect. We correct for the effect at
261  // least till b = 10 solar radii, where the effect is only about
262  // 0.06". Assuming min. sun-earth distance is 200 solar radii.
263  static const dms maxAngle( 1.75 * ( 30.0 / 200.0) / dms::DegToRad );
264 
265  if( !m_Sun )
266  m_Sun = (KSSun*) KStarsData::Instance()->skyComposite()->findByName( "Sun" );
267 
268  // TODO: This can be optimized further. We only need a ballpark estimate of the distance to the sun to start with.
269  return ( fabs( angularDistanceTo( static_cast<const SkyPoint *>(m_Sun) ).Degrees() ) <= maxAngle.Degrees() ); // NOTE: dynamic_cast is slow and not important here.
270 }
271 
272 bool SkyPoint::bendlight() {
273 
274  // NOTE: This should be applied before aberration
275  // NOTE: One must call checkBendLight() before unnecessarily calling this.
276  // We correct for GR effects
277  Q_ASSERT( m_Sun );
278  double corr_sec = 1.75 * m_Sun->physicalSize() / ( m_Sun->rearth() * AU_KM * angularDistanceTo( static_cast<const SkyPoint *>(m_Sun) ).sin() );
279  Q_ASSERT( corr_sec > 0 );
280 
281  SkyPoint sp = moveAway( *m_Sun, corr_sec );
282  setRA( sp.ra() );
283  setDec( sp.dec() );
284  return true;
285 }
286 
287 void SkyPoint::aberrate(const KSNumbers *num) {
288  double cosRA, sinRA, cosDec, sinDec;
289  double cosOb, sinOb, cosL, sinL, cosP, sinP;
290 
291  double K = num->constAberr().Degrees(); //constant of aberration
292  double e = num->earthEccentricity();
293 
294  RA.SinCos( sinRA, cosRA );
295  Dec.SinCos( sinDec, cosDec );
296 
297  num->obliquity()->SinCos( sinOb, cosOb );
298  double tanOb = sinOb/cosOb;
299 
300  num->sunTrueLongitude().SinCos( sinL, cosL );
301  num->earthPerihelionLongitude().SinCos( sinP, cosP );
302 
303 
304  //Step 3: Aberration
305  double dRA = -1.0 * K * ( cosRA * cosL * cosOb + sinRA * sinL )/cosDec
306  + e * K * ( cosRA * cosP * cosOb + sinRA * sinP )/cosDec;
307 
308  double dDec = -1.0 * K * ( cosL * cosOb * ( tanOb * cosDec - sinRA * sinDec ) + cosRA * sinDec * sinL )
309  + e * K * ( cosP * cosOb * ( tanOb * cosDec - sinRA * sinDec ) + cosRA * sinDec * sinP );
310 
311  RA.setD( RA.Degrees() + dRA );
312  Dec.setD( Dec.Degrees() + dDec );
313 
314 }
315 
316 // Note: This method is one of the major rate determining factors in how fast the map pans / zooms in or out
317 void SkyPoint::updateCoords( KSNumbers *num, bool /*includePlanets*/, const dms *lat, const dms *LST, bool forceRecompute ) {
318  //Correct the catalog coordinates for the time-dependent effects
319  //of precession, nutation and aberration
320  bool recompute, lens;
321 
322  // NOTE: The same short-circuiting checks are also implemented in
323  // StarObject::JITUpdate(), even before calling
324  // updateCoords(). While this is code-duplication, these bits of
325  // code need to be really optimized, at least for stars. For
326  // optimization purposes, the code is left duplicated in two
327  // places. Please be wary of changing one without changing the
328  // other.
329 
330  Q_ASSERT( std::isfinite( lastPrecessJD ) );
331 
332  if( Options::useRelativistic() && checkBendLight() ) {
333  recompute = true;
334  lens = true;
335  }
336  else {
337  recompute = ( Options::alwaysRecomputeCoordinates() ||
338  ( lastPrecessJD - num->getJD() ) >= 0.0005 ||
339  (lastPrecessJD - num->getJD() ) <= -0.0005 || forceRecompute ); // 0.0005 solar days is less than a minute
340  lens = false;
341  }
342  if( recompute ) {
343  precess(num);
344  nutate(num);
345  if( lens )
346  bendlight();
347  aberrate(num);
348  lastPrecessJD = num->getJD();
349  Q_ASSERT( std::isfinite( RA.Degrees() ) && std::isfinite( Dec.Degrees() ) );
350  }
351 
352  if ( lat || LST )
353  kWarning() << i18n( "lat and LST parameters should only be used in KSPlanetBase objects." ) ;
354 }
355 
356 void SkyPoint::precessFromAnyEpoch(long double jd0, long double jdf){
357 
358  double cosRA, sinRA, cosDec, sinDec;
359  double v[3], s[3];
360 
361  RA.setD( RA0.Degrees() );
362  Dec.setD( Dec0.Degrees() );
363 
364  RA.SinCos( sinRA, cosRA );
365  Dec.SinCos( sinDec, cosDec );
366 
367  if (jd0 == jdf)
368  return;
369 
370  if ( jd0 == B1950) {
371  B1950ToJ2000();
372  jd0 = J2000;
373  RA.SinCos( sinRA, cosRA );
374  Dec.SinCos( sinDec, cosDec );
375 
376  }
377 
378  if (jd0 !=jdf) {
379  // The original coordinate is referred to the FK5 system and
380  // is NOT J2000.
381  if ( jd0 != J2000 ) {
382 
383  //v is a column vector representing input coordinates.
384  v[0] = cosRA*cosDec;
385  v[1] = sinRA*cosDec;
386  v[2] = sinDec;
387 
388  //Need to first precess to J2000.0 coords
389  //s is the product of P1 and v; s represents the
390  //coordinates precessed to J2000
391  KSNumbers num(jd0);
392  for ( unsigned int i=0; i<3; ++i ) {
393  s[i] = num.p1( 0, i )*v[0] +
394  num.p1( 1, i )*v[1] +
395  num.p1( 2, i )*v[2];
396  }
397 
398  //Input coords already in J2000, set s accordingly.
399  } else {
400 
401  s[0] = cosRA*cosDec;
402  s[1] = sinRA*cosDec;
403  s[2] = sinDec;
404  }
405 
406  if ( jdf == B1950) {
407 
408  RA.setRadians( atan2( s[1],s[0] ) );
409  Dec.setRadians( asin( s[2] ) );
410  J2000ToB1950();
411 
412  return;
413  }
414 
415  KSNumbers num(jdf);
416  for ( unsigned int i=0; i<3; ++i ) {
417  v[i] = num.p2( 0, i )*s[0] +
418  num.p2( 1, i )*s[1] +
419  num.p2( 2, i )*s[2];
420  }
421 
422  RA.setRadians( atan2( v[1],v[0] ) );
423  Dec.setRadians( asin( v[2] ) );
424 
425  if (RA.Degrees() < 0.0 )
426  RA.setD( RA.Degrees() + 360.0 );
427 
428  return;
429  }
430 
431 }
432 
433 void SkyPoint::apparentCoord(long double jd0, long double jdf){
434  precessFromAnyEpoch(jd0,jdf);
435  KSNumbers num(jdf);
436  nutate( &num );
437  if( Options::useRelativistic() && checkBendLight() )
438  bendlight();
439  aberrate( &num );
440 }
441 
442 void SkyPoint::Equatorial1950ToGalactic(dms &galLong, dms &galLat) {
443 
444  double a = 192.25;
445  double sinb, cosb, sina_RA, cosa_RA, sinDEC, cosDEC, tanDEC;
446 
447  dms c(303.0);
448  dms b(27.4);
449  tanDEC = tan( Dec.radians() );
450 
451  b.SinCos(sinb,cosb);
452  dms( a - RA.Degrees() ).SinCos(sina_RA,cosa_RA);
453  Dec.SinCos(sinDEC,cosDEC);
454 
455  galLong.setRadians( c.radians() - atan2( sina_RA, cosa_RA*sinb-tanDEC*cosb) );
456  galLong = galLong.reduce();
457 
458  galLat.setRadians( asin(sinDEC*sinb+cosDEC*cosb*cosa_RA) );
459 }
460 
461 void SkyPoint::GalacticToEquatorial1950(const dms* galLong, const dms* galLat) {
462 
463  double a = 123.0;
464  double sinb, cosb, singLat, cosgLat, tangLat, singLong_a, cosgLong_a;
465 
466  dms c(12.25);
467  dms b(27.4);
468  tangLat = tan( galLat->radians() );
469  galLat->SinCos(singLat,cosgLat);
470 
471  dms( galLong->Degrees() - a ).SinCos(singLong_a,cosgLong_a);
472  b.SinCos(sinb,cosb);
473 
474  RA.setRadians(c.radians() + atan2(singLong_a,cosgLong_a*sinb-tangLat*cosb) );
475  RA = RA.reduce();
476 
477  Dec.setRadians( asin(singLat*sinb+cosgLat*cosb*cosgLong_a) );
478 }
479 
480 void SkyPoint::B1950ToJ2000(void) {
481  double cosRA, sinRA, cosDec, sinDec;
482  // double cosRA0, sinRA0, cosDec0, sinDec0;
483  double v[3], s[3];
484 
485  // 1984 January 1 0h
486  KSNumbers num(2445700.5);
487 
488  // Eterms due to aberration
489  addEterms();
490  RA.SinCos( sinRA, cosRA );
491  Dec.SinCos( sinDec, cosDec );
492 
493  // Precession from B1950 to J1984
494  s[0] = cosRA*cosDec;
495  s[1] = sinRA*cosDec;
496  s[2] = sinDec;
497  for ( unsigned int i=0; i<3; ++i ) {
498  v[i] = num.p2b( 0, i )*s[0]
499  + num.p2b( 1, i )*s[1]
500  + num.p2b( 2, i )*s[2];
501  }
502 
503  // RA zero-point correction at 1984 day 1, 0h.
504  RA.setRadians( atan2( v[1],v[0] ) );
505  Dec.setRadians( asin( v[2] ) );
506 
507  RA.setH( RA.Hours() + 0.06390/3600. );
508  RA.SinCos( sinRA, cosRA );
509  Dec.SinCos( sinDec, cosDec );
510 
511  s[0] = cosRA*cosDec;
512  s[1] = sinRA*cosDec;
513  s[2] = sinDec;
514 
515  // Precession from 1984 to J2000.
516 
517  for ( unsigned int i=0; i<3; ++i ) {
518  v[i] = num.p1( 0, i )*s[0] +
519  num.p1( 1, i )*s[1] +
520  num.p1( 2, i )*s[2];
521  }
522 
523  RA.setRadians( atan2( v[1],v[0] ) );
524  Dec.setRadians( asin( v[2] ) );
525 }
526 
527 void SkyPoint::J2000ToB1950(void) {
528  double cosRA, sinRA, cosDec, sinDec;
529  // double cosRA0, sinRA0, cosDec0, sinDec0;
530  double v[3], s[3];
531 
532  // 1984 January 1 0h
533  KSNumbers num(2445700.5);
534 
535  RA.SinCos( sinRA, cosRA );
536  Dec.SinCos( sinDec, cosDec );
537 
538  s[0] = cosRA*cosDec;
539  s[1] = sinRA*cosDec;
540  s[2] = sinDec;
541 
542  // Precession from J2000 to 1984 day, 0h.
543 
544  for ( unsigned int i=0; i<3; ++i ) {
545  v[i] = num.p2( 0, i )*s[0] +
546  num.p2( 1, i )*s[1] +
547  num.p2( 2, i )*s[2];
548  }
549 
550  RA.setRadians( atan2( v[1],v[0] ) );
551  Dec.setRadians( asin( v[2] ) );
552 
553  // RA zero-point correction at 1984 day 1, 0h.
554 
555  RA.setH( RA.Hours() - 0.06390/3600. );
556  RA.SinCos( sinRA, cosRA );
557  Dec.SinCos( sinDec, cosDec );
558 
559  // Precession from B1950 to J1984
560 
561  s[0] = cosRA*cosDec;
562  s[1] = sinRA*cosDec;
563  s[2] = sinDec;
564  for ( unsigned int i=0; i<3; ++i ) {
565  v[i] = num.p1b( 0, i )*s[0]
566  + num.p1b( 1, i )*s[1]
567  + num.p1b( 2, i )*s[2];
568  }
569 
570  RA.setRadians( atan2( v[1],v[0] ) );
571  Dec.setRadians( asin( v[2] ) );
572 
573  // Eterms due to aberration
574  subtractEterms();
575 }
576 
577 SkyPoint SkyPoint::Eterms(void) {
578 
579  double sd, cd, sinEterm, cosEterm;
580  dms raTemp, raDelta, decDelta;
581 
582  Dec.SinCos(sd,cd);
583  raTemp.setH( RA.Hours() + 11.25);
584  raTemp.SinCos(sinEterm,cosEterm);
585 
586  raDelta.setH( 0.0227*sinEterm/(3600.*cd) );
587  decDelta.setD( 0.341*cosEterm*sd/3600. + 0.029*cd/3600. );
588 
589  return SkyPoint(raDelta, decDelta);
590 }
591 
592 void SkyPoint::addEterms(void) {
593 
594  SkyPoint spd = Eterms();
595 
596  RA = RA + spd.ra();
597  Dec = Dec + spd.dec();
598 }
599 
600 void SkyPoint::subtractEterms(void) {
601 
602  SkyPoint spd = Eterms();
603 
604  RA = RA - spd.ra();
605  Dec = Dec - spd.dec();
606 }
607 
608 dms SkyPoint::angularDistanceTo(const SkyPoint *sp, double * const positionAngle) const {
609 
610  double dalpha = ra().radians() - sp->ra().radians() ;
611  double ddelta = dec().radians() - sp->dec().radians() ;
612 
613  double sa = sin(dalpha/2.);
614  double sd = sin(ddelta/2.);
615 
616  double hava = sa*sa;
617  double havd = sd*sd;
618 
619  double aux = havd + cos (dec().radians()) * cos(sp->dec().radians()) // Haversine law
620  * hava;
621 
622  dms angDist;
623  angDist.setRadians( 2 * fabs(asin( sqrt(aux) )) );
624 
625  if( positionAngle ) {
626  // Also compute the position angle of the line from this SkyPoint to sp
627  *positionAngle = acos( tan(-ddelta)/tan( angDist.radians() ) ); // FIXME: Might fail for large ddelta / zero angDist
628  if( -dalpha < 0 )
629  *positionAngle = 2*M_PI - *positionAngle;
630  }
631  return angDist;
632 }
633 
634 double SkyPoint::vRSun(long double jd0) {
635 
636  double ca, sa, cd, sd, vsun;
637  double cosRA, sinRA, cosDec, sinDec;
638 
639  /* Sun apex (where the sun goes) coordinates */
640 
641  dms asun(270.9592); // Right ascention: 18h 3m 50.2s [J2000]
642  dms dsun(30.00467); // Declination: 30^o 0' 16.8'' [J2000]
643  vsun=20.; // [km/s]
644 
645  asun.SinCos(sa,ca);
646  dsun.SinCos(sd,cd);
647 
648  /* We need an auxiliary SkyPoint since we need the
649  * source referred to the J2000 equinox and we do not want to ovewrite
650  * the current values
651  */
652 
653  SkyPoint aux;
654  aux.set(RA0,Dec0);
655 
656  aux.precessFromAnyEpoch(jd0, J2000);
657 
658  aux.ra().SinCos( sinRA, cosRA );
659  aux.dec().SinCos( sinDec, cosDec );
660 
661  /* Computation is done performing the scalar product of a unitary vector
662  in the direction of the source with the vector velocity of Sun, both being in the
663  LSR reference system:
664  Vlsr = Vhel + Vsun.u_radial =>
665  Vlsr = Vhel + vsun(cos D cos A,cos D sen A,sen D).(cos d cos a,cos d sen a,sen d)
666  Vhel = Vlsr - Vsun.u_radial
667  */
668 
669  return vsun *(cd*cosDec*(cosRA*ca + sa*sinRA) + sd*sinDec);
670 
671 }
672 
673 double SkyPoint::vHeliocentric(double vlsr, long double jd0) {
674 
675  return vlsr - vRSun(jd0);
676 }
677 
678 double SkyPoint::vHelioToVlsr(double vhelio, long double jd0) {
679 
680  return vhelio + vRSun(jd0);
681 }
682 
683 double SkyPoint::vREarth(long double jd0)
684 {
685  double sinRA, sinDec, cosRA, cosDec;
686 
687  /* u_radial = unitary vector in the direction of the source
688  Vlsr = Vhel + Vsun.u_radial
689  = Vgeo + VEarth.u_radial + Vsun.u_radial =>
690 
691  Vgeo = (Vlsr -Vsun.u_radial) - VEarth.u_radial
692  = Vhel - VEarth.u_radial
693  = Vhel - (vx, vy, vz).(cos d cos a,cos d sen a,sen d)
694  */
695 
696  /* We need an auxiliary SkyPoint since we need the
697  * source referred to the J2000 equinox and we do not want to ovewrite
698  * the current values
699  */
700 
701  SkyPoint aux( RA0, Dec0 );
702 
703  aux.precessFromAnyEpoch(jd0, J2000);
704 
705  aux.ra().SinCos( sinRA, cosRA );
706  aux.dec().SinCos( sinDec, cosDec );
707 
708  /* vEarth is referred to the J2000 equinox, hence we need that
709  the source coordinates are also in the same reference system.
710  */
711 
712  KSNumbers num(jd0);
713  return num.vEarth(0) * cosDec * cosRA +
714  num.vEarth(1) * cosDec * sinRA +
715  num.vEarth(2) * sinDec;
716 }
717 
718 
719 double SkyPoint::vGeocentric(double vhelio, long double jd0)
720 {
721  return vhelio - vREarth(jd0);
722 }
723 
724 double SkyPoint::vGeoToVHelio(double vgeo, long double jd0)
725 {
726  return vgeo + vREarth(jd0);
727 }
728 
729 double SkyPoint::vRSite(double vsite[3])
730 {
731 
732  double sinRA, sinDec, cosRA, cosDec;
733 
734  RA.SinCos( sinRA, cosRA );
735  Dec.SinCos( sinDec, cosDec );
736 
737  return vsite[0]*cosDec*cosRA + vsite[1]*cosDec*sinRA + vsite[2]*sinDec;
738 }
739 
740 double SkyPoint::vTopoToVGeo(double vtopo, double vsite[3])
741 {
742  return vtopo + vRSite(vsite);
743 }
744 
745 double SkyPoint::vTopocentric(double vgeo, double vsite[3])
746 {
747  return vgeo - vRSite(vsite);
748 }
749 
750 bool SkyPoint::checkCircumpolar( const dms *gLat ) {
751  return fabs(dec().Degrees()) > (90 - fabs(gLat->Degrees()));
752 }
753 
754 dms SkyPoint::altRefracted() const {
755  if( Options::useRefraction() )
756  return refract(Alt);
757  else
758  return Alt;
759 }
760 
761 double SkyPoint::refractionCorr(double alt) {
762  return 1.02 / tan(dms::DegToRad * ( alt + 10.3/(alt + 5.11) )) / 60;
763 }
764 
765 double SkyPoint::refract(const double alt) {
766  static double corrCrit = SkyPoint::refractionCorr( SkyPoint::altCrit );
767 
768  if( alt > SkyPoint::altCrit )
769  return ( alt + SkyPoint::refractionCorr(alt) );
770  else
771  return ( alt + corrCrit * (alt + 90) / (SkyPoint::altCrit + 90) ); // Linear extrapolation from corrCrit at altCrit to 0 at -90 degrees
772 }
773 
774 // Found uncorrected value by solving equation. This is OK since
775 // unrefract is never called in loops.
776 //
777 // Convergence is quite fast just a few iterations.
778 double SkyPoint::unrefract(const double alt) {
779  double h0 = alt;
780  double h1 = alt - (refract( h0 ) - h0); // It's probably okay to add h0 in refract() and subtract it here, since refract() is called way more frequently.
781 
782  while( fabs(h1 - h0) > 1e-4 ) {
783  h0 = h1;
784  h1 = alt - (refract( h0 ) - h0);
785  }
786  return h1;
787 }
SkyPoint::vHelioToVlsr
double vHelioToVlsr(double vhelio, long double jd)
Computes the radial velocity of a source referred to the Local Standard of Rest, also known as VLSR f...
Definition: skypoint.cpp:678
SkyPoint::deprecess
SkyPoint deprecess(const KSNumbers *num, long double epoch=J2000)
Obtain a Skypoint with RA0 and Dec0 set from the RA, Dec of this skypoint.
Definition: skypoint.cpp:190
SkyPoint::Eterms
SkyPoint Eterms(void)
Determine the E-terms of aberration In the past, the mean places of stars published in catalogs inclu...
Definition: skypoint.cpp:577
SkyPoint::checkBendLight
bool checkBendLight()
Check if this sky point is close enough to the sun for gravitational lensing to be significant...
Definition: skypoint.cpp:258
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
SkyPoint::set
void set(const dms &r, const dms &d)
Sets RA, Dec and RA0, Dec0 according to arguments.
Definition: skypoint.cpp:46
SkyPoint::apparentCoord
void apparentCoord(long double jd0, long double jdf)
Computes the apparent coordinates for this SkyPoint for any epoch, accounting for the effects of prec...
Definition: skypoint.cpp:433
SkyPoint::aberrate
void aberrate(const KSNumbers *num)
Determine the effects of aberration for this SkyPoint.
Definition: skypoint.cpp:287
KSSun
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition: kssun.h:31
KSNumbers::p1
double p1(int i1, int i2) const
Definition: ksnumbers.h:99
SkyPoint::altCrit
static const double altCrit
Critical height for atmospheric refraction corrections.
Definition: skypoint.h:496
KSNumbers::vEarth
double vEarth(int i) const
Definition: ksnumbers.h:125
KSNumbers::p2b
double p2b(int i1, int i2) const
Definition: ksnumbers.h:108
SkyPoint::nutate
void nutate(const KSNumbers *num)
Determine the effects of nutation for this SkyPoint.
Definition: skypoint.cpp:202
SkyPoint::J2000ToB1950
void J2000ToB1950(void)
Exact precession from epoch J2000 Besselian epoch 1950.
Definition: skypoint.cpp:527
Options::alwaysRecomputeCoordinates
static bool alwaysRecomputeCoordinates()
Get Always recompute coordinates.
Definition: Options.h:4407
skyobject.h
KSNumbers::getJD
long double getJD() const
Definition: ksnumbers.h:123
SkyPoint::refract
static double refract(const double alt)
Apply refraction correction to altitude.
Definition: skypoint.cpp:765
SkyPoint::findEcliptic
void findEcliptic(const dms *Obliquity, dms &EcLong, dms &EcLat)
Determine the Ecliptic coordinates of the SkyPoint, given the Julian Date.
Definition: skypoint.cpp:137
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
SkyPoint::vRSite
double vRSite(double vsite[3])
Computes the velocity of any object (oberver's site) projected on the direction of the source...
Definition: skypoint.cpp:729
SkyPoint::updateCoords
virtual void updateCoords(KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute=false)
Determine the current coordinates (RA, Dec) from the catalog coordinates (RA0, Dec0), accounting for both precession and nutation.
Definition: skypoint.cpp:317
SkyPoint::precess
void precess(const KSNumbers *num)
Precess this SkyPoint's catalog coordinates to the epoch described by the given KSNumbers object...
Definition: skypoint.cpp:166
Options::useRelativistic
static bool useRelativistic()
Get Apply relativistic corrections due to the bending of light in sun's gravitational field...
Definition: Options.h:2481
B1950
#define B1950
Definition: kstarsdatetime.h:22
KSNumbers::p1b
double p1b(int i1, int i2) const
Definition: ksnumbers.h:105
dms.h
KSPlanetBase::physicalSize
double physicalSize() const
Definition: ksplanetbase.h:179
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
KSNumbers::p2
double p2(int i1, int i2) const
Definition: ksnumbers.h:102
SkyPoint::checkCircumpolar
bool checkCircumpolar(const dms *gLat)
Check if this point is circumpolar at the given geographic latitude.
Definition: skypoint.cpp:750
AU_KM
#define AU_KM
Definition: kstarsdata.h:42
skymapcomposite.h
SkyPoint::moveAway
SkyPoint moveAway(const SkyPoint &from, double dist)
Find the SkyPoint obtained by moving distance dist (arcseconds) away from the givenSkyPoint.
Definition: skypoint.cpp:230
SkyPoint::refractionCorr
static double refractionCorr(double alt)
Calculate refraction correction.
Definition: skypoint.cpp:761
KSNumbers::dObliq
double dObliq() const
Definition: ksnumbers.h:83
SkyPoint::SkyPoint
SkyPoint()
Default constructor.
Definition: skypoint.cpp:37
KSNumbers::earthPerihelionLongitude
dms earthPerihelionLongitude() const
Definition: ksnumbers.h:76
SkyPoint::HorizontalToEquatorial
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:102
KSNumbers::julianDay
long double julianDay() const
Definition: ksnumbers.h:93
SkyPoint::GalacticToEquatorial1950
void GalacticToEquatorial1950(const dms *galLong, const dms *galLat)
Computes equatorial coordinates referred to 1950 from galactic ones referred to epoch B1950...
Definition: skypoint.cpp:461
ksnumbers.h
SkyPoint::~SkyPoint
virtual ~SkyPoint()
Empty destructor.
Definition: skypoint.cpp:52
KSNumbers::obliquity
const dms * obliquity() const
Definition: ksnumbers.h:58
SkyPoint::setFromEcliptic
void setFromEcliptic(const dms *Obliquity, const dms &EcLong, const dms &EcLat)
Set the current (RA, Dec) coordinates of the SkyPoint, given pointers to its Ecliptic (Long...
Definition: skypoint.cpp:151
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
SkyPoint::addEterms
void addEterms(void)
Coordinates in the FK4 catalog include the effect of aberration due to the ellipticity of the orbit o...
Definition: skypoint.cpp:592
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
KSNumbers::dEcLong
double dEcLong() const
Definition: ksnumbers.h:87
dms::Hours
double Hours() const
Definition: dms.h:125
skypoint.h
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
Options::useRefraction
static bool useRefraction()
Get Correct positions for atmospheric refraction?
Definition: Options.h:2462
Options.h
SkyPoint::altRefracted
dms altRefracted() const
Definition: skypoint.cpp:754
SkyPoint::vGeoToVHelio
double vGeoToVHelio(double vgeo, long double jd)
Computes the radial velocity of a source referred to the solar system barycenter from the velocity re...
Definition: skypoint.cpp:724
SkyPoint::subtractEterms
void subtractEterms(void)
Coordinates in the FK4 catalog include the effect of aberration due to the ellipticity of the orbit o...
Definition: skypoint.cpp:600
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
kssun.h
SkyPoint::vHeliocentric
double vHeliocentric(double vlsr, long double jd)
Computes the radial velocity of a source referred to the solar system barycenter from the radial velo...
Definition: skypoint.cpp:673
KSNumbers::earthEccentricity
double earthEccentricity() const
Definition: ksnumbers.h:79
KSPlanetBase::rearth
double rearth() const
Definition: ksplanetbase.h:134
NaN::d
const double d
Definition: nan.h:35
SkyPoint::vGeocentric
double vGeocentric(double vhelio, long double jd)
Computes the radial velocity of a source referred to the center of the earth from the radial velocity...
Definition: skypoint.cpp:719
J2000
#define J2000
Definition: kstarsdatetime.h:21
PI
#define PI
Definition: satellite.cpp:43
SkyPoint::vREarth
double vREarth(long double jd0)
Computes the velocity of any object projected on the direction of the source.
Definition: skypoint.cpp:683
SkyPoint::precessFromAnyEpoch
void precessFromAnyEpoch(long double jd0, long double jdf)
General case of precession.
Definition: skypoint.cpp:356
SkyMapComposite::findByName
virtual SkyObject * findByName(const QString &name)
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument...
Definition: skymapcomposite.cpp:426
KSNumbers::constAberr
dms constAberr() const
Definition: ksnumbers.h:61
SkyPoint::unrefract
static double unrefract(const double alt)
Remove refraction correction.
Definition: skypoint.cpp:778
kstarsdatetime.h
SkyPoint::setRA
void setRA(dms r)
Sets RA, the current Right Ascension.
Definition: skypoint.h:119
SkyPoint::setDec
void setDec(dms d)
Sets Dec, the current Declination.
Definition: skypoint.h:130
kstarsdata.h
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
SkyPoint::lastPrecessJD
long double lastPrecessJD
Definition: skypoint.h:505
dms::setD
void setD(const double &x)
Sets floating-point value of angle, in degrees.
Definition: dms.h:130
SkyPoint::Equatorial1950ToGalactic
void Equatorial1950ToGalactic(dms &galLong, dms &galLat)
Computes galactic coordinates from equatorial coordinates referred to epoch 1950. ...
Definition: skypoint.cpp:442
SkyPoint::vTopoToVGeo
double vTopoToVGeo(double vtopo, double vsite[3])
Computes the radial velocity of a source referred to the center of the Earth from the radial velocity...
Definition: skypoint.cpp:740
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
SkyPoint::vTopocentric
double vTopocentric(double vgeo, double vsite[3])
Computes the radial velocity of a source referred to the observer site on the surface of the earth fr...
Definition: skypoint.cpp:745
KSNumbers::sunTrueLongitude
dms sunTrueLongitude() const
Definition: ksnumbers.h:73
SkyPoint::B1950ToJ2000
void B1950ToJ2000(void)
Exact precession from Besselian epoch 1950 to epoch J2000.
Definition: skypoint.cpp:480
SkyPoint::vRSun
double vRSun(long double jd)
Computes the velocity of the Sun projected on the direction of the source.
Definition: skypoint.cpp:634
SkyPoint::bendlight
bool bendlight()
Correct for the effect of "bending" of light around the sun for positions near the sun...
Definition: skypoint.cpp:272
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal