summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/skypoint.h
blob: 335c9557c9725da572aa9a986ddc59cf540aea1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/***************************************************************************
                          skypoint.h  -  K Desktop Planetarium
                             -------------------
    begin                : Sun Feb 11 2001
    copyright            : (C) 2001-2005 by Jason Harris
    email                : jharris@30doradus.org
    copyright            : (C) 2004-2005 by Pablo de Vicente
    email                : p.devicente@wanadoo.es
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SKYPOINT_H
#define SKYPOINT_H

#include <tqstring.h>
#include <tqptrlist.h>

#include "dms.h"

/**@class SkyPoint
	*
	*The sky coordinates of a point in the sky.  The
	*coordinates are stored in both Equatorial (Right Ascension,
	*Declination) andQt::Horizontal (Azimuth, Altitude) coordinate systems.
	*Provides set/get functions for each coordinate angle, and functions
	*to convert between the Equatorial and Horizon coordinate systems.
	*
	*Because the coordinate values change slowly over time (due to
	*precession, nutation), the "catalog coordinates" are stored
	*(RA0, Dec0), which were the true coordinates on Jan 1, 2000.
	*The true coordinates (RA, Dec) at any other epoch can be found
	*from the catalog coordinates using updateCoords().
	*@short Stores dms coordinates for a point in the sky.
	*for converting between coordinate systems.
	*@author Jason Harris
	*@version 1.0
	*/

class KSNumbers;
class CSegment;
class SkyObject;

class SkyPoint {
public:
/**Default constructor: Sets RA, Dec and RA0, Dec0 according
	*to arguments.  Does not set Altitude or Azimuth.
	*@param r Right Ascension
	*@param d Declination
	*/
	SkyPoint( const dms& r, const dms& d ) { set( r, d ); }

/**Alternate constructor using pointer arguments, for convenience.
	*It behaves essentially like the default constructor.
	*@param r Right Ascension pointer
	*@param d Declination pointer
	*/
	SkyPoint( const dms *r, const dms *d ) { set( dms(*r), dms(*d) ); }

/**Alternate constructor using double arguments, for convenience.
	*It behaves essentially like the default constructor.
	*@param r Right Ascension, expressed as a double
	*@param d Declination, expressed as a double
	*/
	SkyPoint( double r=0.0, double d=0.0 ) { set( r, d ); }

/**
	*Empty destructor.
	*/
	virtual ~SkyPoint();

////
//// 1.  Setting Coordinates
//// =======================

/**Sets RA, Dec and RA0, Dec0 according to arguments.
	*Does not set Altitude or Azimuth.
	*@param r Right Ascension
	*@param d Declination
	*/
	void set( const dms& r, const dms& d );

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param r Right Ascension
	*@param d Declination
	*/
	void set( const dms *r, const dms *d ) { set( *r, *d ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param r Right Ascension
	*@param d Declination
	*/
	void set( double r, double d );

/**Sets RA0, the catalog Right Ascension.
	*@param r catalog Right Ascension.
	*/
	void setRA0( dms r ) { RA0.set( r ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param r Right Ascension, expressed as a double.
	*/
	void setRA0( double r ) { RA0.setH( r ); }

/**Sets Dec0, the catalog Declination.
	*@param d catalog Declination.
	*/
	void setDec0( dms d ) { Dec0.set( d ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param d Declination, expressed as a double.
	*/
	void setDec0( double d ) { Dec0.setD( d ); }

/**Sets RA, the current Right Ascension.
	*@param r Right Ascension.
	*/
	void setRA( dms r ) { RA.set( r ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param r Right Ascension, expressed as a double.
	*/
	void setRA( double r ) { RA.setH( r ); }

/**Sets Dec, the current Declination
	*@param d Declination.
	*/
	void setDec( dms d ) { Dec.set( d ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param d Declination, expressed as a double.
	*/
	void setDec( double d ) { Dec.setD( d ); }

/**Sets Alt, the Altitude.
	*@param alt Altitude.
	*/
	void setAlt( dms alt ) { Alt.set( alt ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param alt Altitude, expressed as a double.
	*/
	void setAlt( double alt ) { Alt.setD( alt ); }

/**Sets Az, the Azimuth.
	*@param az Azimuth.
	*/
	void setAz( dms az ) { Az.set( az ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param az Azimuth, expressed as a double.
	*/
	void setAz( double az ) { Az.setD( az ); }

/**Sets Galactic Longitude.
	*@param glo Galactic Longitude.
	*/
//	void setGalLong( dms glo ) { galLong.set( glo ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param glo Galactic Longitude, expressed as a double.
	*/
//	void setGalLong( double glo ) { galLong.setD( glo ); }

/**Sets Galactic Longitude.
	*@param gla Galactic Longitude.
	*/
//	void setGalLat( dms gla ) { galLat.set( gla ); }

/**Overloaded member function, provided for convenience.
	*It behaves essentially like the above function.
	*@param gla Galactic Longitude, expressed as a double.
	*/
//	void setGalLat( double gla ) { galLat.setD( gla ); }

////
//// 2. Returning coordinates.
//// =========================

/**@return a pointer to the catalog Right Ascension.
	*/
	const dms* ra0() const { return &RA0; }

/**@return a pointer to the catalog Declination.
	*/
	const dms* dec0() const { return &Dec0; }

/**@returns a pointer to the current Right Ascension.
	*/
	const dms* ra() const { return &RA; }

/**@return a pointer to the current Declination.
	*/
	const dms* dec() const { return &Dec; }

/**@return a pointer to the current Azimuth.
	*/
	const dms* az() const { return &Az; }

/**@return a pointer to the current Altitude.
	*/
	const dms* alt() const { return &Alt; }

/**@return a pointer to the current galactic latitude.
	*/
//	const dms* gLat() const { return &galLat; }

/**@return a pointer to the current galactic longitude.
	*/
//	const dms* gLong() const { return &galLong; }

////
//// 3. Coordinate conversions.
//// ==========================

/**Determine the (Altitude, Azimuth) coordinates of the
	*SkyPoint from its (RA, Dec) coordinates, given the local
	*sidereal time and the observer's latitude.
	*@param LST pointer to the local sidereal time
	*@param lat pointer to the geographic latitude
	*/
	void EquatorialToHorizontal( 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.
	*@param LST pointer to the local sidereal time
	*@param lat pointer to the geographic latitude
	*/
	void HorizontalToEquatorial( const dms* LST, const dms* lat );

	/**@short Convert Right Ascension/Declination to Ecliptic logitude/latitude.
	*/
	void EquatorialToEcliptic( const KSNumbers *num );

	/**@short Convert Ecliptic logitude/latitude to Right Ascension/Declination.
	*/

	void EclipticToEquatorial( const KSNumbers *num );

/**Determine the Ecliptic coordinates of the SkyPoint, given the Julian Date.
	*The ecliptic coordinates are returned as reference arguments (since
	*they are not stored internally)
	*/
	void findEcliptic( const dms *Obliquity, dms &EcLong, dms &EcLat );

/**Set the current (RA, Dec) coordinates of the
	*SkyPoint, given pointers to its Ecliptic (Long, Lat) coordinates, and
	*to the current obliquity angle (the angle between the equator and ecliptic).
	*/
	void setFromEcliptic( const dms *Obliquity, const dms *EcLong, const dms *EcLat );

/** Computes galactic coordinates from equatorial coordinates referred to
	* epoch 1950. RA and Dec are, therefore assumed to be B1950
	* coordinates.
	*/
	void Equatorial1950ToGalactic(dms &galLong, dms &galLat);

/** Computes equatorial coordinates referred to 1950 from galactic ones referred to
	* epoch B1950. RA and Dec are, therefore assumed to be B1950
	* coordinates.
	*/
	void GalacticToEquatorial1950(const dms* galLong, const dms* galLat);

////
//// 4. Coordinate update/corrections.
//// =================================

/**Determine the current coordinates (RA, Dec) from the catalog
	*coordinates (RA0, Dec0), accounting for both precession and nutation.
	*@param num pointer to KSNumbers object containing current values of
	*time-dependent variables.
	*@param includePlanets does nothing in this implementation (see KSPlanetBase::updateCoords()).
	*@param lat does nothing in this implementation (see KSPlanetBase::updateCoords()).
	*@param LST does nothing in this implementation (see KSPlanetBase::updateCoords()).
	*/
	virtual void updateCoords( KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0 );

/**Computes the apparent coordinates for this SkyPoint for any epoch,
	*accounting for the effects of precession, nutation, and aberration.
	*Similar to updateCoords(), but the starting epoch need not be
	*J2000, and the target epoch need not be the present time.
	*@param jd0 Julian Day which identifies the original epoch
	*@param jdf Julian Day which identifies the final epoch
	*/
	void apparentCoord(long double jd0, long double jdf);

/**Determine the effects of nutation for this SkyPoint.
	*@param num pointer to KSNumbers object containing current values of
	*time-dependent variables.
	*/
	void nutate(const KSNumbers *num);

/**Determine the effects of aberration for this SkyPoint.
	*@param num pointer to KSNumbers object containing current values of
	*time-dependent variables.
	*/
	void aberrate(const KSNumbers *num);

/**General case of precession. It precess from an original epoch to a
	*final epoch. In this case RA0, and Dec0 from SkyPoint object represent
	*the coordinates for the original epoch and not for J2000, as usual.
	*@param jd0 Julian Day which identifies the original epoch
	*@param jdf Julian Day which identifies the final epoch
	*/
	void precessFromAnyEpoch(long double jd0, long double jdf);

	/** Determine the E-terms of aberration 
	 *In the past, the mean places of stars published in catalogs included
	 *the contribution to the aberration due to the ellipticity of the orbit
	 *of the Earth. These terms, known as E-terms were almost constant, and
	 *in the newer catalogs (FK5) are not included. Therefore to convert from
	 *FK4 to FK5 one has to compute these E-terms.
	 */
	SkyPoint Eterms(void);

	/** Exact precession from Besselian epoch 1950 to epoch J2000. The 
	*coordinates referred to the first epoch are in the 
	FK4 catalog, while the latter are in the Fk5 one.
	*Reference: Smith, C. A.; Kaplan, G. H.; Hughes, J. A.; Seidelmann,
	*P. K.; Yallop, B. D.; Hohenkerk, C. Y.
	*Astronomical Journal, vol. 97, Jan. 1989, p. 265-279
	*This transformation requires 4 steps:
	* - Correct E-terms
	* - Precess from B1950 to 1984, January 1st, 0h, using Newcomb expressions
	* - Add zero point correction in right ascension for 1984
	* - Precess from 1984, January 1st, 0h to J2000
	*/
	void B1950ToJ2000(void);

	/** Exact precession from epoch J2000 Besselian epoch 1950. The coordinates
	*referred to the first epoch are in the FK4 catalog, while the 
	*latter are in the Fk5 one.
	*Reference: Smith, C. A.; Kaplan, G. H.; Hughes, J. A.; Seidelmann,
	*P. K.; Yallop, B. D.; Hohenkerk, C. Y.
	*Astronomical Journal, vol. 97, Jan. 1989, p. 265-279
	*This transformation requires 4 steps:
	* - Precess from J2000 to 1984, January 1st, 0h
	* - Add zero point correction in right ascension for 1984
	* - Precess from 1984, January 1st, 0h, to B1950 using Newcomb expressions
	* - Correct E-terms
	*/
	void J2000ToB1950(void);

	/** Coordinates in the FK4 catalog include the effect of aberration due
	 *to the ellipticity of the orbit of the Earth. Coordinates in the FK5
	 *catalog do not include these terms. In order to convert from B1950 (FK4)
	 *to actual mean places one has to use this function.
	*/
	void addEterms(void);

	/** Coordinates in the FK4 catalog include the effect of aberration due
	 *to the ellipticity of the orbit of the Earth. Coordinates in the FK5 
	 *catalog do not include these terms. In order to convert from 
	 * FK5 coordinates to B1950 (FK4) one has to use this function. 
	*/
	void subtractEterms(void);

	/** Computes the angular distance between two SkyObjects. The algorithm
	 *  to compute this distance is:
	 *  cos(distance) = sin(d1)*sin(d2) + cos(d1)*cos(d2)*cos(a1-a2)
	 *  where a1,d1 are the coordinates of the first object and a2,d2 are
	 *  the coordinates of the second object.
	 *  However this algorithm is not accurate when the angular separation
	 *  is small.
	 *  Meeus provides a different algorithm in page 111 which we 
	 *  implement here.
	 *  @param sp SkyPoint to which distance is to be calculated
	 *  @return dms angle representing angular separation.
	 **/

	dms angularDistanceTo( SkyPoint *sp);

	bool operator == ( SkyPoint &p ) { return ( ra()->Degrees() == p.ra()->Degrees() && dec()->Degrees() == p.dec()->Degrees() ); }
	
	/** Computes the velocity of the Sun projected on the direction of the source.
	 *
	 * @param jd Epoch expressed as julian day to which the source coordinates refer to.
	 * @return Radial velocity of the source referred to the barycenter of the solar system in km/s
	 **/
	double vRSun(long double jd);

	/** Computes the radial velocity of a source referred to the solar system barycenter 
	 * from the radial velocity referred to the
	 * Local Standard of Rest, aka known as VLSR. To compute it we need the coordinates of the
	 * source the VLSR and the epoch for the source coordinates.
	 *
	 * @param vlsr radial velocity of the source referred to the LSR in km/s
	 * @param jd Epoch expressed as julian day to which the source coordinates refer to.
	 * @return Radial velocity of the source referred to the barycenter of the solar system in km/s
	 **/
	double vHeliocentric(double vlsr, long double jd);

	/** Computes the radial velocity of a source referred to the Local Standard of Rest, also known as VLSR
	 * from the radial velocity referred to the solar system barycenter 
	 *
	 * @param vhelio radial velocity of the source referred to the LSR in km/s
	 * @param jd Epoch expressed as julian day to which the source coordinates refer to.
	 * @return Radial velocity of the source referred to the barycenter of the solar system in km/s
	 **/
	double vHelioToVlsr(double vhelio, long double jd);

	/** Computes the velocity of any object projected on the direction of the source.
	 *  @param jd0 Julian day for which we compute the direction of the source
	 *  @return velocity of the Earth projected on the direction of the source kms-1
	 */
	double vREarth(long double jd0);
	
	/** Computes the radial velocity of a source referred to the center of the earth 
	 * from the radial velocity referred to the solar system barycenter
	 *
	 * @param vhelio radial velocity of the source referred to the barycenter of the 
	 *               solar system in km/s
	 * @param jd     Epoch expressed as julian day to which the source coordinates refer to.
	 * @return Radial velocity of the source referred to the center of the Earth in km/s
	 **/
	double vGeocentric(double vhelio, long double jd);

	/** Computes the radial velocity of a source referred to the solar system barycenter 
	 * from the velocity referred to the center of the earth 
	 *
	 * @param vgeo   radial velocity of the source referred to the center of the Earth
	 *               [km/s]
	 * @param jd     Epoch expressed as julian day to which the source coordinates refer to.
	 * @return Radial velocity of the source referred to the solar system barycenter in km/s
	 **/
	double vGeoToVHelio(double vgeo, long double jd);

	/** Computes the velocity of any object (oberver's site) projected on the 
	 * direction of the source.
	 *  @param vsite velocity of that object in cartesian coordinates
	 *  @return velocity of the object projected on the direction of the source kms-1
	 */
	double vRSite(double vsite[3]);

	/** Computes the radial velocity of a source referred to the observer site on the surface
	 * of the earth from the geocentric velovity and the velocity of the site referred to the center
	 * of the Earth.
	 *
	 * @param vgeo radial velocity of the source referred to the center of the earth in km/s
	 * @param vsite Velocity at which the observer moves referred to the center of the earth.
	 * @return Radial velocity of the source referred to the observer's site in km/s
	 **/
	double vTopocentric(double vgeo, double vsite[3]);

	/** Computes the radial velocity of a source referred to the center of the Earth from 
	 * the radial velocity referred to an observer site on the surface of the earth 
	 * 
	 * @param vtopo radial velocity of the source referred to the observer's site in km/s
	 * @param vsite Velocity at which the observer moves referred to the center of the earth.
	 * @return Radial velocity of the source referred the center of the earth in km/s
	 **/
	double vTopoToVGeo(double vtopo, double vsite[3]);

////
//// 5. Calculating Rise/Set/Transit data.
//// =====================================

//// To Be Moved from SkyObject....

////
//// 6. Constellation Identification
//// =====================================

	TQString constellation( TQPtrList<CSegment> &seglist, TQPtrList<SkyObject> &cnames ) const;


protected:
/**Precess this SkyPoint's catalog coordinates to the epoch described by the
	*given KSNumbers object.
	*@param num pointer to a KSNumbers object describing the target epoch.
	*/
	void precess(const KSNumbers *num);


private:
	dms RA0, Dec0; //catalog coordinates
	dms RA, Dec; //current true sky coordinates
	dms Alt, Az;
};

#endif