Пример #1
0
    /// <summary>
    /// Inits the N body position and velocity based on the ellipse parameters and the
    /// position and velocity of the parent.
    /// </summary>
    /// <param name="physicalScale">Physical scale.</param>
    public void InitNBody(float physicalScale, float massScale)
    {
        float a_phy = a_scaled / physicalScale;
        NBody nbody = GetComponent <NBody>();

        // Phase is TRUE anomoly f
        float f = phase * Mathf.Deg2Rad;
        // Murray and Dermot
        // (2.26)
        // This should really be (M+m), but assume m << M
        // (massScale is added in at the GE level)
        float n = Mathf.Sqrt((float)(centerNbody.mass * massScale) / (a_phy * a_phy * a_phy));
        // (2.36)
        float denom = Mathf.Sqrt(1f - ecc * ecc);
        float xdot  = -1f * n * a_phy * Mathf.Sin(f) / denom;
        float ydot  = n * a_phy * (ecc + Mathf.Cos(f)) / denom;

        // Init functions are called in the engine by SetupOneBody and calls of parent vs children/grandchildren etc.
        // can be in arbitrary order. A child will need info from parent for position and velocity. Ensure parent
        // has inited. Init may get called more than once.
        INbodyInit centerInit = centerObject.GetComponent <INbodyInit>();

        if (centerInit != null)
        {
            centerInit.InitNBody(physicalScale, massScale);
        }

        SetTransform();

        Vector3 v_xy = new Vector3(xdot, ydot, 0);
        Vector3 vphy = ellipse_orientation * v_xy + centerNbody.vel_scaled;

        nbody.vel_scaled = vphy;
        SetTransform();
    }
Пример #2
0
    /// <summary>
    /// Inits the N body position and velocity based on the hyperbola parameters and the
    /// position and velocity of the parent.
    /// </summary>
    /// <param name="physicalScale">Physical scale.</param>
    public void InitNBody(float physicalScale, float massScale)
    {
        Init();
        float a_phy = a_scaled / physicalScale;

        if (nbody == null)
        {
            nbody = GetComponent <NBody>();
        }

        // Phase is TRUE anomoly f
        float f = ThetaForR(r_initial_phy);
        // Murray and Dermot (2.20)
        float n     = Mathf.Sqrt((float)(centerNbody.mass * massScale) / (a_phy * a_phy * a_phy));
        float denom = Mathf.Sqrt(ecc * ecc - 1f);
        // reverse sign from text to get prograde motion
        float xdot = 1f * n * a_phy * Mathf.Sin(f) / denom;
        float ydot = -1f * n * a_phy * (ecc + Mathf.Cos(f)) / denom;

        if (!r_initial_outbound)
        {
            xdot *= -1f;
            ydot *= -1f;
        }

        // Init functions are called in the engine by SetupOneBody and calls of parent vs children/grandchildren etc.
        // can be in arbitrary order. A child will need info from parent for position and velocity. Ensure parent
        // has inited.
        INbodyInit centerInit = centerObject.GetComponent <INbodyInit>();

        if (centerInit != null)
        {
            centerInit.InitNBody(physicalScale, massScale);
        }
        if (centerNbody.engineRef != null)
        {
            centerPos = GravityEngine.Instance().GetPhysicsPosition(centerNbody);
        }
        else
        {
            // setup - not yet added to GE
            centerPos = centerNbody.initialPhysPosition;
        }

        Vector3 v_xy = new Vector3(xdot, ydot, 0);
        Vector3 vphy = hyper_orientation * v_xy + centerNbody.vel_phys;

        nbody.vel_phys = vphy;
    }
Пример #3
0
 /// <summary>
 /// Apply scale to the orbit. This is used by the inspector scripts during
 /// scene setup. Do not use at run-time.
 /// </summary>
 /// <param name="scale">Scale.</param>
 public void ApplyScale(float scale)
 {
     if (paramBy == ParamBy.AXIS_A)
     {
         a_scaled = a * scale;
     }
     else if (paramBy == ParamBy.CLOSEST_P)
     {
         p_scaled = p * scale;
     }
     if (binaryNbody != null)
     {
         // this binary will have orbit w.r.t something. Make sure that update has been done
         // check for initial condition setup (e.g. initial conditions for elliptical orbit)
         GravityEngine ge = GravityEngine.Instance();
         if (binaryNbody.engineRef == null)
         {
             INbodyInit initNbody = GetComponent <INbodyInit>();
             if (initNbody != null)
             {
                 initNbody.InitNBody(ge.physToWorldFactor, ge.massScale);
             }
             cmPosition = binaryNbody.initialPhysPosition;
         }
         else
         {
             cmPosition = ge.GetPhysicsPosition(binaryNbody);
         }
     }
     else
     {
         cmPosition = transform.position * scale / GravityEngine.instance.physToWorldFactor;
     }
     UpdateOrbitParams();
     // if there is a binaryNbody, then need to determine the CM position and velocity before the
     SetupBodies();
 }
Пример #4
0
    /// <summary>
    /// Inits the N body position and velocity based on the hyperbola parameters and the
    /// position and velocity of the parent.
    /// </summary>
    /// <param name="physicalScale">Physical scale.</param>
    public void InitNBody(float physicalScale, float massScale)
    {
        float a_phy = a / physicalScale;
        NBody nbody = GetComponent <NBody>();

        // Phase is TRUE anomoly f
        float f = ThetaForR(r_initial);
        // Murray and Dermot (2.20)
        float n     = Mathf.Sqrt((float)(centerNbody.mass * massScale) / (a_phy * a_phy * a_phy));
        float denom = Mathf.Sqrt(ecc * ecc - 1f);
        // reverse sign from text to get prograde motion
        float xdot = 1f * n * a_phy * Mathf.Sin(f) / denom;
        float ydot = -1f * n * a_phy * (ecc + Mathf.Cos(f)) / denom;

        if (!r_initial_outbound)
        {
            xdot *= -1f;
            ydot *= -1f;
        }

        // Init functions are called in the engine by SetupOneBody and calls of parent vs children/grandchildren etc.
        // can be in arbitrary order. A child will need info from parent for position and velocity. Ensure parent
        // has inited.
        INbodyInit centerInit = centerObject.GetComponent <INbodyInit>();

        if (centerInit != null)
        {
            centerInit.InitNBody(physicalScale, massScale);
        }

        SetTransform(physicalScale);
        Vector3 v_xy = new Vector3(xdot, ydot, 0);
        Vector3 vphy = ellipse_orientation * v_xy + centerNbody.vel_scaled;

        nbody.vel_scaled = vphy;
    }