65 return sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
91 cross(
double vec1[3],
double vec2[3],
double outvec[3])
93 outvec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
94 outvec[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
95 outvec[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
122 dot(
double x[3],
double y[3])
124 return (x[0] * y[0] + x[1] * y[1] + x[2] * y[2]);
152 angle(
double vec1[3],
double vec2[3])
154 double small, undefined, magv1, magv2, temp;
156 undefined = 999999.1;
161 if (magv1 * magv2 > small * small)
163 temp =
dot(vec1, vec2) / (magv1 * magv2);
164 if (fabs(temp) > 1.0)
165 temp =
sgn(temp) * 1.0;
235 newtonnu(
double ecc,
double nu,
double& e0,
double& m)
237 double small, sine, cose;
245 if (fabs(ecc) < small)
252 if (ecc < 1.0 - small)
254 sine = (sqrt(1.0 - ecc * ecc) * sin(nu)) / (1.0 + ecc * cos(nu));
255 cose = (ecc + cos(nu)) / (1.0 + ecc * cos(nu));
256 e0 = atan2(sine, cose);
257 m = e0 - ecc * sin(e0);
261 if (ecc > 1.0 + small)
263 if ((ecc > 1.0) && (fabs(nu) + 0.00001 <
pi - acos(1.0 / ecc)))
265 sine = (sqrt(ecc * ecc - 1.0) * sin(nu)) / (1.0 + ecc * cos(nu));
267 m = ecc * sinh(e0) - e0;
272 if (fabs(nu) < 168.0 *
pi / 180.0)
275 m = e0 + (e0 * e0 * e0) / 3.0;
280 m = fmod(m, 2.0 *
pi);
283 e0 = fmod(e0, 2.0 *
pi);
360 double undefined, small, hbar[3], nbar[3], magr, magv, magn, ebar[3], sme, rdotv, infinite,
361 temp, c1, hk, twopi, magh, halfpi, e;
369 undefined = 999999.1;
385 c1 = magv * magv - mu / magr;
387 for (i = 0; i <= 2; i++)
388 ebar[i] = (c1 * r[i] - rdotv * v[i]) / mu;
392 sme = (magv * magv * 0.5) - (mu / magr);
393 if (fabs(sme) > small)
394 a = -mu / (2.0 * sme);
397 p = magh * magh / mu;
405 strcpy(typeorbit,
"ei");
409 if ((incl < small) | (fabs(incl -
pi) < small))
410 strcpy(typeorbit,
"ce");
413 strcpy(typeorbit,
"ci");
418 if ((incl < small) | (fabs(incl -
pi) < small))
419 strcpy(typeorbit,
"ee");
425 temp = nbar[0] / magn;
426 if (fabs(temp) > 1.0)
430 omega = twopi - omega;
436 if (strcmp(typeorbit,
"ei") == 0)
438 argp =
angle(nbar, ebar);
446 if (typeorbit[0] ==
'e')
456 if (strcmp(typeorbit,
"ci") == 0)
458 arglat =
angle(nbar, r);
460 arglat = twopi - arglat;
467 if ((ecc > small) && (strcmp(typeorbit,
"ee") == 0))
469 temp = ebar[0] / ecc;
470 if (fabs(temp) > 1.0)
474 lonper = twopi - lonper;
476 lonper = twopi - lonper;
482 if ((magr > small) && (strcmp(typeorbit,
"ce") == 0))
485 if (fabs(temp) > 1.0)
487 truelon = acos(temp);
489 truelon = twopi - truelon;
491 truelon = twopi - truelon;
498 if (typeorbit[0] ==
'e')
551 jday(
int year,
int mon,
int day,
int hr,
int minute,
double sec,
double& jd)
553 jd = 367.0 * year - floor((7 * (year + floor((mon + 9) / 12.0))) * 0.25) +
554 floor(275 * mon / 9.0) + day + 1721013.5 +
555 ((sec / 60.0 + minute) / 60.0 + hr) / 24.0;
596 days2mdhms(
int year,
double days,
int& mon,
int& day,
int& hr,
int& minute,
double& sec)
598 int i, inttemp, dayofyr;
600 int lmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
602 dayofyr = (int)floor(days);
609 while ((dayofyr > inttemp + lmonth[i - 1]) && (i < 12))
611 inttemp = inttemp + lmonth[i - 1];
615 day = dayofyr - inttemp;
618 temp = (days - dayofyr) * 24.0;
619 hr = (int)floor(temp);
620 temp = (temp - hr) * 60.0;
621 minute = (int)floor(temp);
622 sec = (temp - minute) * 60.0;
666 invjday(
double jd,
int& year,
int& mon,
int& day,
int& hr,
int& minute,
double& sec)
669 double days, tu, temp;
672 temp = jd - 2415019.5;
674 year = 1900 + (int)floor(tu);
675 leapyrs = (int)floor((year - 1901) * 0.25);
678 days = temp - ((year - 1900) * 365.0 + leapyrs) + 0.00000000001;
684 leapyrs = (int)floor((year - 1901) * 0.25);
685 days = temp - ((year - 1900) * 365.0 + leapyrs);
689 days2mdhms(year, days, mon, day, hr, minute, sec);
690 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)