• 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
ksnumbers.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksnumbers.cpp - description
3  -------------------
4  begin : Sun Jan 13 2002
5  copyright : (C) 2002-2005 by Jason Harris
6  email : kstars@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 "ksnumbers.h"
21 #include "kstarsdatetime.h" //for J2000 define
22 
23 // 63 elements
24 const int KSNumbers::arguments[NUTTERMS][5] = {
25  { 0, 0, 0, 0, 1},
26  {-2, 0, 0, 2, 2},
27  { 0, 0, 0, 2, 2},
28  { 0, 0, 0, 0, 2},
29  { 0, 1, 0, 0, 0},
30  { 0, 0, 1, 0, 0},
31  {-2, 1, 0, 2, 2},
32  { 0, 0, 0, 2, 1},
33  { 0, 0, 1, 2, 2},
34  {-2,-1, 0, 2, 2},
35  {-2, 0, 1, 0, 0},
36  {-2, 0, 0, 2, 1},
37  { 0, 0,-1, 2, 2},
38  { 2, 0, 0, 0, 0},
39  { 0, 0, 1, 0, 1},
40  { 2, 0,-1, 2, 2},
41  { 0, 0,-1, 0, 1},
42  { 0, 0, 1, 2, 1},
43  {-2, 0, 2, 0, 0},
44  { 0, 0,-2, 2, 1},
45  { 2, 0, 0, 2, 2},
46  { 0, 0, 2, 2, 2},
47  { 0, 0, 2, 0, 0},
48  {-2, 0, 1, 2, 2},
49  { 0, 0, 0, 2, 0},
50  {-2, 0, 0, 2, 0},
51  { 0, 0,-1, 2, 1},
52  { 0, 2, 0, 0, 0},
53  { 2, 0,-1, 0, 1},
54  {-2, 2, 0, 2, 2},
55  { 0, 1, 0, 0, 1},
56  {-2, 0, 1, 0, 1},
57  { 0,-1, 0, 0, 1},
58  { 0, 0, 2,-2, 0},
59  { 2, 0,-1, 2, 1},
60  { 2, 0, 1, 2, 2},
61  { 0, 1, 0, 2, 2},
62  {-2, 1, 1, 0, 0},
63  { 0,-1, 0, 2, 2},
64  { 2, 0, 0, 2, 1},
65  { 2, 0, 1, 0, 0},
66  {-2, 0, 2, 2, 2},
67  {-2, 0, 1, 2, 1},
68  { 2, 0,-2, 0, 1},
69  { 2, 0, 0, 0, 1},
70  { 0,-1, 1, 0, 0},
71  {-2,-1, 0, 2, 1},
72  {-2, 0, 0, 0, 1},
73  { 0, 0, 2, 2, 1},
74  {-2, 0, 2, 0, 1},
75  {-2, 1, 0, 2, 1},
76  { 0, 0, 1,-2, 0},
77  {-1, 0, 1, 0, 0},
78  {-2, 1, 0, 0, 0},
79  { 1, 0, 0, 0, 0},
80  { 0, 0, 1, 2, 0},
81  { 0, 0,-2, 2, 2},
82  {-1,-1, 1, 0, 0},
83  { 0, 1, 1, 0, 0},
84  { 0,-1, 1, 2, 2},
85  { 2,-1,-1, 2, 2},
86  { 0, 0, 3, 2, 2},
87  { 2,-1, 0, 2, 2}
88  };
89 
90 const int KSNumbers::amp[NUTTERMS][4] = {
91  {-171996,-1742, 92025, 89},
92  { -13187, -16, 5736,-31},
93  { -2274, -2, 977, -5},
94  { 2062, 2, -895, 5},
95  { 1426, -34, 54, -1},
96  { 712, 1, -7, 0},
97  { -517, 12, 224, -6},
98  { -386, -4, 200, 0},
99  { -301, 0, 129, -1},
100  { 217, -5, -95, 3},
101  { -158, 0, 0, 0},
102  { 129, 1, -70, 0},
103  { 123, 0, -53, 0},
104  { 63, 0, 0, 0},
105  { 63, 1, -33, 0},
106  { -59, 0, 26, 0},
107  { -58, -1, 32, 0},
108  { -51, 0, 27, 0},
109  { 48, 0, 0, 0},
110  { 46, 0, -24, 0},
111  { -38, 0, 16, 0},
112  { -31, 0, 13, 0},
113  { 29, 0, 0, 0},
114  { 29, 0, -12, 0},
115  { 26, 0, 0, 0},
116  { -22, 0, 0, 0},
117  { 21, 0, -10, 0},
118  { 17, -1, 0, 0},
119  { 16, 0, -8, 0},
120  { -16, 1, 7, 0},
121  { -15, 0, 9, 0},
122  { -13, 0, 7, 0},
123  { -12, 0, 6, 0},
124  { 11, 0, 0, 0},
125  { -10, 0, 5, 0},
126  { -8, 0, 3, 0},
127  { 7, 0, -3, 0},
128  { -7, 0, 0, 0},
129  { -7, 0, 3, 0},
130  { -7, 0, 3, 0},
131  { 6, 0, 0, 0},
132  { 6, 0, -3, 0},
133  { 6, 0, -3, 0},
134  { -6, 0, 3, 0},
135  { -6, 0, 3, 0},
136  { 5, 0, 0, 0},
137  { -5, 0, 3, 0},
138  { -5, 0, 3, 0},
139  { -5, 0, 3, 0},
140  { 4, 0, 0, 0},
141  { 4, 0, 0, 0},
142  { 4, 0, 0, 0},
143  { -4, 0, 0, 0},
144  { -4, 0, 0, 0},
145  { -4, 0, 0, 0},
146  { 3, 0, 0, 0},
147  { -3, 0, 0, 0},
148  { -3, 0, 0, 0},
149  { -3, 0, 0, 0},
150  { -3, 0, 0, 0},
151  { -3, 0, 0, 0},
152  { -3, 0, 0, 0},
153  { -3, 0, 0, 0}
154  };
155 
156 
157 KSNumbers::KSNumbers( long double jd ){
158  K.setD( 20.49552 / 3600. ); //set the constant of aberration
159  P.setD( 102.94719 ); // ecliptic longitude of earth's perihelion, source: http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html; FIXME: We should correct this, as it changes with time. See the commit log for an order of magnitude estimate of the error.
160  computeConstantValues();
161  updateValues( jd );
162 }
163 
164 void KSNumbers::computeConstantValues() {
165 
166  // Compute those nubmers that need to be computed only
167  // once.
168  //
169  // Ideally, these should be computed at compile-time. When we
170  // upgrade to C++11, we can make this function static and
171  // constexpr (maybe?) But even otherwise, the overhead is very
172  // negligible.
173 
174  //Compute Precession Matrices from B1950 to 1984 using Newcomb formulae
175  XB.setD( 0.217697 );
176  YB.setD( 0.189274 );
177  ZB.setD( 0.217722 );
178 
179  XB.SinCos( SXB, CXB );
180  YB.SinCos( SYB, CYB );
181  ZB.SinCos( SZB, CZB );
182 
183  //P1B is used to precess from 1984 to B1950:
184 
185  P1B[0][0] = CXB*CYB*CZB - SXB*SZB;
186  P1B[1][0] = CXB*CYB*SZB + SXB*CZB;
187  P1B[2][0] = CXB*SYB;
188  P1B[0][1] = -1.0*SXB*CYB*CZB - CXB*SZB;
189  P1B[1][1] = -1.0*SXB*CYB*SZB + CXB*CZB;
190  P1B[2][1] = -1.0*SXB*SYB;
191  P1B[0][2] = -1.0*SYB*CZB;
192  P1B[1][2] = -1.0*SYB*SZB;
193  P1B[2][2] = CYB;
194 
195  //P2 is used to precess from B1950 to 1984 (it is the transpose of P1)
196  // FIXME: This can be optimized by taking the transpose of P1 instead of recomputing it from scratch
197  P2B[0][0] = CXB*CYB*CZB - SXB*SZB;
198  P2B[1][0] = -1.0*SXB*CYB*CZB - CXB*SZB;
199  P2B[2][0] = -1.0*SYB*CZB;
200  P2B[0][1] = CXB*CYB*SZB + SXB*CZB;
201  P2B[1][1] = -1.0*SXB*CYB*SZB + CXB*CZB;
202  P2B[2][1] = -1.0*SYB*SZB;
203  P2B[0][2] = CXB*SYB;
204  P2B[1][2] = -1.0*SXB*SYB;
205  P2B[2][2] = CYB;
206 }
207 
208 KSNumbers::~KSNumbers(){
209 }
210 
211 void KSNumbers::updateValues( long double jd ) {
212  dms arg;
213  double args, argc;
214 
215  days = jd;
216 
217  //Julian Centuries since J2000.0
218  T = ( jd - J2000 ) / 36525.;
219 
220  // Julian Millenia since J2000.0
221  jm = T / 10.0;
222 
223  double T2 = T*T;
224  double T3 = T2*T;
225 
226  //Sun's Mean Longitude
227  L.setD( 280.46645 + 36000.76983*T + 0.0003032*T2 );
228 
229  //Mean elongation of the Moon from the Sun
230  D.setD( 297.85036 + 445267.111480*T - 0.0019142*T2 + T3/189474.);
231 
232  //Sun's Mean Anomaly
233  M.setD( 357.52910 + 35999.05030*T - 0.0001559*T2 - 0.00000048*T3);
234 
235  //Moon's Mean Anomaly
236  MM.setD( 134.96298 + 477198.867398*T + 0.0086972*T2 + T3/56250.0 );
237 
238  //Moon's Mean Longitude
239  LM.setD( 218.3164591 + 481267.88134236*T - 0.0013268*T2 + T3/538841. - T*T*T*T/6519400.);
240 
241  //Moon's argument of latitude
242  F.setD( 93.27191 + 483202.017538*T - 0.0036825*T2 + T3/327270.);
243 
244  //Longitude of Moon's Ascending Node
245  O.setD( 125.04452 - 1934.136261*T + 0.0020708*T2 + T3/450000.0 );
246 
247  //Earth's orbital eccentricity
248  e = 0.016708617 - 0.000042037*T - 0.0000001236*T2;
249 
250  double C = ( 1.914600 - 0.004817*T - 0.000014*T2 ) * sin( M.radians() )
251  + ( 0.019993 - 0.000101*T ) * sin( 2.0* M.radians() )
252  + 0.000290 * sin( 3.0* M.radians() );
253 
254  //Sun's True Longitude
255  L0.setD( L.Degrees() + C );
256 
257  //Sun's True Anomaly
258  M0.setD( M.Degrees() + C );
259 
260  //Obliquity of the Ecliptic
261  // FIXME: This can be optimized by using the fact that U^3 = U^2 * U, so we can reduce the number of multiplications
262  double U = T/100.0;
263  double dObliq = -4680.93*U - 1.55*U*U + 1999.25*U*U*U
264  - 51.38*U*U*U*U - 249.67*U*U*U*U*U
265  - 39.05*U*U*U*U*U*U + 7.12*U*U*U*U*U*U*U
266  + 27.87*U*U*U*U*U*U*U*U + 5.79*U*U*U*U*U*U*U*U*U
267  + 2.45*U*U*U*U*U*U*U*U*U*U;
268  Obliquity.setD( 23.43929111 + dObliq/3600.0);
269 
270  //Nutation parameters
271  dms L2, M2, O2;
272  double sin2L, cos2L, sin2M, cos2M;
273  double sinO, cosO, sin2O, cos2O;
274 
275  O2.setD( 2.0*O.Degrees() );
276  L2.setD( 2.0*L.Degrees() ); //twice mean ecl. long. of Sun
277  M2.setD( 2.0*LM.Degrees() ); //twice mean ecl. long. of Moon
278 
279  O.SinCos( sinO, cosO );
280  O2.SinCos( sin2O, cos2O );
281  L2.SinCos( sin2L, cos2L );
282  M2.SinCos( sin2M, cos2M );
283 
284  // deltaEcLong = ( -17.2*sinO - 1.32*sin2L - 0.23*sin2M + 0.21*sin2O)/3600.0; //Ecl. long. correction
285  // deltaObliquity = ( 9.2*cosO + 0.57*cos2L + 0.10*cos2M - 0.09*cos2O)/3600.0; //Obliq. correction
286 
287  deltaEcLong = 0.;
288  deltaObliquity = 0.;
289 
290  for (unsigned int i=0; i < NUTTERMS; i++) {
291 
292  arg.setD ( arguments[i][0]*D.Degrees() + arguments[i][1]*M.Degrees() +
293  arguments[i][2]*MM.Degrees() + arguments[i][3]*F.Degrees() + arguments[i][4]*O.Degrees() );
294  arg.SinCos( args, argc );
295 
296  deltaEcLong += (amp[i][0] + amp[i][1]/10. * T ) * args * 1e-4 ;
297  deltaObliquity += (amp[i][2] + amp[i][3]/10. * T ) * argc * 1e-4 ;
298  }
299 
300  deltaEcLong/= 3600.0;
301  deltaObliquity /= 3600.0;
302 
303  //Compute Precession Matrices:
304  XP.setD( 0.6406161*T + 0.0000839*T2 + 0.0000050*T3 );
305  YP.setD( 0.5567530*T - 0.0001185*T2 - 0.0000116*T3 );
306  ZP.setD( 0.6406161*T + 0.0003041*T2 + 0.0000051*T3 );
307 
308  XP.SinCos( SX, CX );
309  YP.SinCos( SY, CY );
310  ZP.SinCos( SZ, CZ );
311 
312  //P1 is used to precess from any epoch to J2000
313  // FIXME: Is this a rotation matrix? If so, quaternions might be more efficient
314  // A: Yes, it has to be, because the inverse is the transpose, so the matrix is orthogonal 3x3
315  P1[0][0] = CX*CY*CZ - SX*SZ;
316  P1[1][0] = CX*CY*SZ + SX*CZ;
317  P1[2][0] = CX*SY;
318  P1[0][1] = -1.0*SX*CY*CZ - CX*SZ;
319  P1[1][1] = -1.0*SX*CY*SZ + CX*CZ;
320  P1[2][1] = -1.0*SX*SY;
321  P1[0][2] = -1.0*SY*CZ;
322  P1[1][2] = -1.0*SY*SZ;
323  P1[2][2] = CY;
324 
325  //P2 is used to precess from J2000 to any other epoch (it is the transpose of P1)
326  // FIXME: More optimization -- just use P1[j][i] instead of P2[i][j] in code
327  P2[0][0] = P1[0][0];
328  P2[1][0] = P1[0][1];
329  P2[2][0] = P1[0][2];
330  P2[0][1] = P1[1][0];
331  P2[1][1] = P1[1][1];
332  P2[2][1] = P1[1][2];
333  P2[0][2] = P1[2][0];
334  P2[1][2] = P1[2][1];
335  P2[2][2] = P1[2][2];
336 
337  // Mean longitudes for the planets. radians
338  //
339 
340  // TODO Pasar a grados [Google Translate says "Jump to Degrees". --asimha]
341  double LVenus = 3.1761467+1021.3285546*T; // Venus
342  double LMars = 1.7534703+ 628.3075849*T; // Mars
343  double LEarth = 6.2034809+ 334.0612431*T; // Earth
344  double LJupiter = 0.5995465+ 52.9690965*T; // Jupiter
345  double LSaturn = 0.8740168+ 21.3299095*T; // Saturn
346  double LNeptune = 5.3118863+ 3.8133036*T; // Neptune
347  double LUranus = 5.4812939+ 7.4781599*T; // Uranus
348 
349  double LMRad = 3.8103444+8399.6847337*T; // Moon
350  double DRad = 5.1984667+7771.3771486*T;
351  double MMRad = 2.3555559+8328.6914289*T; // Moon
352  double FRad = 1.6279052+8433.4661601*T;
353 
360  double vondrak[36][7] = {
361  {LMars, -1719914-2*T, -25, 25-13*T,1578089+156*T, 10+32*T,684185-358*T},
362  {2*LMars, 6434+141*T,28007-107*T,25697-95*T, -5904-130*T,11141-48*T, -2559-55*T},
363  {LJupiter, 715, 0, 6, -657, -15, -282},
364  {LMRad, 715, 0, 0, -656, 0, -285},
365  {3*LMars, 486-5*T, -236-4*T, -216-4*T, -446+5*T, -94, -193},
366  {LSaturn, 159, 0, 2, -147, -6, -61},
367  {FRad, 0, 0, 0, 26, 0, -59},
368  {LMRad+MMRad, 39, 0, 0, -36, 0, -16},
369  {2*LJupiter, 33, -10, -9, -30, -5, -13},
370  {2*LMars-LJupiter, 31, 1, 1, -28, 0, -12},
371  {3*LMars-8*LEarth+3*LJupiter, 8, -28, 25, 8, 11, 3},
372  {5*LMars-8*LEarth+3*LJupiter, 8, -28, -25, -8, -11, -3},
373  {2*LVenus-LMars, 21, 0, 0, -19, 0, -8},
374  {LVenus, -19, 0, 0, 17, 0, 8},
375  {LNeptune, 17, 0, 0, -16, 0, -7},
376  {LMars-2*LJupiter, 16, 0, 0, 15, 1, 7},
377  {LUranus, 16, 0, 1, -15, -3, -6},
378  {LMars+LJupiter, 11, -1, -1, -10, -1, -5},
379  {2*LVenus-2*LMars, 0, -11, -10, 0, -4, 0},
380  {LMars-LJupiter, -11, -2, -2, 9, -1, 4},
381  {4*LMars, -7, -8, -8, 6, -3, 3},
382  {3*LMars-2*LJupiter, -10, 0, 0, 9, 0, 4},
383  {LVenus-2*LMars, -9, 0, 0, -9, 0, -4},
384  {2*LVenus-3*LMars, -9, 0, 0, -8, 0, -4},
385  {2*LSaturn, 0, -9, -8, 0, -3, 0},
386  {2*LVenus-4*LMars, 0, -9, 8, 0, 3, 0},
387  {3*LMars-2*LEarth, 8, 0, 0, -8, 0, -3},
388  {LMRad+2*DRad-MMRad, 8, 0, 0, -7, 0, -3},
389  {8*LVenus-12*LMars, -4, -7, -6, 4, -3, 2},
390  {8*LVenus-14*LMars, -4, -7, 6, -4, 3, -2},
391  {2*LEarth, -6, -5, -4, 5, -2, 2},
392  {3*LVenus-4*LMars, -1, -1, -2, -7, 1, -4},
393  {2*LMars-2*LJupiter, 4, -6, -5, -4, -2, -2},
394  {3*LVenus-3*LMars, 0, -7, -6, 0, -3, 0},
395  {2*LMars-2*LEarth, 5, -5, -4, -5, -2, -2},
396  {LMRad-2*DRad, 5, 0, 0, -5, 0, -2}
397  };
398 
399  dms anglev;
400  double sa, ca;
401  // Vearth X component
402  vearth[0] = 0.;
403  // Vearth Y component
404  vearth[1] = 0.;
405  // Vearth Z component
406  vearth[2] = 0.;
407 
408  for (unsigned int i=0; i<36; i++) {
409  anglev.setRadians(vondrak[i][0]);
410  anglev.SinCos(sa,ca);
411  for (unsigned int j=0; j<3; j++) {
412  vearth[j] += vondrak[i][2*j+1]*sa +vondrak[i][2*j+2]*ca;
413  }
414  }
415 
416  const double UA2km = 1.49597870/86400.; // 10^{-8}*UA/dia -> km/s
417 
418  for (unsigned int j=0; j<3; j++) {
419  vearth[j] = vearth[j] * UA2km;
420  }
421 }
NUTTERMS
#define NUTTERMS
Definition: ksnumbers.h:23
KSNumbers::updateValues
void updateValues(long double jd)
update all values for the date given as an argument.
Definition: ksnumbers.cpp:211
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
KSNumbers::KSNumbers
KSNumbers(long double jd)
Constructor.
Definition: ksnumbers.cpp:157
KSNumbers::computeConstantValues
void computeConstantValues()
compute constant values that need to be computed only once per instance of the application ...
Definition: ksnumbers.cpp:164
KSNumbers::dObliq
double dObliq() const
Definition: ksnumbers.h:83
KSNumbers::~KSNumbers
~KSNumbers()
Destructor (empty).
Definition: ksnumbers.cpp:208
ksnumbers.h
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
J2000
#define J2000
Definition: kstarsdatetime.h:21
kstarsdatetime.h
dms::setD
void setD(const double &x)
Sets floating-point value of angle, in degrees.
Definition: dms.h:130
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 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