// Vallado Algorithm 10, p118 // (generic, will work for Ellipse as well, provided special cases are handled) // Not used yet. private void SetInitialPosition(NBody nbody) { // phase is in float denom = 1 + ecc * Mathf.Cos(phase_nu); Vector3 r_pqw = new Vector3(p * Mathf.Cos(phase_nu) / denom, p * Mathf.Sin(phase_nu) / denom, 0); r_initial_phy = r_pqw.magnitude; Vector3 r = hyper_orientation * r_pqw; // orbit position is WRT center. Could be adding dynamically to an object in motion, so need current position. Vector3 centerPos = Vector3.zero; // used by widgets - so need to get explcitly centerNbody = OrbitUtils.GetCenterNbody(this.transform, centerObject); if (centerNbody.engineRef != null) { centerPos = GravityEngine.Instance().GetPhysicsPosition(centerNbody); } else { // setup - not yet added to GE centerPos = centerNbody.initialPhysPosition; } nbody.initialPhysPosition = r + centerPos; }
/// <summary> /// Sets the initial position based on the orbit parameters. Used in the init phase to set the NBody in the /// correct position in the scene before handing control GE. /// </summary> public void SetInitialPosition(NBody nbody) { float phaseRad = phase * Mathf.Deg2Rad; // position object using true anomoly (angle from focus) float r = a_scaled * (1f - ecc * ecc) / (1f + ecc * Mathf.Cos(phaseRad)); Vector3 pos = new Vector3(r * Mathf.Cos(phaseRad), r * Mathf.Sin(phaseRad), 0); // move from XY plane to the orbital plane Vector3 new_p = ellipse_orientation * pos; // orbit position is WRT center. Could be adding dynamically to an object in motion, so need current position. Vector3 centerPos = Vector3.zero; // used by widgets - so need to get explcitly centerNbody = OrbitUtils.GetCenterNbody(transform, centerObject); if (centerNbody.engineRef != null) { centerPos = GravityEngine.Instance().GetPhysicsPosition(centerNbody); } else { // setup - not yet added to GE centerPos = centerNbody.initialPhysPosition; } nbody.initialPhysPosition = new_p + centerPos; }
/// <summary> /// Init the hyperbola, verify a center body is present and determine orientation. /// </summary> public void Init() { CalcOrbitParams(); centerNbody = OrbitUtils.GetCenterNbody(transform, centerObject); CalculateRotation(); NBody nbody = GetComponent <NBody>(); // particle ring would not have an NBody if (nbody != null) { SetInitialPosition(nbody); } }
/// <summary> /// Init the ellipse, verify a center body is present, determine orientation and update transform. /// </summary> public void Init() { // mode determines if user wants to define wrt to A or P. Determine other quantity if (paramBy == ParamBy.AXIS_A) { p = a * (1 - ecc); } else if (paramBy == ParamBy.CLOSEST_P) { a = p / (1 - ecc); } centerNbody = OrbitUtils.GetCenterNbody(transform, centerObject); CalculateRotation(); NBody nbody = GetComponent <NBody>(); // particle ring would not have an NBody if (nbody != null) { SetInitialPosition(nbody); } }