public void KeplerVsTimeOfFlight() { // Need to make sure TOF < 1 period const float mass = 100f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); NBody starNbody = star.GetComponent <NBody>(); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbitUniversal(starNbody, 1f, orbitRadius); OrbitUniversal orbitU = planet.GetComponent <OrbitUniversal>(); // Parabola (ecc=1.0 fails, need to investigate) float[] ecc_values = { 0.0f, 0.1f, 0.5f, 0.9f, 1.2f, 1.5f }; foreach (float ecc in ecc_values) { Debug.LogFormat("======= ecc={0} =======", ecc); orbitU.eccentricity = ecc; orbitU.p = 10f; orbitU.evolveMode = OrbitUniversal.EvolveMode.KEPLERS_EQN; // Evolve to position r1 double time = 5.0; TestSetupUtils.SetupGravityEngine(star, planet); double[] r1 = new double[] { 0, 0, 0 }; // orbitU.PreEvolve(pscale, mscale); // Ugh. Need to do this before call evolve, since it caches the value. Vector3d r0_vec = GravityEngine.Instance().GetPositionDoubleV3(planet.GetComponent <NBody>()); orbitU.Evolve(time, ref r1); Vector3d r1_vec = new Vector3d(ref r1); // check time to r1 double time_test = orbitU.TimeOfFlight(r0_vec, r1_vec); Debug.LogFormat("check r0={0} to r1={1} p ={2} after t={3} TOF => {4}", r0_vec, r1_vec, orbitU.p, time, time_test); Assert.IsTrue(GEUnit.DoubleEqual(time, time_test, 1E-4)); } }