コード例 #1
0
ファイル: Orbit.cs プロジェクト: TruthfulGnome/SFSModLoader
    public Orbit(Double3 posIn, Double3 velIn, double timeIn, CelestialBodyData planet, CelestialBodyData lastPlanet)
    {
        this.planet = planet;
        this.timeIn = timeIn;
        double  mass    = planet.mass;
        Double3 b       = Double3.Cross2d(posIn, velIn);
        Double3 @double = Double3.Cross(velIn, b) / mass - posIn.normalized2d;

        this.eccentricity        = @double.magnitude2d;
        this.argumentOfPeriapsis = Math.Atan2(@double.y, @double.x);
        this.semiMajorAxis       = -mass / (2.0 * (Math.Pow(velIn.magnitude2d, 2.0) / 2.0 - mass / posIn.magnitude2d));
        this.periapsis           = this.semiMajorAxis * (1.0 - this.eccentricity);
        this.apoapsis            = ((this.eccentricity >= 1.0) ? double.PositiveInfinity : (this.semiMajorAxis * (1.0 + this.eccentricity)));
        this.semiLatusRectum     = Kepler.GetSemiLatusRectum(this.periapsis, this.eccentricity);
        this._period             = Kepler.GetPeriod(this.eccentricity, this.semiMajorAxis, mass);
        this.meanMotion          = Kepler.GetMeanMotion(this._period, this.eccentricity, mass, this.semiMajorAxis) * (double)Math.Sign(b.z);
        double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(posIn.magnitude2d, this.semiLatusRectum, this.eccentricity);
        double num = Kepler.GetMeanAnomaly(this.eccentricity, trueAnomalyAtRadius, posIn, this.argumentOfPeriapsis) / this.meanMotion;

        if (this.apoapsis > planet.orbitData.SOI || this.eccentricity >= 1.0)
        {
            this._period = 0.0;
        }
        this.periapsisPassageTime = timeIn + num - this._period * 10.0;
        this.GetOrbitType(timeIn, lastPlanet);
        this.stopTimeWarpTime = this.GetStopTimeWarpTime();
    }
コード例 #2
0
    public static double GetEjectionAngle(double escapeVelocity, double targetPeriapsis, double mass, double SOI)
    {
        Double3 a    = new Double3(SOI, 0.0);
        double  num  = 0.78539816339744828;
        double  num2 = 0.39269908169872414;

        for (int i = 0; i < 16; i++)
        {
            Double3 @double = new Double3(Math.Cos(num) * escapeVelocity, Math.Sin(num) * escapeVelocity);
            Double3 double2 = Double3.Cross(@double, Double3.Cross2d(a, @double)) / mass - a.normalized2d;
            if (i == 15)
            {
                return(num - Math.Atan2(double2.y, double2.x));
            }
            num  -= num2 * (double)Math.Sign(-mass / (2.0 * (Math.Pow(@double.magnitude2d, 2.0) / 2.0 - mass / a.magnitude2d)) * (1.0 - double2.magnitude2d) - targetPeriapsis);
            num2 *= 0.5;
        }
        return(0.0);
    }