Esempio n. 1
0
 public MockBody(string name,
                 double radius,
                 MockBody parent,
                 double inclination,
                 double eccentricity,
                 double semiMajorAxis,
                 double lan,
                 double argumentOfPeriapsis,
                 double epoch,
                 double meanAnomalyAtEpoch,
                 double mu,
                 double soiRadius,
                 bool hasAtmosphere,
                 double atmosphereDepth,
                 double rotationPeriod)
 {
     this.name      = name;
     this.parent    = parent;
     this.mu        = mu;
     this.soiRadius = soiRadius;
     orbit          = new MockOrbit(parent, inclination, eccentricity, semiMajorAxis, lan, argumentOfPeriapsis,
                                    epoch, meanAnomalyAtEpoch);
     this.radius          = radius;
     this.hasAtmosphere   = hasAtmosphere;
     this.atmosphereDepth = atmosphereDepth;
     this.rotationPeriod  = rotationPeriod;
     angularVelocity      = Vector3d.down * (2 * Math.PI / rotationPeriod);
 }
Esempio n. 2
0
 public MockBody(string name, double radius, double mu)
 {
     this.name       = name;
     this.mu         = mu;
     parent          = null;
     orbit           = null;
     soiRadius       = double.PositiveInfinity;
     this.radius     = radius;
     hasAtmosphere   = false;
     atmosphereDepth = 0;
 }
Esempio n. 3
0
        public MockOrbit(MockBody body,
                         double inclination,
                         double eccentricity,
                         double semiMajorAxis,
                         double lan,
                         double argumentOfPeriapsis,
                         double epoch,
                         double meanAnomalyAtEpoch)
        {
            this.body                = body;
            this.inclination         = inclination;
            this.eccentricity        = eccentricity;
            this.semiMajorAxis       = semiMajorAxis;
            this.lan                 = lan;
            this.argumentOfPeriapsis = argumentOfPeriapsis;
            this.meanAnomalyAtEpoch  = meanAnomalyAtEpoch;
            this.epoch               = epoch;

            double anX  = Math.Cos(lan * DegToRad);
            double anY  = Math.Sin(lan * DegToRad);
            double incX = Math.Cos(inclination * DegToRad);
            double incY = Math.Sin(inclination * DegToRad);
            double peX  = Math.Cos(argumentOfPeriapsis * DegToRad);
            double peY  = Math.Sin(argumentOfPeriapsis * DegToRad);

            frameX = new Vector3d(anX * peX - anY * incX * peY, anY * peX + anX * incX * peY, incY * peY);
            frameY = new Vector3d(-anX * peY - anY * incX * peX, -anY * peY + anX * incX * peX, incY * peX);
            frameZ = new Vector3d(anY * incY, -anX * incY, incX);

            ascendingNode = Vector3d.Cross(Vector3d.forward, frameZ);
            if (ascendingNode.sqrMagnitude == 0.0)
            {
                ascendingNode = Vector3d.right;
            }

            eccVec           = frameX * eccentricity;
            meanMotion       = GetMeanMotion();
            orbitTimeAtEpoch = meanAnomalyAtEpoch / meanMotion;
            if (eccentricity < 1.0)
            {
                period = 2 * Math.PI / meanMotion;
            }
            else
            {
                period = double.PositiveInfinity;
            }
        }
Esempio n. 4
0
        public MockOrbit(MockBody body, Vector3d position, Vector3d velocity, double ut)
        {
            this.body = body;

            Vector3d h             = Vector3d.Cross(position, velocity);
            double   orbitalEnergy = velocity.sqrMagnitude / 2.0 - body.mu / position.magnitude;

            if (h.sqrMagnitude == 0.0)
            {
                ascendingNode = Vector3d.Cross(position, Vector3d.forward);
            }
            else
            {
                ascendingNode = Vector3d.Cross(Vector3d.forward, h);
            }

            if (ascendingNode.sqrMagnitude == 0.0)
            {
                ascendingNode = Vector3d.right;
            }

            lan          = RadToDeg * Math.Atan2(ascendingNode.y, ascendingNode.x);
            eccVec       = Vector3d.Cross(velocity, h) / body.mu - position / position.magnitude;
            eccentricity = eccVec.magnitude;
            if (eccentricity < 1.0)
            {
                semiMajorAxis = -body.mu / (2.0 * orbitalEnergy);
            }
            else
            {
                semiMajorAxis = -h.sqrMagnitude / body.mu / (eccVec.sqrMagnitude - 1.0);
            }

            if (eccentricity == 0.0)
            {
                frameX = ascendingNode.normalized;
                argumentOfPeriapsis = 0.0;
            }
            else
            {
                frameX = eccVec.normalized;
                argumentOfPeriapsis =
                    RadToDeg * Math.Acos(Vector3d.Dot(ascendingNode, frameX) / ascendingNode.magnitude);
                if (frameX.z < 0.0)
                {
                    argumentOfPeriapsis = 360.0 - argumentOfPeriapsis;
                }
            }

            if (h.sqrMagnitude == 0.0)
            {
                frameY = ascendingNode.normalized;
                frameZ = Vector3d.Cross(frameX, frameY);
            }
            else
            {
                frameZ = h.normalized;
                frameY = Vector3d.Cross(frameZ, frameX);
            }

            inclination = RadToDeg * Math.Acos(frameZ.z);
            epoch       = ut;
            double trueAnomaly      = Math.Atan2(Vector3d.Dot(frameY, position), Vector3d.Dot(frameX, position));
            double eccentricAnomaly = GetEccentricAnomalyForTrue(trueAnomaly);
            double meanAnomaly      = GetMeanAnomaly(eccentricAnomaly);

            meanAnomalyAtEpoch = meanAnomaly;
            meanMotion         = GetMeanMotion();
            orbitTimeAtEpoch   = meanAnomalyAtEpoch / meanMotion;
            if (eccentricity < 1.0)
            {
                period = 2 * Math.PI / meanMotion;
            }
            else
            {
                period = double.PositiveInfinity;
            }
        }