} // coe2rv public static void COEtoRVMirror(OrbitElements oe, NBody centerBody, ref Vector3d r, ref Vector3d v, bool relativePos) { double temp, sinnu, cosnu; Vector3d rpqw, vpqw; double mu = GravityEngine.Instance().GetMass(centerBody); // -------------------- implementation ---------------------- // determine what type of orbit is involved and set up the // set up angles for the special cases. // ------------------------------------------------------------- if (oe.ecc < small) { // ---------------- circular equatorial ------------------ if ((oe.incl < small) | (Mathd.Abs(oe.incl - Mathd.PI) < small)) { oe.argp = 0.0; oe.raan = 0.0; oe.nu = oe.truelon; } else { // -------------- circular inclined ------------------ oe.argp = 0.0; oe.nu = oe.arglat; } } else { // --------------- elliptical equatorial ----------------- if ((oe.incl < small) | (Mathd.Abs(oe.incl - Mathd.PI) < small)) { oe.argp = oe.lonper; oe.raan = 0.0; } } // ---------- form pqw position and velocity vectors ---------- cosnu = Mathd.Cos(oe.nu); sinnu = Mathd.Sin(oe.nu); temp = oe.p / (1.0 + oe.ecc * cosnu); // flip Y rpqw = new Vector3d(temp * cosnu, -temp * sinnu, 0.0); if (Mathd.Abs(oe.p) < 0.00000001) { oe.p = 0.00000001; } // flip X (not Y) vpqw = new Vector3d(sinnu * Mathd.Sqrt(mu / oe.p), (oe.ecc + cosnu) * Mathd.Sqrt(mu / oe.p), 0.0); // ---------------- perform transformation to ijk ------------ r = GEMath.Rot3(rpqw, -oe.argp); r = GEMath.Rot1(r, -oe.incl); r = GEMath.Rot3(r, -oe.raan); v = GEMath.Rot3(vpqw, -oe.argp); v = GEMath.Rot1(v, -oe.incl); v = GEMath.Rot3(v, -oe.raan); if (!relativePos) { r += GravityEngine.Instance().GetPositionDoubleV3(centerBody); v += GravityEngine.Instance().GetVelocityDoubleV3(centerBody); } } // coe2rvMirror