示例#1
0
        public void TestAddition()
        {
            JulianDate original = new JulianDate(2460000, 1000.0);
            Duration   toAdd    = Duration.FromSeconds(50.0);
            JulianDate added    = original.Add(toAdd);

            Assert.AreEqual(2460000, added.Day);
            Assert.AreEqual(1050.0, added.SecondsOfDay);
            JulianDate subtracted = original.Subtract(toAdd);

            Assert.AreEqual(2460000, subtracted.Day);
            Assert.AreEqual(950.0, subtracted.SecondsOfDay);

            original = new JulianDate(2460000, 8382.1);
            toAdd    = new Duration(1, 10.0);
            added    = original + toAdd;
            Assert.AreEqual(2460001, added.Day);
            Assert.AreEqual(8392.1, added.SecondsOfDay);
            subtracted = original - toAdd;
            Assert.AreEqual(2459999, subtracted.Day);
            Assert.AreEqual(8372.1, subtracted.SecondsOfDay);

            original = new JulianDate(2460000, 86000.0);
            toAdd    = Duration.FromSeconds(1000.0);
            added    = original.Add(toAdd);
            Assert.AreEqual(2460001, added.Day);
            Assert.AreEqual(600.0, added.SecondsOfDay);
            subtracted = original.Subtract(toAdd);
            Assert.AreEqual(2460000, subtracted.Day);
            Assert.AreEqual(85000.0, subtracted.SecondsOfDay);
        }
示例#2
0
        /// <summary>
        /// Propagate a Platform using a NumericalPropagator configured with the entered KeplerianElements,
        /// ForceModels, NumericalIntegrator, and start and stop dates.
        /// </summary>
        private void PropagateSatellite()
        {
            KeplerianElements orbitalElements = m_keplerianOrbitalElementsEntry.KeplerianElementValues;

            if (orbitalElements == null)
            {
                return;
            }

            Motion <Cartesian>        initialMotion = orbitalElements.ToCartesian();
            PropagationNewtonianPoint point         = new PropagationNewtonianPoint(m_elementID, m_forceModelSettings.CurrentCentralBody.InertialFrame, initialMotion.Value, initialMotion.FirstDerivative);

            point.Mass = new ScalarFixed(double.Parse(m_mass.Text));
            m_forceModelSettings.SetForceModelsOnPoint(point, new ScalarFixed(double.Parse(m_area.Text)));
            CentralBody primaryCentralBody = m_forceModelSettings.CurrentCentralBody;

            NumericalPropagatorDefinition state = new NumericalPropagatorDefinition();

            state.IntegrationElements.Add(point);
            state.Integrator = m_integratorSettings.GetIntegrator();

            JulianDate start = new JulianDate(GregorianDate.ParseExact(m_start.Text, DateFormat, null));
            JulianDate end   = new JulianDate(GregorianDate.ParseExact(m_end.Text, DateFormat, null));

            state.Epoch = start;
            NumericalPropagator propagator = state.CreatePropagator();

            propagator.StepTaken += (sender, args) =>
            {
                // Telling the propagator to stop if we get too close to the central body
                Cartesian position = propagator.Converter.ConvertState <Cartesian>(m_elementID, args.CurrentState).Value;
                if (position.Magnitude <= primaryCentralBody.Shape.SemimajorAxisLength + 10000)
                {
                    args.Indication = PropagationEventIndication.StopPropagationAfterStep;
                }
            };

            DateMotionCollection <Cartesian> answer = null;

            var backgroundCalculation = new BackgroundCalculation();

            backgroundCalculation.DoWork += (sender, e) =>
            {
                // actually propagate
                var result = propagator.Propagate(end.Subtract(start), 1, backgroundCalculation);
                answer = result.GetDateMotionCollection <Cartesian>(m_elementID);
            };
            backgroundCalculation.ProgressChanged    += (sender, e) => m_propagationProgress.Value = e.ProgressPercentage;
            backgroundCalculation.RunWorkerCompleted += (sender, e) =>
            {
                // when finished, draw the satellite
                DrawSatellite(answer, primaryCentralBody.InertialFrame);
                m_propagate.Enabled = true;
            };

            m_propagate.Enabled = false;
            backgroundCalculation.RunWorkerAsync();
        }
示例#3
0
        public void TestConversionToJulianDate()
        {
            GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 0);

            JulianDate julianDate = date.ToJulianDate();

            GregorianDate oneSecondLater  = new GregorianDate(2008, 12, 31, 23, 59, 1);
            GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 58, 59);

            Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(julianDate).Seconds);
            Assert.AreEqual(1, julianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds);
        }
示例#4
0
        public void CanConvertGregorianDateRepresentingLeapSecondToJulianDate()
        {
            GregorianDate leapSecondGregorianDate = new GregorianDate(2008, 12, 31, 23, 59, 60);
            JulianDate    leapSecondJulianDate    = leapSecondGregorianDate.ToJulianDate();

            Assert.AreEqual(leapSecondGregorianDate, leapSecondJulianDate.ToGregorianDate());

            GregorianDate oneSecondLater  = new GregorianDate(2009, 1, 1, 0, 0, 0);
            GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 59, 59);

            Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(leapSecondJulianDate).Seconds);
            Assert.AreEqual(1, leapSecondJulianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds);
        }
示例#5
0
        public void TestSecondsDifferenceAtLeapSecond()
        {
            JulianDate leapSecond = new JulianDate(2453736, 43232, TimeStandard.InternationalAtomicTime);
            JulianDate utcDate    = new JulianDate(2453736, 43232, TimeStandard.CoordinatedUniversalTime);

            Assert.AreEqual(-33, utcDate.SecondsDifference(leapSecond));
            Assert.AreEqual(33, leapSecond.SecondsDifference(utcDate));

            JulianDate secondBeforeLeapSecondUTC = leapSecond.SubtractSeconds(1).ToTimeStandard(TimeStandard.CoordinatedUniversalTime);
            JulianDate secondAfterLeapSecondUTC  = leapSecond.AddSeconds(1).ToTimeStandard(TimeStandard.CoordinatedUniversalTime);

            Assert.AreEqual(2, secondBeforeLeapSecondUTC.SecondsDifference(secondAfterLeapSecondUTC));
            Assert.AreEqual(2, secondAfterLeapSecondUTC.Subtract(secondBeforeLeapSecondUTC).Seconds);
        }
示例#6
0
        public void TestAddition()
        {
            JulianDate original = new JulianDate(2460000, 1000.0);
            Duration toAdd = Duration.FromSeconds(50.0);
            JulianDate added = original.Add(toAdd);
            Assert.AreEqual(2460000, added.Day);
            Assert.AreEqual(1050.0, added.SecondsOfDay);
            JulianDate subtracted = original.Subtract(toAdd);
            Assert.AreEqual(2460000, subtracted.Day);
            Assert.AreEqual(950.0, subtracted.SecondsOfDay);

            original = new JulianDate(2460000, 8382.1);
            toAdd = new Duration(1, 10.0);
            added = original + toAdd;
            Assert.AreEqual(2460001, added.Day);
            Assert.AreEqual(8392.1, added.SecondsOfDay);
            subtracted = original - toAdd;
            Assert.AreEqual(2459999, subtracted.Day);
            Assert.AreEqual(8372.1, subtracted.SecondsOfDay);

            original = new JulianDate(2460000, 86000.0);
            toAdd = Duration.FromSeconds(1000.0);
            added = original.Add(toAdd);
            Assert.AreEqual(2460001, added.Day);
            Assert.AreEqual(600.0, added.SecondsOfDay);
            subtracted = original.Subtract(toAdd);
            Assert.AreEqual(2460000, subtracted.Day);
            Assert.AreEqual(85000.0, subtracted.SecondsOfDay);
        }
        private void WorkerThread()
        {
            while (m_active)
            {
                JulianDate time = new JulianDate(DateTime.UtcNow);

                //FIXED WIDTH FORMAT
                //ID(12) X(20) Y(20) Z(20) QX(20) QY(20) QZ(20) QW(20) Marking(12) Symbology(16) Force(2)
                string[] records = File.ReadAllLines(Path.Combine(m_dataPath, "surveillance.txt"));

                foreach (string record in records)
                {
                    if (!m_active)
                    {
                        break;
                    }

                    string entityID = record.Substring(0, 12).Trim();
                    int delay = int.Parse(record.Substring(12, 4).Trim(), CultureInfo.InvariantCulture);
                    double x = double.Parse(record.Substring(16, 20).Trim(), CultureInfo.InvariantCulture);
                    double y = double.Parse(record.Substring(36, 20).Trim(), CultureInfo.InvariantCulture);
                    double z = double.Parse(record.Substring(56, 20).Trim(), CultureInfo.InvariantCulture);
                    double qx = double.Parse(record.Substring(76, 20).Trim(), CultureInfo.InvariantCulture);
                    double qy = double.Parse(record.Substring(96, 20).Trim(), CultureInfo.InvariantCulture);
                    double qz = double.Parse(record.Substring(116, 20).Trim(), CultureInfo.InvariantCulture);
                    double qw = double.Parse(record.Substring(136, 20).Trim(), CultureInfo.InvariantCulture);
                    string marking = record.Substring(156, 12).Trim();
                    string symbology = record.Substring(168, 16).Trim();
                    Force force = (Force)int.Parse(record.Substring(184, 2).Trim(), CultureInfo.InvariantCulture);

                    m_entities.Context.DoTransactionally(
                        delegate(Transaction transaction)
                        {
                            ExampleEntity entity = m_entities.GetEntityById(transaction, entityID);
                            if (entity == null)
                            {
                                entity = new ExampleEntity(m_entities.Context, entityID);
                                m_entities.Add(transaction, entity);
                            }

                            entity.LastUpdate.SetValue(transaction, time);
                            entity.LastUpdateDateTime.SetValue(transaction, time.ToDateTime());
                            entity.Marking.SetValue(transaction, marking);
                            entity.Orientation.SetValue(transaction, new UnitQuaternion(qw, qx, qy, qz));
                            entity.Position.SetValue(transaction, new Cartesian(x, y, z));
                            entity.Affiliation.SetValue(transaction, force);
                            entity.Symbology.SetValue(transaction, symbology);
                        });

                    if (delay > 0)
                    {
                        //Remove anything that hasn't been updated.

                        m_entities.Context.DoTransactionally(
                            delegate(Transaction transaction)
                            {
                                foreach (ExampleEntity entity in m_entities.GetEntities(transaction))
                                {
                                    if (time.Subtract(entity.LastUpdate.GetValue(transaction)).TotalSeconds > .5)
                                    {
                                        m_entities.Remove(transaction, entity);
                                    }
                                }
                            });

                        Thread.Sleep(delay);
                        time = time.AddSeconds((double)delay / 1000.0);
                    }
                }
            }
        }