45 double PlanetarySats::atan23 (
double y,
double x)
50 if ((x == 0) && (y == 0)) result = 0;
51 else result = atan2 (y, x);
56 void PlanetarySats::plsatinit()
72 strcpy (pls_satelmfl,
"./planetarysats.txt");
83 jd = 40587.0 + tt/86400.0;
85 jd = jd + pls_delta_rt / 24.0;
86 caldat(jd, hh, mm, ss, hr);
95 if (pls_del_auto) pls_del_tdut =
DefTdUt(pls_year);
96 setMJD(pls_year, pls_month, pls_day, hh, mm, jd);
102 if (s < 0.01) pls_step = 0.01;
117 pls_del_tdut = d + 32.184;
125 pls_del_tdut =
DefTdUt(pls_year);
140 jd =
ddd(hour, min, sec);
141 jd =
mjd(day, month, year, jd);
145 if (pls_del_auto) pls_del_tdut =
DefTdUt(pls_year);
155 caldat((mjd), day, month, year, magn);
156 dms (magn,hour,min,sec);
157 if (sec>30.0) min++;;
167 strcpy (pls_satelmfl, fname);
186 getDatefromMJD(mjd, year, month, day, hour, min, sec);
187 setMJD(year, month, day, hour, min, sec);
188 pls_tepoch = pls_time;
198 int fsc, j, k, nst, utc;
199 int yr, month, day, hour, min;
207 strcpy(plntname,
"");
213 cfle.open(pls_satelmfl, ios::in);
225 if (!cfle.getline(satname,40)) fsc = 0;
229 if ((k>1) && (satname[0] ==
'#'))
233 pls_satname[j-1] = satname[j];
234 if(pls_satname[j-1] ==
'\n') pls_satname[j-1] =
'\0';
236 pls_satname[k-1] =
'\0';
249 if (!cfle.getline(plntname, 40)) fsc = 0;
252 k = strlen(plntname);
255 if(plntname[k-1] ==
'\n') plntname[k-1] =
'\0';
256 if((k>1) && (plntname[k-2] ==
'\r')) plntname[k-2] =
'\0';
263 cfle >> yr >> month >> day >> hour >> min >> sec >> utc;
264 if (cfle.bad()) fsc = 0;
274 cfle >> pls_rep[0] >> pls_rep[1] >> pls_rep[2];
275 if (cfle.bad()) fsc = 0;
285 cfle >> pls_vep[0] >> pls_vep[1] >> pls_vep[2];
286 if (cfle.bad()) fsc = 0;
291 if (strncmp(pls_plntname, plntname, 4) == 0) nst++;
296 setMJD(yr, month, day, hour, min, sec);
297 pls_tepoch = pls_time;
298 if (utc) pls_tepoch = pls_tepoch + pls_del_tdut/86400.0;
305 if (fsc == 0) nst = 0;
313 strcpy(pls_plntname, pname);
314 if (strncmp(
"Mars", pname, 4) == 0) getMars();
315 if (strncmp(
"Venus", pname, 4) == 0) getVenus();
316 if (strncmp(
"Mercury", pname, 4) == 0) getMercury();
317 if (strncmp(
"Moon", pname, 4) == 0) getMoon();
324 double t, dt, ag, gm, re, j2;
325 double n, c, w, a, ecc, inc;
329 dt = (pls_tepoch - 51544.5) / 36525.0;
330 gm = pls_GM * 7.4649600000;
338 r1 =
mxvct (mx, pls_rep);
339 v1 =
mxvct (mx, pls_vep);
344 ag = (pls_axl0 + pls_axl1 * dt) *
M_PI / 180.0;
346 r1 =
mxvct (mx, pls_rep);
347 v1 =
mxvct (mx, pls_vep);
349 ag = (pls_axb0 + pls_axb1 * dt) *
M_PI / 180.0;
357 oscelm(gm, pls_tepoch, r1, v1, t, pls_m0, pls_a, pls_ecc, pls_ra, pls_per, pls_inc);
367 n = sqrt (gm / (a*a*a));
374 c = sin (inc*
M_PI/180.0);
375 n = n*(1.0 + 1.5*j2*re*re/(a*a) * w * (1.0 - 1.5*c*c));
380 if (n > 1000.0) n = 1000.0;
397 gm = pls_GM * 7.4649600000;
399 mx = getSelenographic(pls_tepoch);
400 r1 =
mxvct (mx, pls_rep);
401 v1 =
mxvct (mx, pls_vep);
404 oscelm(gm, pls_tepoch, r1, v1, t, m0, a, ecc, ra, tano, inc);
409 n0 = sqrt (gm / (a*a*a));
410 n0 = n0 / (2.0*
M_PI);
423 perc = pls_a * (1.0 - pls_ecc) - pls_R0;
424 apoc = pls_a * (1.0 + pls_ecc) - pls_R0;
442 res = getStateVector(nst);
445 if (strncmp(pls_satname, sname, sl) == 0) searching =
false;
447 else searching =
false;
456 strcpy (sname, pls_satname);
466 pls_time = pls_time + pls_step / 86400.0;
497 void PlanetarySats::getSatPos (
double tutc)
501 const double mp2 = 2.0*
M_PI;
503 double t, dt, m0, ran, aper, inc, a, ecc, n0, re;
504 double f, e, c, s, k, sh, j2, gm, fac, b1, b2, b3;
507 Vec3 r1, v1, rg1, s2;
512 t = tutc + pls_del_tdut/86400.0;
516 if (ecc >= 1.0) ecc = 0.999;
519 if (a < 1.0) a = 1.0;
523 gm = pls_GM * 7.4649600000;
526 aper = (re / a) / (1.0 - ecc*ecc);
527 aper = 1.5 * j2 * aper*aper * n0;
528 m0 = pls_inc*
M_PI/180.0;
529 ran = -aper * cos(m0) * dt;
531 aper = aper * (2.0 - 2.5*m0*m0) * dt;
532 ran = pls_ra *
M_PI/180.0 + ran;
533 aper = pls_per *
M_PI/180.0 + aper;
534 m0 = pls_m0*
M_PI/180.0 + n0*dt;
535 inc = pls_inc *
M_PI/180.0;
538 if (a < 1.0) a = 1.0;
540 fac = sqrt(1.0 - ecc*ecc);
543 r1.
assign (a*(c - ecc), a*fac*s, 0.0);
547 v1.
assign (-k*s/m0, k*fac*c/m0, 0.0);
561 if (pls_moonflg) m1 = getSelenographic(t);
562 else m1 =
zrot((pls_W + pls_Wd*(t-51544.5))*(
M_PI/180.0));
563 pls_r =
mxvct(m1,r1);
564 pls_v =
mxvct(m1,v1);
575 if (pls_lng > mp2) pls_lng -= mp2;
576 if (pls_lng < -
M_PI) pls_lng += mp2;
577 if (pls_lng >
M_PI) pls_lng -= mp2;
582 if (f == 0) pls_height =
abs(r1) - re;
586 s = r1[0]*r1[0] + r1[1]*r1[1];
593 if (b3 < 1e-5) b3 = sin(pls_lat);
595 b2 = re / sqrt(1.0 - c*b3*b3);
600 pls_lat =
atan20(sh,sqrt(s));
601 sh = sqrt(s+sh*sh) - b2;
607 pls_lat = pls_lat * 180.0 /
M_PI;
608 pls_lng = pls_lng * 180.0 /
M_PI;
613 void PlanetarySats::getMars()
617 pls_flat = 0.00647630;
623 pls_Wd = 350.8919830;
624 pls_GM = 4.282828596416e+13;
627 void PlanetarySats::getVenus()
638 pls_GM = 3.24858761e+14;
641 void PlanetarySats::getMercury()
652 pls_GM = 2.20320802e+13;
655 void PlanetarySats::getMoon()
666 pls_Wd = 13.17635898;
667 pls_GM = 4.90279412e+12;
670 Mat3 PlanetarySats::getSelenographic (
double jd)
675 double t, gam, gmp, l, omg, mln;
676 double a, b, c, ic, gn, gp, omp;
680 t = (jd - 15019.5) / 36525.0;
681 gam = 281.2208333 + ((0.33333333e-5*t + 0.45277778e-3)*t + 1.7191750)*t;
682 gmp = 334.3295556 + ((-0.125e-4*t - 0.10325e-1)*t + 4069.0340333)*t;
683 l = 279.6966778 + (0.3025e-3*t + 36000.768925)*t;
684 omg = 259.1832750 + ((0.22222222e-5*t + 0.20777778e-2)*t - 1934.1420083)*t;
685 b = 23.45229444 + ((0.50277778e-6*t -0.16388889e-5)*t - 0.130125e-1)*t;
686 mln = 270.4341639 + ((0.1888889e-5*t -0.11333e-2)*t + 481267.8831417)*t;
688 gn = (l - gam)*degrad;
689 gp = (mln - gmp)*degrad;
690 omp = (gmp - omg)*degrad;
691 a = -107.0*cos(gp) + 37.0*cos(gp+2.0*omp) -11.0*cos(2.0*(gp+omp));
692 a = a*0.000277778*degrad + ic;
693 c = (-109.0*sin(gp) + 37.0*sin(gp+2.0*omp) - 11.0*sin(2.0*(gp+omp)))/sin(ic);
694 c = (c*0.000277778 + omg)*degrad;
695 gn = -12.0*sin(gp) + 59.0*sin(gn) + 18.0*sin(2.0*omp);
696 gn = gn*0.000277778*
degrad;
699 gam = cos(a)*cos(b) + sin(a)*sin(b)*cos(c);
701 if(gmp > 1.0) gmp = 0;
702 else gmp = sqrt(1.0 - gmp);
703 gam = atan23(gmp,gam);
704 t = cos(a)*sin(b) - sin(a)*sin(b)*cos(c);
708 t = sin(a)*cos(b) - cos(a)*sin(b)*cos(c);
711 c = a + mln*degrad + gn - c;
static void getDatefromMJD(double mjd, int &year, int &month, int &day, int &hour, int &min, double &sec)
void setMJD(int year, int month, int day, int hour, int min, double sec)
double atan20(double y, double x)
double getLastMJD() const
double ddd(int d, int m, double s)
void setSatFile(char *fname)
Vec3 carpol(const Vec3 &c)
void setDeltaRT(double drt)
Mat3 pmatequ(double t1, double t2)
void oscelm(double gm, double t, Vec3 &r1, Vec3 &v1, double &t0, double &m0, double &a, double &ecc, double &ran, double &aper, double &inc)
void setStepWidth(double s)
void caldat(double mjd, int &day, int &month, int &year, double &hour)
int getStateVector(int nsat)
void getKeplerElements(double &perc, double &apoc, double &inc, double &ecc, double &ra, double &tano, double &m0, double &a, double &n0)
double abs(const Vec3 &c)
void setStateVector(double mjd, double x, double y, double z, double vx, double vy, double vz)
void setDeltaTAI_UTC(double d)
int selectSat(char *sname)
void dms(double dd, int &d, int &m, double &s)
double eccanom(double man, double ecc)
void getSatName(char *sname) const
double mjd(int day, int month, int year, double hour)
void getFixedFrame(double &x, double &y, double &z, double &vx, double &vy, double &vz)
void assign(double x=0, double y=0, double z=0)
void setPlanet(char *pname)
double julcent(double mjuld)
Vec3 mxvct(const Mat3 &m1, Vec3 &v1)
void getPlanetographic(double &lng, double &lat, double &height) const