コード例 #1
0
        public void TestEqualityWithWrongType()
        {
            UnitQuaternion first  = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            Cartographic   second = new Cartographic(1.0, 2.0, 3.0);

            Assert.IsFalse(first.Equals(second));
        }
コード例 #2
0
 public void TestFromInfinity()
 {
     Assert.Throws <NotFiniteNumberException>(() =>
     {
         var unused = new UnitQuaternion(double.PositiveInfinity, 0.0, 0.0, 0.0);
     });
 }
コード例 #3
0
        /// <summary>
        /// Writes the time-tagged <see cref="UnitQuaternion"/> collection as an array in
        /// [Time, X, Y, Z, W] order.
        /// Times are epoch seconds since an epoch that is determined from the first date to be written.
        /// The epoch property is written as well.
        /// </summary>
        /// <param name="output">The stream to which to write the array.</param>
        /// <param name="propertyName">The name of the property to write.</param>
        /// <param name="dates">The dates at which the value is specified.</param>
        /// <param name="values">The corresponding value for each date.</param>
        /// <param name="startIndex">The index of the first element to use in the <paramref name="values"/> collection.</param>
        /// <param name="length">The number of elements to use from the <paramref name="values"/> collection.</param>
        public static void WriteUnitQuaternion(CesiumOutputStream output, string propertyName, IList <JulianDate> dates, IList <UnitQuaternion> values, int startIndex, int length)
        {
            if (dates.Count != values.Count)
            {
                throw new ArgumentException(CesiumLocalization.MismatchedNumberOfDatesAndValues, "values");
            }

            JulianDate epoch = GetAndWriteEpoch(output, dates, startIndex, length);

            output.WritePropertyName(propertyName);
            output.WriteStartSequence();
            int last = startIndex + length;

            for (int i = startIndex; i < last; ++i)
            {
                output.WriteValue(epoch.SecondsDifference(dates[i]));
                UnitQuaternion quaternion = values[i];
                output.WriteValue(quaternion.X);
                output.WriteValue(quaternion.Y);
                output.WriteValue(quaternion.Z);
                output.WriteValue(quaternion.W);
                output.WriteLineBreak();
            }

            output.WriteEndSequence();
        }
コード例 #4
0
        public void TestEqualityWithWrongType()
        {
            UnitQuaternion first  = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            Cartographic   second = new Cartographic(1.0, 2.0, 3.0);

            // ReSharper disable once SuspiciousTypeConversion.Global
            Assert.IsFalse(first.Equals(second));
        }
コード例 #5
0
 public void TestHoldValue()
 {
     UnitQuaternion test = new UnitQuaternion(2.0, 4.0, 7.0, 10.0);
     Assert.AreEqual(2.0 / 13.0, test.W);
     Assert.AreEqual(4.0 / 13.0, test.X);
     Assert.AreEqual(7.0 / 13.0, test.Y);
     Assert.AreEqual(10.0 / 13.0, test.Z);
 }
コード例 #6
0
        public void TestNegation()
        {
            UnitQuaternion u = -new UnitQuaternion(2.0, 4.0, 7.0, 10.0);

            Assert.AreEqual(-2.0 / 13.0, u.W);
            Assert.AreEqual(-4.0 / 13.0, u.X);
            Assert.AreEqual(-7.0 / 13.0, u.Y);
            Assert.AreEqual(-10.0 / 13.0, u.Z);
        }
コード例 #7
0
 /// <summary>
 /// Writes a <see cref="UnitQuaternion"/> as an array in [X, Y, Z, W] order.
 /// </summary>
 /// <param name="output">The stream to which to write the value.</param>
 /// <param name="value">The value to write.</param>
 public static void WriteUnitQuaternion(CesiumOutputStream output, UnitQuaternion value)
 {
     output.WriteStartSequence();
     output.WriteValue(value.X);
     output.WriteValue(value.Y);
     output.WriteValue(value.Z);
     output.WriteValue(value.W);
     output.WriteEndSequence();
 }
コード例 #8
0
        public void TestGetHashCode()
        {
            UnitQuaternion object1 = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            UnitQuaternion object2 = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            UnitQuaternion object3 = new UnitQuaternion(1.0, 2.0, 3.0, 4.1);

            Assert.AreEqual(object1.GetHashCode(), object2.GetHashCode());
            Assert.AreNotEqual(object1.GetHashCode(), object3.GetHashCode());
        }
コード例 #9
0
        public void TestIdentity()
        {
            UnitQuaternion identity = UnitQuaternion.Identity;

            Assert.AreEqual(1.0, identity.W);
            Assert.AreEqual(0.0, identity.X);
            Assert.AreEqual(0.0, identity.Y);
            Assert.AreEqual(0.0, identity.Z);
        }
コード例 #10
0
 public void TestConjugate()
 {
     UnitQuaternion original = new UnitQuaternion(2.0, 4.0, 7.0, 10.0);
     UnitQuaternion conjugate = original.Conjugate();
     Assert.AreEqual(2.0 / 13.0, conjugate.W);
     Assert.AreEqual(-4.0 / 13.0, conjugate.X);
     Assert.AreEqual(-7.0 / 13.0, conjugate.Y);
     Assert.AreEqual(-10.0 / 13.0, conjugate.Z);
 }
コード例 #11
0
        public void TestHoldValue()
        {
            UnitQuaternion test = new UnitQuaternion(2.0, 4.0, 7.0, 10.0);

            Assert.AreEqual(2.0 / 13.0, test.W);
            Assert.AreEqual(4.0 / 13.0, test.X);
            Assert.AreEqual(7.0 / 13.0, test.Y);
            Assert.AreEqual(10.0 / 13.0, test.Z);
        }
コード例 #12
0
 public void TestInitializeAndReturnMagnitude()
 {
     double magnitude;
     UnitQuaternion test = new UnitQuaternion(2.0, 4.0, 7.0, 10.0, out magnitude);
     Assert.AreEqual(2.0 / 13.0, test.W, Constants.Epsilon15);
     Assert.AreEqual(4.0 / 13.0, test.X, Constants.Epsilon15);
     Assert.AreEqual(7.0 / 13.0, test.Y, Constants.Epsilon15);
     Assert.AreEqual(10.0 / 13.0, test.Z, Constants.Epsilon15);
     Assert.AreEqual(13.0, magnitude, Constants.Epsilon15);
 }
コード例 #13
0
        public void TestConjugate()
        {
            UnitQuaternion original  = new UnitQuaternion(2.0, 4.0, 7.0, 10.0);
            UnitQuaternion conjugate = original.Conjugate();

            Assert.AreEqual(2.0 / 13.0, conjugate.W);
            Assert.AreEqual(-4.0 / 13.0, conjugate.X);
            Assert.AreEqual(-7.0 / 13.0, conjugate.Y);
            Assert.AreEqual(-10.0 / 13.0, conjugate.Z);
        }
コード例 #14
0
        public void MultipleNodeTransformations()
        {
            const string expectedNodeName1    = "node1";
            var          expectedScale1       = new Cartesian(1.0, 2.0, 3.0);
            var          expectedRotation1    = new UnitQuaternion(1.0, 0.0, 0.0, 0.0);
            var          expectedTranslation1 = new Cartesian(4.0, 5.0, 6.0);
            const string expectedNodeName2    = "node2";
            var          expectedScale2       = new Cartesian(4.0, 5.0, 6.0);
            var          expectedRotation2    = new UnitQuaternion(0.0, 0.0, 0.0, 1.0);
            var          expectedTranslation2 = new Cartesian(7.0, 8.0, 9.0);

            using (Packet)
                using (var modelWriter = Packet.OpenModelProperty())
                    using (var nodeTransformationsWriter = modelWriter.OpenNodeTransformationsProperty())
                    {
                        using (var nodeTransformationWriter = nodeTransformationsWriter.OpenNodeTransformationProperty(expectedNodeName1))
                        {
                            nodeTransformationWriter.WriteScaleProperty(expectedScale1);
                            nodeTransformationWriter.WriteRotationProperty(expectedRotation1);
                            nodeTransformationWriter.WriteTranslationProperty(expectedTranslation1);
                        }

                        using (var nodeTransformationWriter = nodeTransformationsWriter.OpenNodeTransformationProperty(expectedNodeName2))
                        {
                            nodeTransformationWriter.WriteScaleProperty(expectedScale2);
                            nodeTransformationWriter.WriteRotationProperty(expectedRotation2);
                            nodeTransformationWriter.WriteTranslationProperty(expectedTranslation2);
                        }
                    }

            AssertExpectedJson(PacketCesiumWriter.ModelPropertyName, new Dictionary <string, object>
            {
                {
                    ModelCesiumWriter.NodeTransformationsPropertyName, new Dictionary <string, object>
                    {
                        {
                            expectedNodeName1, new Dictionary <string, object>
                            {
                                { NodeTransformationCesiumWriter.ScalePropertyName, expectedScale1 },
                                { NodeTransformationCesiumWriter.RotationPropertyName, expectedRotation1 },
                                { NodeTransformationCesiumWriter.TranslationPropertyName, expectedTranslation1 },
                            }
                        },
                        {
                            expectedNodeName2, new Dictionary <string, object>
                            {
                                { NodeTransformationCesiumWriter.ScalePropertyName, expectedScale2 },
                                { NodeTransformationCesiumWriter.RotationPropertyName, expectedRotation2 },
                                { NodeTransformationCesiumWriter.TranslationPropertyName, expectedTranslation2 },
                            }
                        },
                    }
                },
            });
        }
コード例 #15
0
        public void TestEquality()
        {
            UnitQuaternion first  = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            UnitQuaternion second = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);

            Assert.AreEqual(first, second);
            Assert.AreEqual(second, first);
            Assert.IsTrue(first == second);
            Assert.IsTrue(second == first);
            Assert.IsFalse(first != second);
            Assert.IsFalse(second != first);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(second.Equals(first));

            second = new UnitQuaternion(1.1, 2.0, 3.0, 4.0);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));

            second = new UnitQuaternion(1.0, 2.2, 3.0, 4.0);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));


            second = new UnitQuaternion(1.0, 2.0, 3.3, 4.0);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));

            second = new UnitQuaternion(1.0, 2.0, 3.3, 4.4);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
        }
コード例 #16
0
        public void TestEquality()
        {
            UnitQuaternion first = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            UnitQuaternion second = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            Assert.AreEqual(first, second);
            Assert.AreEqual(second, first);
            Assert.IsTrue(first == second);
            Assert.IsTrue(second == first);
            Assert.IsFalse(first != second);
            Assert.IsFalse(second != first);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(second.Equals(first));

            second = new UnitQuaternion(1.1, 2.0, 3.0, 4.0);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));

            second = new UnitQuaternion(1.0, 2.2, 3.0, 4.0);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));


            second = new UnitQuaternion(1.0, 2.0, 3.3, 4.0);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));

            second = new UnitQuaternion(1.0, 2.0, 3.3, 4.4);
            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(second, first);
            Assert.IsFalse(first == second);
            Assert.IsFalse(second == first);
            Assert.IsTrue(first != second);
            Assert.IsTrue(second != first);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
        }
コード例 #17
0
        public void TestEqualsEpsilon()
        {
            UnitQuaternion first  = new UnitQuaternion(1.0, 1.0, 1.0, 1.0);
            UnitQuaternion second = new UnitQuaternion(0.99, 1.0, 1.0, 1.01);

            Assert.IsTrue(second.EqualsEpsilon(first, 1e-1));
            Assert.IsTrue(second.EqualsEpsilon(first, 1e-2));
            Assert.IsFalse(second.EqualsEpsilon(first, 1e-3));
            Assert.IsFalse(second.EqualsEpsilon(first, 1e-4));
            Assert.IsFalse(second.EqualsEpsilon(first, 1e-5));
        }
コード例 #18
0
        public void TestInitializeAndReturnMagnitude()
        {
            double         magnitude;
            UnitQuaternion test = new UnitQuaternion(2.0, 4.0, 7.0, 10.0, out magnitude);

            Assert.AreEqual(2.0 / 13.0, test.W, Constants.Epsilon15);
            Assert.AreEqual(4.0 / 13.0, test.X, Constants.Epsilon15);
            Assert.AreEqual(7.0 / 13.0, test.Y, Constants.Epsilon15);
            Assert.AreEqual(10.0 / 13.0, test.Z, Constants.Epsilon15);
            Assert.AreEqual(13.0, magnitude, Constants.Epsilon15);
        }
コード例 #19
0
        public void TestToString()
        {
            UnitQuaternion test1 = new UnitQuaternion(1.0, 0.0, 0.0, 0.0);
            UnitQuaternion test2 = new UnitQuaternion(0.0, 1.0, 0.0, 0.0);
            UnitQuaternion test3 = new UnitQuaternion(0.0, 0.0, 1.0, 0.0);
            UnitQuaternion test4 = new UnitQuaternion(0.0, 0.0, 0.0, 1.0);

            Assert.AreEqual("1, 0, 0, 0", test1.ToString());
            Assert.AreEqual("0, 1, 0, 0", test2.ToString());
            Assert.AreEqual("0, 0, 1, 0", test3.ToString());
            Assert.AreEqual("0, 0, 0, 1", test4.ToString());
        }
コード例 #20
0
        public void TestFromQuaternion()
        {
            UnitQuaternion quaternion = UnitQuaternion.Identity;

            Matrix3By3 matrix = new Matrix3By3(quaternion);

            Assert.AreEqual(1.0, matrix.M11);
            Assert.AreEqual(0.0, matrix.M12);
            Assert.AreEqual(0.0, matrix.M13);
            Assert.AreEqual(0.0, matrix.M21);
            Assert.AreEqual(1.0, matrix.M22);
            Assert.AreEqual(0.0, matrix.M23);
            Assert.AreEqual(0.0, matrix.M31);
            Assert.AreEqual(0.0, matrix.M32);
            Assert.AreEqual(1.0, matrix.M33);
        }
コード例 #21
0
        public void TestMultiplicationByUnitQuaternion()
        {
            // Choose quaternions whose vector portions (x, y, z) do not produce zeros
            // when dotted or crossed.  They should also have non-zero scalar (w) portions as well.
            UnitQuaternion first  = new UnitQuaternion(7.0, 2.0, 3.0, 6.0);
            UnitQuaternion second = new UnitQuaternion(7.0, 2.0, 3.0, 6.0);

            UnitQuaternion result = first.Multiply(second);

            Assert.AreEqual(0.0 / 7.0, result.W, Constants.Epsilon15);
            Assert.AreEqual(2.0 / 7.0, result.X, Constants.Epsilon15);
            Assert.AreEqual(3.0 / 7.0, result.Y, Constants.Epsilon15);
            Assert.AreEqual(6.0 / 7.0, result.Z, Constants.Epsilon15);

            result = first * second;
            Assert.AreEqual(0.0 / 7.0, result.W, Constants.Epsilon15);
            Assert.AreEqual(2.0 / 7.0, result.X, Constants.Epsilon15);
            Assert.AreEqual(3.0 / 7.0, result.Y, Constants.Epsilon15);
            Assert.AreEqual(6.0 / 7.0, result.Z, Constants.Epsilon15);
        }
コード例 #22
0
        private void _TestFromMatrix3By3(double angle, Cartesian axis)
        {
            Cartesian unit = axis.Normalize();

            double c = Math.Cos(angle);
            double s = Math.Sin(angle);

            double w = c;
            double x = s * unit.X;
            double y = s * unit.Y;
            double z = s * unit.Z;

            UnitQuaternion quaternion = new UnitQuaternion(w, x, y, z);
            Matrix3By3     matrix     = new Matrix3By3(quaternion);

            UnitQuaternion test = new UnitQuaternion(matrix);

            Assert.AreEqual(w, quaternion.W, Constants.Epsilon15);
            Assert.AreEqual(x, quaternion.X, Constants.Epsilon15);
            Assert.AreEqual(y, quaternion.Y, Constants.Epsilon15);
            Assert.AreEqual(z, quaternion.Z, Constants.Epsilon15);
        }
コード例 #23
0
        private static string FormatValue([NotNull] object value)
        {
            if (value is bool)
            {
                // in C#, booleans format with a capital first letter
                return(value.ToString().ToLowerInvariant());
            }
            if (value is double)
            {
                double d = (double)value;
                return(d.ToString(CultureInfo.InvariantCulture));
            }
            if (value is string)
            {
                return(string.Format("\"{0}\"", value));
            }

            if (value is Color)
            {
                Color color = (Color)value;
                return(CreateExpectedJson(new Dictionary <string, object>
                {
                    { "rgba", new List <object> {
                          color.R, color.G, color.B, color.A
                      } },
                }));
            }

            if (value is NearFarScalar)
            {
                NearFarScalar nearFarScalar = (NearFarScalar)value;
                return(CreateExpectedJson(new Dictionary <string, object>
                {
                    { "nearFarScalar", new List <object> {
                          nearFarScalar.NearDistance, nearFarScalar.NearValue, nearFarScalar.FarDistance, nearFarScalar.FarValue
                      } },
                }));
            }

            if (value is Rectangular)
            {
                Rectangular rectangular = (Rectangular)value;
                return(CreateExpectedJson(new Dictionary <string, object>
                {
                    { "cartesian2", new List <object> {
                          rectangular.X, rectangular.Y
                      } },
                }));
            }

            if (value is Cartesian)
            {
                Cartesian cartesian = (Cartesian)value;
                return(CreateExpectedJson(new Dictionary <string, object>
                {
                    { "cartesian", new List <object> {
                          cartesian.X, cartesian.Y, cartesian.Z
                      } },
                }));
            }
            if (value is Cartographic)
            {
                Cartographic cartographic = (Cartographic)value;
                return(CreateExpectedJson(new Dictionary <string, object>
                {
                    { "cartographicRadians", new List <object> {
                          cartographic.Longitude, cartographic.Latitude, cartographic.Height
                      } },
                }));
            }

            if (value is UnitQuaternion)
            {
                UnitQuaternion unitQuaternion = (UnitQuaternion)value;
                return(CreateExpectedJson(new Dictionary <string, object>
                {
                    { "unitQuaternion", new List <object> {
                          unitQuaternion.X, unitQuaternion.Y, unitQuaternion.Z, unitQuaternion.W
                      } },
                }));
            }

            var dictionary = value as IDictionary <string, object>;

            if (dictionary != null)
            {
                return(CreateExpectedJson(dictionary));
            }

            var list = value as IEnumerable <object>;

            if (list != null)
            {
                var builder = new StringBuilder();
                builder.Append('[');
                foreach (object o in list)
                {
                    builder.Append(FormatValue(o))
                    .Append(',');
                }
                builder[builder.Length - 1] = ']';
                return(builder.ToString());
            }

            return(value.ToString());
        }
コード例 #24
0
 public void TestFromInfinity()
 {
     UnitQuaternion first = new UnitQuaternion(Double.PositiveInfinity, 0.0, 0.0, 0.0);
 }
コード例 #25
0
 public void TestIndexTooLow()
 {
     UnitQuaternion first = new UnitQuaternion(7.0, 2.0, 3.0, 6.0);
     double bad = first[-1];
 }
コード例 #26
0
 public void TestIndexTooLow()
 {
     UnitQuaternion first = new UnitQuaternion(7.0, 2.0, 3.0, 6.0);
     double         bad   = first[-1];
 }
コード例 #27
0
 public void TestFromInfinity()
 {
     UnitQuaternion first = new UnitQuaternion(Double.PositiveInfinity, 0.0, 0.0, 0.0);
 }
コード例 #28
0
 /// <summary>
 /// Writes a value for the <code>orientation</code> property as a <code>unitQuaternion</code> value.  The <code>orientation</code> property specifies the orientation of the object in the world.  The orientation has no direct visual representation, but it is used to orient models, cones, and pyramids attached to the object.
 /// </summary>
 /// <param name="value">The value.</param>
 public void WriteOrientationProperty(UnitQuaternion value)
 {
     using (var writer = OpenOrientationProperty())
     {
         writer.WriteUnitQuaternion(value);
     }
 }
コード例 #29
0
 /// <summary>
 /// Writes a <see cref="UnitQuaternion"/> as an array in [X, Y, Z, W] order.
 /// </summary>
 /// <param name="output">The stream to which to write the value.</param>
 /// <param name="value">The value to write.</param>
 public static void WriteUnitQuaternion(CesiumOutputStream output, UnitQuaternion value)
 {
     output.WriteStartSequence();
     output.WriteValue(value.X);
     output.WriteValue(value.Y);
     output.WriteValue(value.Z);
     output.WriteValue(value.W);
     output.WriteEndSequence();
 }
コード例 #30
0
        private void _TestFromMatrix3By3(double angle, Cartesian axis)
        {
            Cartesian unit = axis.Normalize();

            double c = Math.Cos(angle);
            double s = Math.Sin(angle);

            double w = c;
            double x = s * unit.X;
            double y = s * unit.Y;
            double z = s * unit.Z;

            UnitQuaternion quaternion = new UnitQuaternion(w, x, y, z);
            Matrix3By3 matrix = new Matrix3By3(quaternion);

            UnitQuaternion test = new UnitQuaternion(matrix);

            Assert.AreEqual(w, quaternion.W, Constants.Epsilon15);
            Assert.AreEqual(x, quaternion.X, Constants.Epsilon15);
            Assert.AreEqual(y, quaternion.Y, Constants.Epsilon15);
            Assert.AreEqual(z, quaternion.Z, Constants.Epsilon15);
        }
コード例 #31
0
        public void TestCompleteExample()
        {
            var date = new JulianDate(2451545.0);

            const string id           = "MyID";
            var          availability = new TimeInterval(date, date.AddDays(2.0));

            var interval1 = new TimeInterval(date, date.AddDays(1.0));

            var interval1Position    = new Cartesian(1.0, 2.0, 3.0);
            var interval1Orientation = new UnitQuaternion(1, 0, 0, 0);

            var interval2 = new TimeInterval(date.AddDays(1.0), date.AddDays(2.0));

            var interval2SampleDates = new List <JulianDate>
            {
                date.AddDays(1.0),
                date.AddDays(1.5),
                date.AddDays(2.0)
            };

            var interval2SamplePositions = new List <Cartographic>
            {
                Cartographic.Zero,
                new Cartographic(1.0, 0.0, 0.0),
                new Cartographic(0.0, 1.0, 0.0)
            };
            var interval2SampleOrientations = new List <UnitQuaternion>
            {
                UnitQuaternion.Identity,
                new UnitQuaternion(0.0, 1.0, 0.0, 0.0),
                new UnitQuaternion(0.0, 0.0, 1.0, 0.0)
            };

            const CesiumInterpolationAlgorithm orientationInterpolationAlgorithm = CesiumInterpolationAlgorithm.Linear;
            const int orientationInterpolationDegree = 1;

            var outputStream = new CesiumOutputStream(StringWriter)
            {
                PrettyFormatting = true
            };
            var writer = new CesiumStreamWriter();

            using (var packet = writer.OpenPacket(outputStream))
            {
                packet.WriteId(id);
                packet.WriteAvailability(availability);

                using (var positionWriter = packet.OpenPositionProperty())
                    using (var intervalListWriter = positionWriter.OpenMultipleIntervals())
                    {
                        using (var interval = intervalListWriter.OpenInterval())
                        {
                            interval.WriteInterval(interval1);
                            interval.WriteCartesian(interval1Position);
                        }

                        using (var interval = intervalListWriter.OpenInterval(interval2.Start, interval2.Stop))
                        {
                            interval.WriteCartographicRadians(interval2SampleDates, interval2SamplePositions);
                        }
                    }

                using (var orientationWriter = packet.OpenOrientationProperty())
                    using (var intervalListWriter = orientationWriter.OpenMultipleIntervals())
                    {
                        using (var interval = intervalListWriter.OpenInterval())
                        {
                            interval.WriteInterval(interval1);
                            interval.WriteUnitQuaternion(interval1Orientation);
                        }

                        using (var interval = intervalListWriter.OpenInterval(interval2.Start, interval2.Stop))
                        {
                            interval.WriteInterpolationAlgorithm(orientationInterpolationAlgorithm);
                            interval.WriteInterpolationDegree(orientationInterpolationDegree);

                            interval.WriteUnitQuaternion(interval2SampleDates, interval2SampleOrientations);
                        }
                    }
            }

            Console.WriteLine(StringWriter.ToString());
        }
コード例 #32
0
        public void TestMultiplicationByUnitQuaternion()
        {
            // Choose quaternions whose vector portions (x, y, z) do not produce zeros
            // when dotted or crossed.  They should also have non-zero scalar (w) portions as well.
            UnitQuaternion first = new UnitQuaternion(7.0, 2.0, 3.0, 6.0);
            UnitQuaternion second = new UnitQuaternion(7.0, 2.0, 3.0, 6.0);

            UnitQuaternion result = first.Multiply(second);
            Assert.AreEqual(0.0 / 7.0, result.W, Constants.Epsilon15);
            Assert.AreEqual(2.0 / 7.0, result.X, Constants.Epsilon15);
            Assert.AreEqual(3.0 / 7.0, result.Y, Constants.Epsilon15);
            Assert.AreEqual(6.0 / 7.0, result.Z, Constants.Epsilon15);

            result = first * second;
            Assert.AreEqual(0.0 / 7.0, result.W, Constants.Epsilon15);
            Assert.AreEqual(2.0 / 7.0, result.X, Constants.Epsilon15);
            Assert.AreEqual(3.0 / 7.0, result.Y, Constants.Epsilon15);
            Assert.AreEqual(6.0 / 7.0, result.Z, Constants.Epsilon15);
        }
コード例 #33
0
        public void TestToString()
        {
            UnitQuaternion test1 = new UnitQuaternion(1.0, 0.0, 0.0, 0.0);
            UnitQuaternion test2 = new UnitQuaternion(0.0, 1.0, 0.0, 0.0);
            UnitQuaternion test3 = new UnitQuaternion(0.0, 0.0, 1.0, 0.0);
            UnitQuaternion test4 = new UnitQuaternion(0.0, 0.0, 0.0, 1.0);

            Assert.AreEqual("1, 0, 0, 0", test1.ToString());
            Assert.AreEqual("0, 1, 0, 0", test2.ToString());
            Assert.AreEqual("0, 0, 1, 0", test3.ToString());
            Assert.AreEqual("0, 0, 0, 1", test4.ToString());
        }
コード例 #34
0
        /// <summary>
        /// Create a Platform for the requested satellite using a TLE for position.
        /// The satellite will be visually represented by a labeled glTF model,
        /// the satellite's orbit will be shown, and vectors will be drawn for
        /// the body axes of the satellite, plus a vector indicating the direction
        /// of the sun.
        /// </summary>
        private void CreateSatellite()
        {
            // Get the current TLE for the given satellite identifier.
            var tleList = TwoLineElementSetHelper.GetTles(m_satelliteIdentifier, JulianDate.Now);

            // Use the epoch of the first TLE, since the TLE may have been loaded from offline data.
            m_epoch = tleList[0].Epoch;

            // Propagate the TLE and use that as the satellite's location point.
            var locationPoint = new Sgp4Propagator(tleList).CreatePoint();

            m_satellite = new Platform
            {
                Name          = "Satellite " + m_satelliteIdentifier,
                LocationPoint = locationPoint,
                // Orient the satellite using Vehicle Velocity Local Horizontal (VVLH) axes.
                OrientationAxes = new AxesVehicleVelocityLocalHorizontal(m_earth.FixedFrame, locationPoint),
            };

            // Set the identifier for the satellite in the CZML document.
            m_satellite.Extensions.Add(new IdentifierExtension(m_satelliteIdentifier));

            // Configure a glTF model for the satellite.
            m_satellite.Extensions.Add(new ModelGraphicsExtension(new ModelGraphics
            {
                // Link to a binary glTF file.
                Model = new CesiumResource(GetModelUri("satellite.glb"), CesiumResourceBehavior.LinkTo),
                // By default, Cesium plays all animations in the model simultaneously, which is not desirable.
                RunAnimations = false,
            }));

            // Configure a label for the satellite.
            m_satellite.Extensions.Add(new LabelGraphicsExtension(new LabelGraphics
            {
                // Use the name of the satellite as the text of the label.
                Text = m_satellite.Name,
                // Change the color of the label after 12 hours. This demonstrates specifying that
                // a value varies over time using intervals.
                FillColor = new TimeIntervalCollection <Color>
                {
                    // Green for the first half day...
                    new TimeInterval <Color>(JulianDate.MinValue, m_epoch.AddDays(0.5), Color.Green, true, false),
                    // Red thereafter.
                    new TimeInterval <Color>(m_epoch.AddDays(0.5), JulianDate.MaxValue, Color.Red, false, true),
                },
                // Only show label when camera is far enough from the satellite,
                // to avoid visually clashing with the model.
                DistanceDisplayCondition = new Bounds(1000.0, double.MaxValue),
            }));

            // Configure graphical display of the orbital path of the satellite.
            m_satellite.Extensions.Add(new PathGraphicsExtension(new PathGraphics
            {
                // Configure the visual appearance of the line.
                Material = new PolylineOutlineMaterialGraphics
                {
                    Color        = Color.White,
                    OutlineWidth = 1.0,
                    OutlineColor = Color.Black,
                },
                Width = 2.0,
                // Lead and Trail time indicate how much of the path to render.
                LeadTime  = Duration.FromMinutes(44.0).TotalSeconds,
                TrailTime = Duration.FromMinutes(44.0).TotalSeconds,
            }));

            // Create vectors for the X, Y, and Z axes of the satellite.
            m_satelliteXAxis = CreateAxesVector(m_satellite, CartesianElement.X, Color.Green, "SatelliteX");
            m_satelliteYAxis = CreateAxesVector(m_satellite, CartesianElement.Y, Color.Red, "SatelliteY");
            m_satelliteZAxis = CreateAxesVector(m_satellite, CartesianElement.Z, Color.Blue, "SatelliteZ");

            // Create a vector from the satellite to the Sun.

            // Compute the vector from the satellite's location to the Sun's center of mass.
            var sunCenterOfMassPoint = CentralBodiesFacet.GetFromContext().Sun.CenterOfMassPoint;
            var vectorSatelliteToSun = new VectorTrueDisplacement(m_satellite.LocationPoint, sunCenterOfMassPoint);

            // Create the visual vector.
            m_satelliteSunVector = new GraphicalVector
            {
                LocationPoint  = m_satellite.LocationPoint,
                Vector         = vectorSatelliteToSun,
                VectorGraphics = new VectorGraphics
                {
                    Length = 5.0,
                    Color  = Color.Yellow,
                },
            };

            // Set the identifier for the vector in the CZML document.
            m_satelliteSunVector.Extensions.Add(new IdentifierExtension("SunVector"));

            // Orient the solar panels on the satellite model to point at the sun.
            var satelliteYVector = m_satellite.OrientationAxes.GetVectorElement(CartesianElement.Y);

            // allow only Z axis to rotate to follow sun vector. Constrain sun vector to Y, and satellite Y vector to X.
            var constrainedAxes = new AxesAlignedConstrained(satelliteYVector, AxisIndicator.First, vectorSatelliteToSun, AxisIndicator.Second);

            // Satellite axes are Vehicle Velocity Local Horizontal (VVLH) axes, where X is forward and Z is down,
            // but Cesium model axes are Z forward, Y up. So, create an axes rotates to the Cesium model axes.
            var offset = new UnitQuaternion(new ElementaryRotation(AxisIndicator.First, -Math.PI / 2)) *
                         new UnitQuaternion(new ElementaryRotation(AxisIndicator.Third, Math.PI / 2));
            var cesiumModelAxes = new AxesFixedOffset(m_satellite.OrientationAxes, offset);

            // The rotation will be from the Cesium model axes to the constrained axes.
            var solarPanelRotationAxes = new AxesInAxes(constrainedAxes, cesiumModelAxes);

            // Add a node transformation to rotate the SolarPanels node of the model.
            m_satellite.Extensions.GetByType <ModelGraphicsExtension>().ModelGraphics.NodeTransformations = new Dictionary <string, NodeTransformationGraphics>
            {
                {
                    "SolarPanels", new NodeTransformationGraphics
                    {
                        Rotation = new AxesCesiumProperty(solarPanelRotationAxes)
                    }
                }
            };
        }
コード例 #35
0
        public void TestEqualityWithWrongType()
        {
            UnitQuaternion first = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
            Cartographic second = new Cartographic(1.0, 2.0, 3.0);

            Assert.IsFalse(first.Equals(second));
        }
コード例 #36
0
        /// <summary>
        /// Create an aircraft with two sensors.
        /// The aircraft will be visually represented by a labeled glTF model.
        /// </summary>
        private void CreateAircraft()
        {
            // Define waypoints for the aircraft's path and use the propagated point as the location point.
            Cartographic point1             = new Cartographic(Trig.DegreesToRadians(-122.0), Trig.DegreesToRadians(46.3), 4000.0);
            Cartographic point2             = new Cartographic(Trig.DegreesToRadians(-122.28), Trig.DegreesToRadians(46.25), 4100.0);
            Cartographic point3             = new Cartographic(Trig.DegreesToRadians(-122.2), Trig.DegreesToRadians(46.1), 6000.0);
            Cartographic point4             = new Cartographic(Trig.DegreesToRadians(-121.5), Trig.DegreesToRadians(46.0), 7000.0);
            Waypoint     waypoint1          = new Waypoint(m_epoch, point1, 20.0, 0.0);
            Waypoint     waypoint2          = new Waypoint(waypoint1, m_earth.Shape, point2, 20.0);
            Waypoint     waypoint3          = new Waypoint(waypoint2, m_earth.Shape, point3, 20.0);
            Waypoint     waypoint4          = new Waypoint(waypoint3, m_earth.Shape, point4, 20.0);
            var          waypointPropagator = new WaypointPropagator(m_earth, waypoint1, waypoint2, waypoint3, waypoint4);
            var          locationPoint      = waypointPropagator.CreatePoint();

            m_aircraft = new Platform
            {
                Name            = "Aircraft",
                LocationPoint   = locationPoint,
                OrientationAxes = new AxesVehicleVelocityLocalHorizontal(m_earth.FixedFrame, locationPoint),
            };

            // Set the identifier for the aircraft in the CZML document.
            m_aircraft.Extensions.Add(new IdentifierExtension("Aircraft"));

            // Hermite interpolation works better for aircraft-like vehicles.
            m_aircraft.Extensions.Add(new CesiumPositionExtension
            {
                InterpolationAlgorithm = CesiumInterpolationAlgorithm.Hermite
            });

            // Configure a glTF model for the aircraft.
            m_aircraft.Extensions.Add(new ModelGraphicsExtension(new ModelGraphics
            {
                // Link to a binary glTF file.
                Model = new CesiumResource(GetModelUri("aircraft.glb"), CesiumResourceBehavior.LinkTo),
                // Flip the model visually to point Z in the correct direction.
                NodeTransformations = new Dictionary <string, NodeTransformationGraphics>
                {
                    {
                        "Aircraft", new NodeTransformationGraphics
                        {
                            Rotation = new UnitQuaternion(new ElementaryRotation(AxisIndicator.Third, Math.PI))
                        }
                    }
                },
                RunAnimations = false,
            }));

            // Show the path of the aircraft.
            m_aircraft.Extensions.Add(new PathGraphicsExtension(new PathGraphics
            {
                Width     = 2.0,
                LeadTime  = Duration.FromHours(1.0).TotalSeconds,
                TrailTime = Duration.FromHours(1.0).TotalSeconds,
                Material  = new PolylineOutlineMaterialGraphics
                {
                    Color        = Color.White,
                    OutlineColor = Color.Black,
                    OutlineWidth = 1.0,
                },
            }));

            // Configure label for the aircraft.
            m_aircraft.Extensions.Add(new LabelGraphicsExtension(new LabelGraphics
            {
                Text = m_aircraft.Name,
                // Change label color over time.
                FillColor = new TimeIntervalCollection <Color>
                {
                    // Green by default...
                    TimeInterval.Infinite.AddData(Color.Green),
                    // Red between first and second waypoints.
                    new TimeInterval <Color>(waypoint1.Date, waypoint2.Date, Color.Red),
                },
                // Only show label when camera is far enough from the aircraft,
                // to avoid visually clashing with the model.
                DistanceDisplayCondition = new Bounds(1000.0, double.MaxValue),
            }));

            // Define a description for the aircraft which will be shown when selected in Cesium.
            m_aircraft.Extensions.Add(new DescriptionExtension(new Description("Aircraft with two offset sensors")));

            // Create 30 degree simple conic sensor definition
            var sensorCone = new ComplexConic();

            sensorCone.SetHalfAngles(0.0, Trig.DegreesToRadians(15));
            sensorCone.SetClockAngles(Trig.DegreesToRadians(20), Trig.DegreesToRadians(50));
            sensorCone.Radius = double.PositiveInfinity;

            // Create a sensor pointing "forward".
            // Position sensor underneath the wing.
            var sensorOneLocationPoint = new PointFixedOffset(m_aircraft.ReferenceFrame, new Cartesian(-3.0, 8.0, 0.0));
            var sensorAxesOne          = new AxesAlignedConstrained(m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.Z), AxisIndicator.Third,
                                                                    m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.X), AxisIndicator.First);
            // This rotation points the z-axis of the volume back along the x-axis of the ellipsoid.
            var rotationOne = new UnitQuaternion(new ElementaryRotation(AxisIndicator.Second, Constants.HalfPi / 4));

            m_aircraftSensorOne = new Platform
            {
                LocationPoint   = sensorOneLocationPoint,
                OrientationAxes = new AxesFixedOffset(sensorAxesOne, rotationOne),
            };

            // Set the identifier for the sensor in the CZML document.
            m_aircraftSensorOne.Extensions.Add(new IdentifierExtension("AircraftSensorOne"));

            m_aircraftSensorOne.Extensions.Add(new CesiumPositionExtension
            {
                InterpolationAlgorithm = CesiumInterpolationAlgorithm.Hermite
            });

            // Define the sensor geometry.
            m_aircraftSensorOne.Extensions.Add(new FieldOfViewExtension(sensorCone));

            // Configure graphical display of the sensor.
            m_aircraftSensorOne.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics
            {
                // Configure the outline of the projection onto the earth.
                EllipsoidSurfaceMaterial = new SolidColorMaterialGraphics(Color.White),
                IntersectionWidth        = 2.0,
                LateralSurfaceMaterial   = new GridMaterialGraphics
                {
                    Color = Color.FromArgb(171, Color.Blue),
                },
            }));

            // Create sensor pointing to the "side".
            // Position sensor underneath the wing.
            var sensorTwoLocationPoint = new PointFixedOffset(m_aircraft.ReferenceFrame, new Cartesian(-3.0, -8.0, 0.0));
            var sensorAxesTwo          = new AxesAlignedConstrained(m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.Z), AxisIndicator.Third,
                                                                    m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.Y), AxisIndicator.Second);

            // This rotation points the z-axis of the volume back along the x-axis of the ellipsoid.
            var rotationTwo = new UnitQuaternion(new ElementaryRotation(AxisIndicator.First, Constants.HalfPi / 2));

            m_aircraftSensorTwo = new Platform
            {
                LocationPoint   = sensorTwoLocationPoint,
                OrientationAxes = new AxesFixedOffset(sensorAxesTwo, rotationTwo),
            };

            // Set the identifier for the sensor in the CZML document.
            m_aircraftSensorTwo.Extensions.Add(new IdentifierExtension("AircraftSensorTwo"));

            m_aircraftSensorTwo.Extensions.Add(new CesiumPositionExtension
            {
                InterpolationAlgorithm = CesiumInterpolationAlgorithm.Hermite
            });

            // Define the sensor geometry.
            m_aircraftSensorTwo.Extensions.Add(new FieldOfViewExtension(sensorCone));

            // Configure graphical display of the sensor.
            m_aircraftSensorTwo.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics
            {
                // Configure the outline of the projection onto the earth.
                EllipsoidSurfaceMaterial = new SolidColorMaterialGraphics(Color.White),
                IntersectionWidth        = 2.0,
                LateralSurfaceMaterial   = new GridMaterialGraphics
                {
                    Color = Color.FromArgb(171, Color.Red),
                },
            }));

            // Create an access link between the aircraft and the observer position
            // on Mount St. Helens, using the same azimuth elevation mask to constrain access.

            m_aircraftAzimuthElevationMaskLink = new LinkInstantaneous(m_maskPlatform, m_aircraft);

            // Set the identifier for the link in the CZML document.
            m_aircraftAzimuthElevationMaskLink.Extensions.Add(new IdentifierExtension("AircraftMountStHelensAccess"));

            // Constrain access using the azimuth-elevation mask.
            var query = new AzimuthElevationMaskConstraint(m_aircraftAzimuthElevationMaskLink, LinkRole.Transmitter);

            // Configure graphical display of the access link.
            m_aircraftAzimuthElevationMaskLink.Extensions.Add(new LinkGraphicsExtension(new LinkGraphics
            {
                // Show the access link only when access is satisfied.
                Show     = new AccessQueryCesiumProperty <bool>(query, true, false, false),
                Material = new SolidColorMaterialGraphics(Color.Yellow),
            }));
        }
コード例 #37
0
 public void TestEqualsEpsilon()
 {
     UnitQuaternion first = new UnitQuaternion(1.0, 1.0, 1.0, 1.0);
     UnitQuaternion second = new UnitQuaternion(0.99, 1.0, 1.0, 1.01);
     Assert.IsTrue(second.EqualsEpsilon(first, 1e-1));
     Assert.IsTrue(second.EqualsEpsilon(first, 1e-2));
     Assert.IsFalse(second.EqualsEpsilon(first, 1e-3));
     Assert.IsFalse(second.EqualsEpsilon(first, 1e-4));
     Assert.IsFalse(second.EqualsEpsilon(first, 1e-5));
 }
コード例 #38
0
 public void TestGetHashCode()
 {
     UnitQuaternion object1 = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
     UnitQuaternion object2 = new UnitQuaternion(1.0, 2.0, 3.0, 4.0);
     UnitQuaternion object3 = new UnitQuaternion(1.0, 2.0, 3.0, 4.1);
     Assert.AreEqual(object1.GetHashCode(), object2.GetHashCode());
     Assert.AreNotEqual(object1.GetHashCode(), object3.GetHashCode());
 }
コード例 #39
0
        /// <summary>
        /// Create another ground facility with a sensor dome, and a rotating sensor inside the dome.
        /// </summary>
        private void CreateSensorDome()
        {
            // Define the location of the facility using cartographic coordinates.
            var locationPoint = new PointCartographic(m_earth, new Cartographic(Trig.DegreesToRadians(-122.3), Trig.DegreesToRadians(46), 456.359));

            m_sensorDome = new Platform
            {
                Name            = "Sensor Dome",
                LocationPoint   = locationPoint,
                OrientationAxes = new AxesEastNorthUp(m_earth, locationPoint),
            };

            // Set the identifier for the facility in the CZML document.
            m_sensorDome.Extensions.Add(new IdentifierExtension("SensorDome"));

            // Define the sensor geometry.
            var dome = new ComplexConic();

            dome.SetHalfAngles(0.0, Math.PI);
            dome.SetClockAngles(0.0, Math.PI * 2);
            dome.Radius = 10000.0;
            m_sensorDome.Extensions.Add(new FieldOfViewExtension(dome));

            // Configure graphical display of the sensor dome.
            m_sensorDome.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics
            {
                DomeSurfaceMaterial = new GridMaterialGraphics
                {
                    Color     = Color.White,
                    CellAlpha = 0.1,
                },
            }));

            // Define a rotating axes.
            var rotatingAxes = new AxesLinearRate
            {
                ReferenceAxes             = new AxesEastNorthUp(m_earth, locationPoint),
                ReferenceEpoch            = m_epoch,
                InitialRotation           = UnitQuaternion.Identity,
                SpinAxis                  = UnitCartesian.UnitZ,
                InitialRotationalVelocity = Trig.DegreesToRadians(5.0), // 5 degrees per second
                RotationalAcceleration    = 0.0,
            };

            // Define a rotation around X.
            UnitQuaternion quaternion = new UnitQuaternion(new AngleAxisRotation(Math.PI / 3.0, UnitCartesian.UnitX));
            // Define an angular offset for the rotating axes.
            var rotatedOffsetAxes = new AxesFixedOffset(rotatingAxes, quaternion);

            m_rotatingSensor = new Platform
            {
                Name            = "Rotating Sensor",
                LocationPoint   = locationPoint,
                OrientationAxes = rotatedOffsetAxes
            };

            // Set the identifier for the sensor in the CZML document.
            m_rotatingSensor.Extensions.Add(new IdentifierExtension("RotatingSensor"));

            // Define the sensor geometry.
            m_rotatingSensor.Extensions.Add(new FieldOfViewExtension(new RectangularPyramid
            {
                XHalfAngle = Trig.DegreesToRadians(30),
                YHalfAngle = Trig.DegreesToRadians(30),
                Radius     = 10000.0,
            }));

            // Configure graphical display of the sensor.
            m_rotatingSensor.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics
            {
                DomeSurfaceMaterial = new GridMaterialGraphics
                {
                    Color     = Color.Green,
                    CellAlpha = 0.5,
                },
                LateralSurfaceMaterial = new GridMaterialGraphics
                {
                    Color     = Color.Pink,
                    CellAlpha = 0.5,
                },
                IntersectionColor            = Color.White,
                ShowIntersection             = true,
                ShowEllipsoidHorizonSurfaces = true,
            }));
        }