public void OmegasEllipseInclination() { const float mass = 1000f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>(); orbitEllipse.InitNBody(1f, 1f); orbitEllipse.inclination = 35f; orbitEllipse.ecc = 0.25f; orbitEllipse.Init(); orbitEllipse.ApplyScale(1f); orbitEllipse.InitNBody(1f, 1f); // Try some values of om float[] omegaValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f }; foreach (float omega in omegaValues) { orbitEllipse.omega_uc = omega; orbitEllipse.Init(); orbitEllipse.InitNBody(1f, 1f); OrbitData od = new OrbitData(); od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>()); TestRV(od, planet, star, orbitRadius); } }
// Check eccentricity and inclination public void CheckTestRV() { const float mass = 1000f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>(); orbitEllipse.ecc = .25f; orbitEllipse.inclination = 25f; orbitEllipse.omega_uc = 10f; orbitEllipse.omega_lc = 20f; orbitEllipse.phase = 190f; orbitEllipse.Init(); orbitEllipse.ApplyScale(1f); orbitEllipse.InitNBody(1f, 1f); OrbitData od = new OrbitData(); od.a = orbitRadius; od.ecc = 0.25f; od.inclination = 25f; od.omega_uc = 10f; od.omega_lc = 20f; od.phase = 190f; TestRV(od, planet, star, orbitRadius); }
public void OmegaUNoInclination() { const float mass = 1000f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>(); orbitEllipse.InitNBody(1f, 1f); orbitEllipse.ecc = 0.1f; // Try some values of om float[] omegaValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 320f }; foreach (float omega in omegaValues) { orbitEllipse.omega_uc = omega; orbitEllipse.Init(); orbitEllipse.ApplyScale(1f); orbitEllipse.InitNBody(1f, 1f); OrbitData od = new OrbitData(); od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>()); Debug.Log("omega = " + omega + " od.omega_lc=" + od.omega_lc); Assert.IsTrue(FloatEqual(omega, od.omega_lc, 0.4)); } }
public void PhaseRetrogradeEllipse() { const float mass = 1000f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>(); orbitEllipse.ecc = 0.4f; orbitEllipse.inclination = 180f; // Try some values of om float[] phaseValues = { 30f, 45f, 60f, 90f, 135f, 180f, 0f }; foreach (float phase in phaseValues) { orbitEllipse.phase = phase; orbitEllipse.Init(); orbitEllipse.ApplyScale(1f); orbitEllipse.InitNBody(1f, 1f); OrbitData od = new OrbitData(); od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>()); Debug.Log("phase = " + phase + " od.phase=" + od.phase); // Need a bit of leeway at 0 with error Assert.IsTrue(FloatEqual(phase, od.phase, 0.02)); TestRV(od, planet, star, orbitRadius); } }
public void CirclePhaseOmegaInclined() { const float mass = 1000f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>(); orbitEllipse.inclination = 20f; // Try some values of phase float[] phaseValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 320f }; float[] omegaUValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 320f }; foreach (float phase in phaseValues) { foreach (float omegau in omegaUValues) { orbitEllipse.phase = phase; orbitEllipse.omega_uc = omegau; orbitEllipse.Init(); orbitEllipse.ApplyScale(1f); orbitEllipse.InitNBody(1f, 1f); orbitEllipse.Log("Initial circle:"); OrbitData od = new OrbitData(); od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>()); Debug.Log("TEST: phase = " + phase + " od.phase=" + od.phase + " omegaU = " + omegau + " od.omegau=" + od.omega_uc); TestRV(od, planet, star, orbitRadius); } } }
public void AddBody(string bodyType) { GameObject go = Instantiate(orbitingPrefab) as GameObject; go.transform.parent = star.transform; NBody nbody = go.GetComponent <NBody>(); if (bodyType == "massless") { nbody.mass = 0f; masslessObjects.Add(go); } else { nbody.mass = 1f; // nominal massiveObjects.Add(go); } OrbitEllipse eb = go.GetComponent <OrbitEllipse>(); if (eb == null) { Debug.LogError("Failed to get EllipseStart from prefab"); return; } eb.paramBy = EllipseBase.ParamBy.AXIS_A; eb.a = Random.Range(MIN_RADIUS, MAX_RADIUS); eb.inclination = Random.Range(-30f, 30f); eb.Init(); TrailRenderer[] trail = go.GetComponentsInChildren <TrailRenderer>(); trail[0].material.color = colors[colorIndex]; colorIndex = (colorIndex + 1) % colors.Length; GravityEngine.instance.AddBody(go); }
public void OmegaULEllipseInclined() { const float mass = 1000f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>(); orbitEllipse.InitNBody(1f, 1f); orbitEllipse.inclination = 30f; orbitEllipse.ecc = 0.2f; orbitEllipse.Init(); orbitEllipse.ApplyScale(1f); orbitEllipse.InitNBody(1f, 1f); // Try some values of om float[] omegaUValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 310f }; float[] omegaLValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f, 210f, 310f }; foreach (float omegaU in omegaUValues) { foreach (float omegaL in omegaLValues) { orbitEllipse.omega_uc = omegaU; orbitEllipse.omega_lc = omegaL; TestSetupUtils.SetupGravityEngine(star, planet); orbitEllipse.Log("OmegaUL inclined:"); OrbitData od = new OrbitData(); od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>()); Debug.Log("omegaU = " + omegaU + "omegaL = " + omegaL + " OD:=" + od.LogString()); TestRV(od, planet, star, orbitRadius); } } }
public void AddBody(string bodyType) { GameObject go = Instantiate(orbitingPrefab) as GameObject; go.transform.parent = star.transform; NBody nbody = go.GetComponent <NBody>(); if (bodyType == MASSLESS) { nbody.mass = 0f; masslessObjects.Add(go); } else if (bodyType == KEPLER) { nbody.mass = 0f; keplerObjects.Add(go); } else { nbody.mass = mass; // nominal massiveObjects.Add(go); } OrbitEllipse eb = go.GetComponent <OrbitEllipse>(); if (eb == null) { Debug.LogError("Failed to get EllipseStart from prefab"); return; } eb.paramBy = EllipseBase.ParamBy.AXIS_A; eb.a = Random.Range(minRadius, maxRadius); eb.inclination = Random.Range(-80f, 80f); if (bodyType == KEPLER) { eb.evolveMode = OrbitEllipse.evolveType.KEPLERS_EQN; } eb.Init(); GravityEngine.instance.AddBody(go); // Do this after added otherwise Kepler trails have a segment to origin TrailRenderer trail = go.GetComponentInChildren <TrailRenderer>(); if (trail != null) { trail.material.color = colors[colorIndex]; colorIndex = (colorIndex + 1) % colors.Length; trail.enabled = true; } }
// Check eccetricity and inclination public void EllipseInclination() { const float mass = 1000f; GameObject star = TestSetupUtils.CreateNBody(mass, new Vector3(0, 0, 0)); const float orbitRadius = 10f; GameObject planet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse orbitEllipse = planet.GetComponent <OrbitEllipse>(); orbitEllipse.InitNBody(1f, 1f); float eccentricity = 0.3f; orbitEllipse.ecc = eccentricity; orbitEllipse.Init(); orbitEllipse.ApplyScale(1f); orbitEllipse.InitNBody(1f, 1f); // take the velocity and check OrbitData orbitData = new OrbitData(); orbitData.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>()); Assert.IsTrue(FloatEqual(orbitRadius, orbitData.a)); Assert.IsTrue(FloatEqual(eccentricity, orbitData.ecc)); // Try some values of inclination float[] inclinationValues = { 0f, 30f, 45f, 60f, 90f, 135f, 180f }; foreach (float inc in inclinationValues) { orbitEllipse.inclination = inc; orbitEllipse.Init(); orbitEllipse.InitNBody(1f, 1f); OrbitData od = new OrbitData(); od.SetOrbitForVelocity(planet.GetComponent <NBody>(), star.GetComponent <NBody>()); Debug.Log("TEST: incl = " + inc + " od.inclination=" + od.inclination); Assert.IsTrue(FloatEqual(inc, od.inclination)); TestRV(od, planet, star, orbitRadius); } }
private void TestRV(OrbitData od, GameObject planet, GameObject star, float orbitRadius) { Vector3 r_initial = planet.transform.position; Vector3 v_initial = planet.GetComponent <NBody>().vel; GameObject testPlanet = TestSetupUtils.CreatePlanetInOrbit(star, 1f, orbitRadius); OrbitEllipse testEllipse = testPlanet.GetComponent <OrbitEllipse>(); testEllipse.InitFromOrbitData(od); testEllipse.ApplyScale(1f); testEllipse.Init(); testEllipse.InitNBody(1f, 1f); Vector3 r = testPlanet.transform.position; Vector3 v = testPlanet.GetComponent <NBody>().vel; Debug.Log(" r_i=" + r_initial + " r=" + r + " delta=" + Vector3.Distance(r_initial, r)); Debug.Log(" v_i=" + v_initial + " v=" + v + " delta=" + Vector3.Distance(v_initial, v)); Assert.IsTrue(FloatEqual(Vector3.Distance(r_initial, r), 0f, 1E-2)); Assert.IsTrue(FloatEqual(Vector3.Distance(v_initial, v), 0f, 1E-2)); }
private void AddBody() { // Pick a prefab int prefabNum = (int)Random.Range(0, planetPrefabs.Length); GameObject planet = Instantiate(planetPrefabs[prefabNum]) as GameObject; // make a child of this object planet.transform.parent = gameObject.transform; OrbitEllipse oe = planet.GetComponent <OrbitEllipse>(); oe.centerObject = gameObject; // set ranges with appropriate limits oe.a = Random.Range(Mathf.Max(a_min, 0.1f), a_max); oe.ecc = Random.Range(Mathf.Max(ecc_min, 0f), Mathf.Min(0.99f, ecc_max)); oe.inclination = Random.Range(Mathf.Max(0, incl_min), Mathf.Min(180f, incl_max)); oe.omega_lc = Random.Range(Mathf.Max(0, omega_lc_min), Mathf.Min(359.9f, omega_lc_max)); oe.omega_uc = Random.Range(Mathf.Max(0, omega_uc_min), Mathf.Min(359.9f, omega_uc_max)); oe.phase = Random.Range(Mathf.Max(0, phase_min), Mathf.Min(359.9f, phase_max)); // If there is a MeshRenderer - apply scale MeshRenderer mr = planet.GetComponentInChildren <MeshRenderer>(); if (mr != null) { mr.transform.localScale = Random.Range(Mathf.Max(scale_min, 0.01f), scale_max) * Vector3.one; } // If there is an OrbitPredictor, assign the parent OrbitPredictor op = planet.GetComponentInChildren <OrbitPredictor>(); if (op != null) { op.body = planet; op.centerBody = gameObject; } oe.Init(); }
private void EllipseInit(GameObject go, NBody nbody, GameObject parent, string bodyType) { OrbitEllipse eb = go.GetComponent <OrbitEllipse>(); eb.centerObject = parent; if (eb == null) { Debug.LogError("Failed to get OrbitEllipse from prefab:" + go.name); return; } // Awkward test code if (parent == star) { eb.paramBy = EllipseBase.ParamBy.AXIS_A; eb.a = Random.Range(minRadius, maxRadius); eb.inclination = Random.Range(-80f, 80f); eb.ecc = Random.Range(minEccentricity, maxEccentricity); } else { // moon test, so keep "a" small eb.paramBy = EllipseBase.ParamBy.AXIS_A; eb.a = moonRadius; eb.inclination = Random.Range(-80f, 80f); eb.ecc = 0; } if (bodyType == KEPLER) { eb.evolveMode = OrbitEllipse.evolveType.KEPLERS_EQN; } eb.Init(); OrbitPredictor op = go.GetComponentInChildren <OrbitPredictor>(); if (op != null) { op.SetNBody(nbody); op.SetCenterObject(parent); } }