Exemplo n.º 1
0
        void OnEntityChange(EntityState entity)
        {
            OrderingEntity    = entity;
            _actionDateTime   = _uiState.PrimarySystemDateTime;
            _orderEntityOrbit = entity.Entity.GetDataBlob <OrbitDB>();

            _massParentBody     = _orderEntityOrbit.Parent.GetDataBlob <MassVolumeDB>().Mass;
            _massOrderingEntity = OrderingEntity.Entity.GetDataBlob <MassVolumeDB>().Mass;
            _stdGravParam_m     = OrbitMath.CalculateStandardGravityParameterInM3S2(_massOrderingEntity, _massParentBody);

            _positonAtChange_m = OrbitProcessor.GetPosition_m(_orderEntityOrbit, _actionDateTime);
            var velAtChange2d = OrbitProcessor.GetOrbitalVector_m(_orderEntityOrbit, _actionDateTime);

            _orbitalVelocityAtChange_m = new Vector3(velAtChange2d.X, velAtChange2d.Y, 0);
            _origionalAngle            = Math.Atan2(_orbitalVelocityAtChange_m.X, _orbitalVelocityAtChange_m.Y);


            var newtondb = entity.Entity.GetDataBlob <NewtonThrustAbilityDB>();

            _newtonUI = new NewtonionOrderUI(newtondb, _massOrderingEntity);



            IsActive = true;
        }
Exemplo n.º 2
0
 public override void OnSystemTickChange(DateTime newDate)
 {
     if (_actionDateTime < newDate)
     {
         _actionDateTime    = newDate;
         _positonAtChange_m = OrbitProcessor.GetPosition_m(_orderEntityOrbit, _actionDateTime);
         var vector2 = OrbitProcessor.GetOrbitalVector_m(_orderEntityOrbit, _actionDateTime);
         _orbitalVelocityAtChange_m = new Vector3(vector2.X, vector2.Y, 0);
         _origionalAngle            = Math.Atan2(_orbitalVelocityAtChange_m.X, _orbitalVelocityAtChange_m.Y);
     }
 }
Exemplo n.º 3
0
        public void TestOrbitDBFromVectors(double parentMass, double objMass, Vector3 position_InMeters, Vector3 velocity_InMetersSec)
        {
            double         angleΔ = 0.0000000001;
            double         sgp_m  = OrbitMath.CalculateStandardGravityParameterInM3S2(objMass, parentMass);
            KeplerElements ke_m   = OrbitMath.KeplerFromPositionAndVelocity(sgp_m, position_InMeters, velocity_InMetersSec, new DateTime());

            Game          game = new Game();
            EntityManager man  = new EntityManager(game, false);

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(man.ManagerGuid)
            {
                X_AU = 0, Y_AU = 0, Z_AU = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                MassDry = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(man, parentblobs);


            OrbitDB objOrbit = OrbitDB.FromVector(parentEntity, objMass, parentMass, sgp_m, position_InMeters, velocity_InMetersSec, new DateTime());
            //Vector3 resultPos_AU = OrbitProcessor.GetPosition_AU(objOrbit, new DateTime());

            //check LoAN
            var objLoAN        = objOrbit.LongitudeOfAscendingNode;
            var keLoAN         = ke_m.LoAN;
            var loANDifference = objLoAN - keLoAN;

            Assert.AreEqual(keLoAN, objLoAN, angleΔ);

            //check AoP
            var objAoP     = objOrbit.ArgumentOfPeriapsis;
            var keAoP      = ke_m.AoP;
            var difference = objAoP - keAoP;

            Assert.AreEqual(keAoP, objAoP, angleΔ);


            //check MeanAnomalyAtEpoch
            var objM0 = objOrbit.MeanAnomalyAtEpoch;
            var keM0  = ke_m.MeanAnomalyAtEpoch;

            Assert.AreEqual(keM0, objM0, angleΔ);
            Assert.AreEqual(objM0, OrbitMath.GetMeanAnomalyFromTime(objM0, objOrbit.MeanMotion_DegreesSec, 0), "meanAnomalyError");

            //checkEpoch
            var objEpoch = objOrbit.Epoch;
            var keEpoch  = ke_m.Epoch;

            Assert.AreEqual(keEpoch, objEpoch);



            //check EccentricAnomaly:
            var objE = (OrbitProcessor.GetEccentricAnomaly(objOrbit, objOrbit.MeanAnomalyAtEpoch_Degrees));
            //var keE =   (OrbitMath.Gete(position, ke.SemiMajorAxis, ke.LinearEccentricity, ke.AoP));

            /*
             * if (objE != keE)
             * {
             *  var dif = objE - keE;
             *  Assert.AreEqual(keE, objE, angleΔ);
             * }
             */
            //check trueAnomaly
            var orbTrueAnom         = OrbitProcessor.GetTrueAnomaly(objOrbit, new DateTime());
            var orbtaDeg            = Angle.ToDegrees(orbTrueAnom);
            var differenceInRadians = orbTrueAnom - ke_m.TrueAnomalyAtEpoch;
            var differenceInDegrees = Angle.ToDegrees(differenceInRadians);

            if (ke_m.TrueAnomalyAtEpoch != orbTrueAnom)
            {
                Vector3 eccentVector = OrbitMath.EccentricityVector(sgp_m, position_InMeters, velocity_InMetersSec);
                var     tacalc1      = OrbitMath.TrueAnomaly(eccentVector, position_InMeters, velocity_InMetersSec);
                var     tacalc2      = OrbitMath.TrueAnomaly(sgp_m, position_InMeters, velocity_InMetersSec);

                var diffa = differenceInDegrees;
                var diffb = Angle.ToDegrees(orbTrueAnom - tacalc1);
                var diffc = Angle.ToDegrees(orbTrueAnom - tacalc2);

                var ketaDeg = Angle.ToDegrees(tacalc1);
            }

            Assert.AreEqual(0, Angle.DifferenceBetweenRadians(ke_m.TrueAnomalyAtEpoch, orbTrueAnom), angleΔ,
                            "more than " + angleΔ + " radians difference, at " + differenceInRadians + " \n " +
                            "(more than " + Angle.ToDegrees(angleΔ) + " degrees difference at " + differenceInDegrees + ")" + " \n " +
                            "ke Angle: " + ke_m.TrueAnomalyAtEpoch + " obj Angle: " + orbTrueAnom + " \n " +
                            "ke Angle: " + Angle.ToDegrees(ke_m.TrueAnomalyAtEpoch) + " obj Angle: " + Angle.ToDegrees(orbTrueAnom));

            Assert.AreEqual(ke_m.Eccentricity, objOrbit.Eccentricity);
            Assert.AreEqual(ke_m.SemiMajorAxis, objOrbit.SemiMajorAxis);


            var majAxisLenke  = ke_m.SemiMajorAxis * 2;
            var majAxisLenke2 = ke_m.Apoapsis + ke_m.Periapsis;

            Assert.AreEqual(majAxisLenke, majAxisLenke2, 1.0E-4);
            var majAxisLendb  = objOrbit.SemiMajorAxis * 2;
            var majAxisLendb2 = objOrbit.Apoapsis + objOrbit.Periapsis;

            Assert.AreEqual(majAxisLendb, majAxisLendb2, 1.0E-4);
            Assert.AreEqual(majAxisLenke, majAxisLendb, 1.0E-4);
            Assert.AreEqual(majAxisLenke2, majAxisLendb2, 1.0E-4);



            var ke_apm    = ke_m.Apoapsis;
            var db_apm    = objOrbit.Apoapsis;
            var differnce = ke_apm - db_apm;

            Assert.AreEqual(ke_m.Apoapsis, objOrbit.Apoapsis, 1.0E-4);
            Assert.AreEqual(ke_m.Periapsis, objOrbit.Periapsis, 1.0E-4);

            Vector3 pos_m    = position_InMeters;
            Vector3 result_m = OrbitProcessor.GetPosition_m(objOrbit, new DateTime());

            double  keslr     = EllipseMath.SemiLatusRectum(ke_m.SemiMajorAxis, ke_m.Eccentricity);
            double  keradius  = OrbitMath.RadiusAtAngle(ke_m.TrueAnomalyAtEpoch, keslr, ke_m.Eccentricity);
            Vector3 kemathPos = OrbitMath.GetRalitivePosition(ke_m.LoAN, ke_m.AoP, ke_m.Inclination, ke_m.TrueAnomalyAtEpoch, keradius);

            Assert.AreEqual(kemathPos.Length(), pos_m.Length(), 0.02);

            Assert.AreEqual(kemathPos.Length(), result_m.Length(), 0.02, "TA: " + orbtaDeg);
            Assert.AreEqual(kemathPos.X, result_m.X, 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(kemathPos.Y, result_m.Y, 0.5, "TA: " + orbtaDeg);
            Assert.AreEqual(kemathPos.Z, result_m.Z, 0.01, "TA: " + orbtaDeg);

            Assert.AreEqual(pos_m.Length(), result_m.Length(), 0.02, "TA: " + orbtaDeg);
            Assert.AreEqual(pos_m.X, result_m.X, 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(pos_m.Y, result_m.Y, 0.5, "TA: " + orbtaDeg);
            Assert.AreEqual(pos_m.Z, result_m.Z, 0.01, "TA: " + orbtaDeg);

            if (velocity_InMetersSec.Z == 0)
            {
                Assert.IsTrue(ke_m.Inclination == 0);
                Assert.IsTrue(objOrbit.Inclination_Degrees == 0);
            }

            //var speedVectorAU = OrbitProcessor.PreciseOrbitalVector(sgp, position, ke.SemiMajorAxis);
            //var speedVectorAU2 = OrbitProcessor.PreciseOrbitalVector(objOrbit, new DateTime());
            //Assert.AreEqual(speedVectorAU, speedVectorAU2);
        }