67 return sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
93cross(
double vec1[3],
double vec2[3],
double outvec[3])
95 outvec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
96 outvec[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
97 outvec[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
124dot(
double x[3],
double y[3])
126 return (x[0] * y[0] + x[1] * y[1] + x[2] * y[2]);
154angle(
double vec1[3],
double vec2[3])
156 double small, undefined, magv1, magv2, temp;
158 undefined = 999999.1;
163 if (magv1 * magv2 > small * small)
165 temp =
dot(vec1, vec2) / (magv1 * magv2);
166 if (fabs(temp) > 1.0)
168 temp =
sgn(temp) * 1.0;
241newtonnu(
double ecc,
double nu,
double& e0,
double& m)
243 double small, sine, cose;
251 if (fabs(ecc) < small)
258 if (ecc < 1.0 - small)
260 sine = (sqrt(1.0 - ecc * ecc) * sin(nu)) / (1.0 + ecc * cos(nu));
261 cose = (ecc + cos(nu)) / (1.0 + ecc * cos(nu));
262 e0 = atan2(sine, cose);
263 m = e0 - ecc * sin(e0);
267 if (ecc > 1.0 + small)
269 if ((ecc > 1.0) && (fabs(nu) + 0.00001 <
pi - acos(1.0 / ecc)))
271 sine = (sqrt(ecc * ecc - 1.0) * sin(nu)) / (1.0 + ecc * cos(nu));
273 m = ecc * sinh(e0) - e0;
278 if (fabs(nu) < 168.0 *
pi / 180.0)
281 m = e0 + (e0 * e0 * e0) / 3.0;
286 m = fmod(m, 2.0 *
pi);
291 e0 = fmod(e0, 2.0 *
pi);
368 double undefined, small, hbar[3], nbar[3], magr, magv, magn, ebar[3], sme, rdotv, infinite,
369 temp, c1, hk, twopi, magh, halfpi, e;
377 undefined = 999999.1;
393 c1 = magv * magv - mu / magr;
395 for (i = 0; i <= 2; i++)
397 ebar[i] = (c1 * r[i] - rdotv * v[i]) / mu;
402 sme = (magv * magv * 0.5) - (mu / magr);
403 if (fabs(sme) > small)
405 a = -mu / (2.0 * sme);
411 p = magh * magh / mu;
419 strcpy(typeorbit,
"ei");
423 if ((incl < small) | (fabs(incl -
pi) < small))
425 strcpy(typeorbit,
"ce");
430 strcpy(typeorbit,
"ci");
436 if ((incl < small) | (fabs(incl -
pi) < small))
438 strcpy(typeorbit,
"ee");
445 temp = nbar[0] / magn;
446 if (fabs(temp) > 1.0)
453 omega = twopi - omega;
462 if (strcmp(typeorbit,
"ei") == 0)
464 argp =
angle(nbar, ebar);
476 if (typeorbit[0] ==
'e')
490 if (strcmp(typeorbit,
"ci") == 0)
492 arglat =
angle(nbar, r);
495 arglat = twopi - arglat;
505 if ((ecc > small) && (strcmp(typeorbit,
"ee") == 0))
507 temp = ebar[0] / ecc;
508 if (fabs(temp) > 1.0)
515 lonper = twopi - lonper;
519 lonper = twopi - lonper;
528 if ((magr > small) && (strcmp(typeorbit,
"ce") == 0))
531 if (fabs(temp) > 1.0)
535 truelon = acos(temp);
538 truelon = twopi - truelon;
542 truelon = twopi - truelon;
552 if (typeorbit[0] ==
'e')
607jday(
int year,
int mon,
int day,
int hr,
int minute,
double sec,
double& jd)
609 jd = 367.0 * year - floor((7 * (year + floor((mon + 9) / 12.0))) * 0.25) +
610 floor(275 * mon / 9.0) + day + 1721013.5 +
611 ((sec / 60.0 + minute) / 60.0 + hr) / 24.0;
652days2mdhms(
int year,
double days,
int& mon,
int& day,
int& hr,
int& minute,
double& sec)
654 int i, inttemp, dayofyr;
656 int lmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
658 dayofyr = (int)floor(days);
667 while ((dayofyr > inttemp + lmonth[i - 1]) && (i < 12))
669 inttemp = inttemp + lmonth[i - 1];
673 day = dayofyr - inttemp;
676 temp = (days - dayofyr) * 24.0;
677 hr = (int)floor(temp);
678 temp = (temp - hr) * 60.0;
679 minute = (int)floor(temp);
680 sec = (temp - minute) * 60.0;
724invjday(
double jd,
int& year,
int& mon,
int& day,
int& hr,
int& minute,
double& sec)
727 double days, tu, temp;
730 temp = jd - 2415019.5;
732 year = 1900 + (int)floor(tu);
733 leapyrs = (int)floor((year - 1901) * 0.25);
736 days = temp - ((year - 1900) * 365.0 + leapyrs) + 0.00000000001;
742 leapyrs = (int)floor((year - 1901) * 0.25);
743 days = temp - ((year - 1900) * 365.0 + leapyrs);
747 days2mdhms(year, days, mon, day, hr, minute, sec);
748 sec = sec - 0.00000086400;
void invjday(double jd, int &year, int &mon, int &day, int &hr, int &minute, double &sec)
void cross(double vec1[3], double vec2[3], double outvec[3])
void days2mdhms(int year, double days, int &mon, int &day, int &hr, int &minute, double &sec)
void newtonnu(double ecc, double nu, double &e0, double &m)
double angle(double vec1[3], double vec2[3])
void rv2coe(double r[3], double v[3], double mu, double &p, double &a, double &ecc, double &incl, double &omega, double &argp, double &nu, double &m, double &arglat, double &truelon, double &lonper)
double dot(double x[3], double y[3])
void jday(int year, int mon, int day, int hr, int minute, double sec, double &jd)