public void CartesianValueSubsetWritesMultipleCartesianProperty() { var startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); using (Packet) using (var position = Packet.OpenPositionProperty()) using (var interval = position.OpenInterval()) { var dates = new List <JulianDate>(); var positions = new List <Cartesian>(); dates.Add(startDate); positions.Add(new Cartesian(1.0, 2.0, 3.0)); dates.Add(startDate.AddSeconds(60.0)); positions.Add(new Cartesian(4.0, 5.0, 6.0)); dates.Add(startDate.AddSeconds(120.0)); positions.Add(new Cartesian(7.0, 8.0, 9.0)); interval.WriteCartesian(dates, positions, 1, 1); } Assert.AreEqual("{\"position\":{\"epoch\":\"20120402T1201Z\",\"cartesian\":[0,4,5,6]}}", StringWriter.ToString()); }
public void TestShowPropertyInterval() { var startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); var stopDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 1, 0)); using (Packet) using (var billboard = Packet.OpenBillboardProperty()) using (var show = billboard.OpenShowProperty()) using (var showIntervals = show.OpenMultipleIntervals()) { using (var interval = showIntervals.OpenInterval(startDate, startDate.AddSeconds(1))) { interval.WriteBoolean(true); } using (var interval = showIntervals.OpenInterval(startDate.AddSeconds(1), startDate.AddSeconds(2))) { interval.WriteBoolean(false); } using (var interval = showIntervals.OpenInterval(startDate.AddSeconds(2), stopDate)) { interval.WriteBoolean(true); } } string interval1String = CesiumFormattingHelper.ToIso8601Interval(startDate, startDate.AddSeconds(1), Iso8601Format.Compact); string interval2String = CesiumFormattingHelper.ToIso8601Interval(startDate.AddSeconds(1), startDate.AddSeconds(2), Iso8601Format.Compact); string interval3String = CesiumFormattingHelper.ToIso8601Interval(startDate.AddSeconds(2), stopDate, Iso8601Format.Compact); Assert.AreEqual("{\"billboard\":{\"show\":[{\"interval\":\"" + interval1String + "\",\"boolean\":true}," + "{\"interval\":\"" + interval2String + "\",\"boolean\":false}," + "{\"interval\":\"" + interval3String + "\",\"boolean\":true}" + "]}}", StringWriter.ToString()); }
/// <summary> /// Generates a set of position, time and DV in x,y,z /// </summary> /// <returns></returns> private Tuple <List <JulianDate>, List <Motion <Cartesian> > > GenerateCartesianVelocitySet(Stage stage) { JulianDate date = new JulianDate(DateTime.Now); var dateList = new List <JulianDate>(); var motionList = new List <Motion <Cartesian> >(); foreach (var profiledata in stage.data.profiledata) { Tuple <float?, Motion <Cartesian> > result = null; try { //result = GenerateStageFrameData(profiledata); result = GenerateStageFrameData(profiledata); var timeChange = result.Item1; var motion = result.Item2; dateList.Add(date.AddSeconds(timeChange.Value)); motionList.Add(motion); } catch (Exception) { Console.WriteLine("null Error"); } //var result = GenerateStageFrameData(profiledata); } return(new Tuple <List <JulianDate>, List <Motion <Cartesian> > >(dateList, motionList)); }
public void TestAddSeconds() { // Make sure AddSeconds produces the correct answer in the correct time standard. JulianDate test = new JulianDate(2451912, 43200.0, TimeStandard.InternationalAtomicTime); JulianDate result = test.AddSeconds(45.123); Assert.AreEqual(TimeStandard.InternationalAtomicTime, result.Standard); Assert.AreEqual(2451912, result.Day); Assert.AreEqual(43245.123, result.SecondsOfDay); }
public void AddSecond() { JulianDate jd = new JulianDate(new DateTime(2003, 1, 1)); JulianDate jd1 = new JulianDate(jd); jd1.AddSeconds(24); Assert.That(jd1 - jd, Is.EqualTo(24.0 / (3600 * 24)).Within(0.00000000000001)); DateTime dt = jd1.ToDateTime(); Assert.That(dt.Second, Is.EqualTo(24)); }
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); }
public void TestHolesIntervals() { var startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); var stopDate = new JulianDate(new GregorianDate(2012, 4, 2, 13, 0, 0)); using (Packet) using (var polygon = Packet.OpenPolygonProperty()) using (var holes = polygon.OpenHolesProperty()) { using (var holesIntervals = holes.OpenMultipleIntervals()) { using (var interval = holesIntervals.OpenInterval(startDate, startDate.AddSeconds(60 * 30))) { var listOfHoles = new List <List <Cartographic> > { new List <Cartographic> { new Cartographic(1, 1, 0), new Cartographic(1, 2, 0), new Cartographic(2, 2, 0), }, new List <Cartographic> { new Cartographic(4, 4, 0), new Cartographic(4, 5, 0), new Cartographic(5, 5, 0), new Cartographic(5, 4, 0), }, }; interval.WriteCartographicDegrees(listOfHoles); } using (var interval = holesIntervals.OpenInterval(startDate.AddSeconds(60 * 30), stopDate)) { var listOfHoles = new List <List <Cartographic> > { new List <Cartographic> { new Cartographic(11, 1, 0), new Cartographic(11, 2, 0), new Cartographic(12, 2, 0), }, new List <Cartographic> { new Cartographic(14, 4, 0), new Cartographic(14, 5, 0), new Cartographic(15, 5, 0), new Cartographic(15, 4, 0), }, }; interval.WriteCartographicDegrees(listOfHoles); } } } Assert.AreEqual("{\"polygon\":{\"holes\":[" + "{\"interval\":\"20120402T12Z/20120402T1230Z\",\"cartographicDegrees\":[[1,1,0,1,2,0,2,2,0],[4,4,0,4,5,0,5,5,0,5,4,0]]}," + "{\"interval\":\"20120402T1230Z/20120402T13Z\",\"cartographicDegrees\":[[11,1,0,11,2,0,12,2,0],[14,4,0,14,5,0,15,5,0,15,4,0]]}" + "]}}", StringWriter.ToString()); }
public void CartesianValueWritesMultipleCartesianProperty() { JulianDate startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); using (Packet) using (PositionCesiumWriter position = Packet.OpenPositionProperty()) using (PositionCesiumWriter interval = position.OpenInterval()) { var dates = new List <JulianDate>(); var positions = new List <Cartesian>(); dates.Add(startDate); positions.Add(new Cartesian(1.1, 2.2, 3.3)); dates.Add(startDate.AddSeconds(60.0)); positions.Add(new Cartesian(4.4, 5.5, 6.6)); interval.WriteCartesian(dates, positions); } Assert.AreEqual("{\"position\":{\"epoch\":\"20120402T12Z\",\"cartesian\":[0,1.1,2.2,3.3,60,4.4,5.5,6.6]}}", StringWriter.ToString()); }
public void CartographicRadiansValueWritesMultipleCartographicRadiansProperty() { JulianDate startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); using (Packet) using (PositionCesiumWriter position = Packet.OpenPositionProperty()) using (PositionCesiumWriter interval = position.OpenInterval()) { var dates = new List <JulianDate>(); var positions = new List <Cartographic>(); dates.Add(startDate); positions.Add(new Cartographic(1.0, 2.0, 3.0)); dates.Add(startDate.AddSeconds(60.0)); positions.Add(new Cartographic(4.0, 5.0, 6.0)); interval.WriteCartographicRadians(dates, positions); } Assert.AreEqual("{\"position\":{\"epoch\":\"20120402T12Z\",\"cartographicRadians\":[0.0,1.0,2.0,3.0,60.0,4.0,5.0,6.0]}}", StringWriter.ToString()); }
public void TestScaleByDistancePropertySamples() { JulianDate startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); using (Packet) using (BillboardCesiumWriter billboard = Packet.OpenBillboardProperty()) using (BillboardCesiumWriter interval = billboard.OpenInterval()) using (NearFarScalarCesiumWriter scaleByDistance = interval.OpenScaleByDistanceProperty()) { var dates = new List <JulianDate>(); var values = new List <NearFarScalar>(); dates.Add(startDate); values.Add(new NearFarScalar(100.0, 1.0, 200.0, 2.0)); dates.Add(startDate.AddSeconds(60.0)); values.Add(new NearFarScalar(200.0, 1.0, 300.0, 2.0)); scaleByDistance.WriteNearFarScalar(dates, values); } Assert.AreEqual("{\"billboard\":{\"scaleByDistance\":{\"epoch\":\"20120402T12Z\",\"nearFarScalar\":[0,100,1,200,2,60,200,1,300,2]}}}", StringWriter.ToString()); }
/// <summary> /// 从Table表中,创建新的PathPrimitive /// <para>表中提供的位置、速度要与参考系一致</para> /// </summary> /// <param name="dt">表名</param> /// <param name="colNames">表列名称(t,x,y,z,Vx,Vy,Vz)</param> /// <param name="frame">坐标系</param> /// <returns></returns> public static PathPrimitive CreatePathPrimitiveFromTable(DataTable dt, JulianDate jd0, string[] colNames, ReferenceFrame frame) { try { DateMotionCollection <Cartesian> ephemeris = new DateMotionCollection <Cartesian> (); //将Table中的相应参数读入 JulianDate jd; Cartesian R, V; foreach (DataRow dr in dt.Rows) { jd = jd0.AddSeconds((double)dr[colNames[0]]); R = new Cartesian((double)dr[colNames[1]], (double)dr[colNames[2]], (double)dr[colNames[3]]); V = new Cartesian((double)dr[colNames[4]], (double)dr[colNames[5]], (double)dr[colNames[6]]); ephemeris.Add(jd, R, V); } return(CreatePathPrimitiveFromEphemeris(ephemeris, frame)); } catch (Exception ex) { throw new Exception(ex.Message + "\n" + "从Table中创建PathPrimitive出错!"); } }
public void CustomPropertyCartesianSampled() { using (Packet) using (var customPropertiesWriter = Packet.OpenPropertiesProperty()) using (var customPropertyWriter = customPropertiesWriter.OpenCustomPropertyProperty("custom_property")) { var dates = new List <JulianDate>(); var values = new List <Cartesian>(); dates.Add(m_startDate); values.Add(new Cartesian(1.0, 2.0, 3.0)); dates.Add(m_startDate.AddSeconds(60.0)); values.Add(new Cartesian(4.0, 5.0, 6.0)); dates.Add(m_startDate.AddSeconds(120.0)); values.Add(new Cartesian(7.0, 8.0, 9.0)); customPropertyWriter.WriteCartesian(dates, values); } Assert.AreEqual("{\"properties\":{\"custom_property\":{\"epoch\":\"" + m_isoStartString + "\",\"cartesian\":[0,1,2,3,60,4,5,6,120,7,8,9]}}}", StringWriter.ToString()); }
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); } } } }