Example #1
0
    /// <summary>
    /// Calculate velocity for binary members and assign.
    /// reflect: One of the bodies positions and velocities must be reflected to opposite side of ellipse
    /// </summary>
    private void SetupBody(NBody nbody, float a_n, float mu, bool reflect)
    {
        float a_phy = a_n / GravityEngine.instance.physToWorldFactor;
        // Phase is TRUE anomoly f
        float f            = phase * Mathf.Deg2Rad;
        float reflect_in_y = 1f;

        if (reflect)
        {
            reflect_in_y = -1f;
            //f = f + Mathf.PI;
        }

        // Murray and Dermott (2.20)
        float r = a_phy * (1f - ecc * ecc) / (1f + ecc * Mathf.Cos(f));
        // (2.26) mu = n^2 a^3  (n is period, aka T)
        float n = Mathf.Sqrt(mu * GravityEngine.Instance().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;

        Vector3 position_xy = new Vector3(reflect_in_y * r * Mathf.Cos(f), r * Mathf.Sin(f), 0);
        // move from XY plane to the orbital plane and scale to world space
        // orbit position is WRT center
        Vector3 position = ellipse_orientation * position_xy;

        // ISSUE: Problematic in case where added after the fact
        position += cmPosition;
        nbody.initialPhysPosition = position;

        Vector3 v_xy = new Vector3(xdot, ydot, 0);

        v_xy *= reflect_in_y;
        // velocity will be scaled when NBody is scaled
        Vector3 vel_phys = Vector3.zero;

        if (binaryNbody != null)
        {
            // use CM velocity from parent for e.g. binary in orbit around something
            vel_phys = binaryNbody.vel_phys;
        }
        else
        {
            vel_phys = velocity * GravityScaler.GetVelocityScale();
        }
        nbody.vel_phys = ellipse_orientation * v_xy + vel_phys;
    }
    /// <summary>
    /// Validation:
    /// - confirmed velocity in SI units matches expected orbital velocity of ISS
    /// - checked that SI acceleration = -g at terminal velocity (9.73 m/s^2 at 28 km)
    /// </summary>

    // Use this for initialization
    void Start()
    {
        if (inertialMassKg == 0)
        {
            Debug.LogError("Mass is zero. Drag calculation will fail.");
        }
        if (spaceship == null)
        {
            spaceship = GetComponent <NBody>();
        }

        geDistanceToKm = 1;
        v_ship         = new double[] { 0, 0, 0 };
        v_earth        = new double[] { 0, 0, 0 };

        velocityScaleInternalToSI = GravityScaler.VelocityScaletoSIUnits() / GravityScaler.GetVelocityScale();
        accelSItoGE = GravityScaler.AccelSItoGEUnits() / GravityScaler.AccelerationScaleInternalToGEUnits();

        LoadDensityProfile();

        liveState = GravityEngine.Instance().GetWorldState();
    }
Example #3
0
 /// <summary>
 /// Set the deltaV for a scalar maneuver in world units (e.g. in ORBITAL
 /// units set velocity in km/hr)
 /// </summary>
 /// <param name="newDv"></param>
 public void SetDvScaled(float newDv)
 {
     dV = newDv * GravityScaler.GetVelocityScale();
 }
Example #4
0
 /// <summary>
 /// Return the dV in scaled units.
 /// </summary>
 /// <returns></returns>
 public float GetDvScaled()
 {
     return(dV / GravityScaler.GetVelocityScale());
 }
Example #5
0
 /// <summary>
 /// Set the velocity change vector in world units (e.g. in ORBITAL
 /// units set velocity in km/hr)
 /// </summary>
 /// <param name="newVel"></param>
 public void SetVelScaled(Vector3 newVel)
 {
     velChange = newVel * GravityScaler.GetVelocityScale();
 }