67 return sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
93 cross(
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];
124 dot(
double x[3],
double y[3])
126 return (x[0] * y[0] + x[1] * y[1] + x[2] * y[2]);
154 angle(
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)
167 temp =
sgn(temp) * 1.0;
237 newtonnu(
double ecc,
double nu,
double& e0,
double& m)
239 double small, sine, cose;
247 if (fabs(ecc) < small)
254 if (ecc < 1.0 - small)
256 sine = (sqrt(1.0 - ecc * ecc) * sin(nu)) / (1.0 + ecc * cos(nu));
257 cose = (ecc + cos(nu)) / (1.0 + ecc * cos(nu));
258 e0 = atan2(sine, cose);
259 m = e0 - ecc * sin(e0);
263 if (ecc > 1.0 + small)
265 if ((ecc > 1.0) && (fabs(nu) + 0.00001 <
pi - acos(1.0 / ecc)))
267 sine = (sqrt(ecc * ecc - 1.0) * sin(nu)) / (1.0 + ecc * cos(nu));
269 m = ecc * sinh(e0) - e0;
274 if (fabs(nu) < 168.0 *
pi / 180.0)
277 m = e0 + (e0 * e0 * e0) / 3.0;
282 m = fmod(m, 2.0 *
pi);
285 e0 = fmod(e0, 2.0 *
pi);
362 double undefined, small, hbar[3], nbar[3], magr, magv, magn, ebar[3], sme, rdotv, infinite,
363 temp, c1, hk, twopi, magh, halfpi, e;
371 undefined = 999999.1;
387 c1 = magv * magv - mu / magr;
389 for (i = 0; i <= 2; i++)
390 ebar[i] = (c1 * r[i] - rdotv * v[i]) / mu;
394 sme = (magv * magv * 0.5) - (mu / magr);
395 if (fabs(sme) > small)
396 a = -mu / (2.0 * sme);
399 p = magh * magh / mu;
407 strcpy(typeorbit,
"ei");
411 if ((incl < small) | (fabs(incl -
pi) < small))
412 strcpy(typeorbit,
"ce");
415 strcpy(typeorbit,
"ci");
420 if ((incl < small) | (fabs(incl -
pi) < small))
421 strcpy(typeorbit,
"ee");
427 temp = nbar[0] / magn;
428 if (fabs(temp) > 1.0)
432 omega = twopi - omega;
438 if (strcmp(typeorbit,
"ei") == 0)
440 argp =
angle(nbar, ebar);
448 if (typeorbit[0] ==
'e')
458 if (strcmp(typeorbit,
"ci") == 0)
460 arglat =
angle(nbar, r);
462 arglat = twopi - arglat;
469 if ((ecc > small) && (strcmp(typeorbit,
"ee") == 0))
471 temp = ebar[0] / ecc;
472 if (fabs(temp) > 1.0)
476 lonper = twopi - lonper;
478 lonper = twopi - lonper;
484 if ((magr > small) && (strcmp(typeorbit,
"ce") == 0))
487 if (fabs(temp) > 1.0)
489 truelon = acos(temp);
491 truelon = twopi - truelon;
493 truelon = twopi - truelon;
500 if (typeorbit[0] ==
'e')
553 jday(
int year,
int mon,
int day,
int hr,
int minute,
double sec,
double& jd)
555 jd = 367.0 * year - floor((7 * (year + floor((mon + 9) / 12.0))) * 0.25) +
556 floor(275 * mon / 9.0) + day + 1721013.5 +
557 ((sec / 60.0 + minute) / 60.0 + hr) / 24.0;
598 days2mdhms(
int year,
double days,
int& mon,
int& day,
int& hr,
int& minute,
double& sec)
600 int i, inttemp, dayofyr;
602 int lmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
604 dayofyr = (int)floor(days);
611 while ((dayofyr > inttemp + lmonth[i - 1]) && (i < 12))
613 inttemp = inttemp + lmonth[i - 1];
617 day = dayofyr - inttemp;
620 temp = (days - dayofyr) * 24.0;
621 hr = (int)floor(temp);
622 temp = (temp - hr) * 60.0;
623 minute = (int)floor(temp);
624 sec = (temp - minute) * 60.0;
668 invjday(
double jd,
int& year,
int& mon,
int& day,
int& hr,
int& minute,
double& sec)
671 double days, tu, temp;
674 temp = jd - 2415019.5;
676 year = 1900 + (int)floor(tu);
677 leapyrs = (int)floor((year - 1901) * 0.25);
680 days = temp - ((year - 1900) * 365.0 + leapyrs) + 0.00000000001;
686 leapyrs = (int)floor((year - 1901) * 0.25);
687 days = temp - ((year - 1900) * 365.0 + leapyrs);
691 days2mdhms(year, days, mon, day, hr, minute, sec);
692 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)