コード例 #1
0
        public void SerializationXml2()
        {
            Matrix33D m1 = new Matrix33D(12, 23, 45,
                                         67, 89, 90,
                                         43, 65, 87.3);
            Matrix33D m2;

            string fileName = "SerializationMatrix33D_DataContractSerializer.xml";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            var serializer = new DataContractSerializer(typeof(Matrix33D));

            using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                using (var writer = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8))
                    serializer.WriteObject(writer, m1);

            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (var reader = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas()))
                    m2 = (Matrix33D)serializer.ReadObject(reader);

            Assert.AreEqual(m1, m2);
        }
コード例 #2
0
        public void SerializationXml()
        {
            Matrix33D m1 = new Matrix33D(12, 23, 45,
                                         67, 89, 90,
                                         43, 65, 87.3);
            Matrix33D m2;

            string fileName = "SerializationMatrix33D.xml";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            XmlSerializer serializer = new XmlSerializer(typeof(Matrix33D));
            StreamWriter  writer     = new StreamWriter(fileName);

            serializer.Serialize(writer, m1);
            writer.Close();

            serializer = new XmlSerializer(typeof(Matrix33D));
            FileStream fileStream = new FileStream(fileName, FileMode.Open);

            m2 = (Matrix33D)serializer.Deserialize(fileStream);
            Assert.AreEqual(m1, m2);
        }
コード例 #3
0
    public void Properties()
    {
      Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
      Assert.AreEqual(1.0, m.M00);
      Assert.AreEqual(2.0, m.M01);
      Assert.AreEqual(3.0, m.M02);
      Assert.AreEqual(4.0, m.M10);
      Assert.AreEqual(5.0, m.M11);
      Assert.AreEqual(6.0, m.M12);
      Assert.AreEqual(7.0, m.M20);
      Assert.AreEqual(8.0, m.M21);
      Assert.AreEqual(9.0, m.M22);

      m = Matrix33D.Zero;
      m.M00 = 1.0;
      m.M01 = 2.0;
      m.M02 = 3.0;
      m.M10 = 4.0;
      m.M11 = 5.0;
      m.M12 = 6.0;
      m.M20 = 7.0;
      m.M21 = 8.0;
      m.M22 = 9.0;
      Assert.AreEqual(new Matrix33D(rowMajor, MatrixOrder.RowMajor), m);
    }
コード例 #4
0
    public void MultiplyTransposed()
    {
      var m = RandomHelper.Random.NextMatrix33D(1, 10);
      var v = RandomHelper.Random.NextVector3D(1, 10);

      Assert.AreEqual(m.Transposed * v, Matrix33D.MultiplyTransposed(m, v));
    }
コード例 #5
0
    public void SerializationBinary()
    {
      Matrix33D m1 = new Matrix33D(12, 23, 45,
                                   56, 67, 89,
                                   90, 12, 43.3);
      Matrix33D m2;

      string fileName = "SerializationMatrix33D.bin";

      if (File.Exists(fileName))
        File.Delete(fileName);

      FileStream fs = new FileStream(fileName, FileMode.Create);

      BinaryFormatter formatter = new BinaryFormatter();
      formatter.Serialize(fs, m1);
      fs.Close();

      fs = new FileStream(fileName, FileMode.Open);
      formatter = new BinaryFormatter();
      m2 = (Matrix33D)formatter.Deserialize(fs);
      fs.Close();

      Assert.AreEqual(m1, m2);
    }
コード例 #6
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void AbsoluteStatic()
        {
            Matrix33D m = new Matrix33D(-1, -2, -3, -4, -5, -6, -7, -8, -9);
              Matrix33D absoluteM = Matrix33D.Absolute(m);

              Assert.AreEqual(1, absoluteM.M00);
              Assert.AreEqual(2, absoluteM.M01);
              Assert.AreEqual(3, absoluteM.M02);
              Assert.AreEqual(4, absoluteM.M10);
              Assert.AreEqual(5, absoluteM.M11);
              Assert.AreEqual(6, absoluteM.M12);
              Assert.AreEqual(7, absoluteM.M20);
              Assert.AreEqual(8, absoluteM.M21);
              Assert.AreEqual(9, absoluteM.M22);

              m = new Matrix33D(1, 2, 3, 4, 5, 6, 7, 8, 9);
              absoluteM = Matrix33D.Absolute(m);
              Assert.AreEqual(1, absoluteM.M00);
              Assert.AreEqual(2, absoluteM.M01);
              Assert.AreEqual(3, absoluteM.M02);
              Assert.AreEqual(4, absoluteM.M10);
              Assert.AreEqual(5, absoluteM.M11);
              Assert.AreEqual(6, absoluteM.M12);
              Assert.AreEqual(7, absoluteM.M20);
              Assert.AreEqual(8, absoluteM.M21);
              Assert.AreEqual(9, absoluteM.M22);
        }
コード例 #7
0
 public void IsRotation()
 {
   Assert.IsTrue(!Matrix33D.Zero.IsRotation);
   Assert.IsTrue(Matrix33D.Identity.IsRotation);
   Assert.IsTrue(Matrix33D.CreateRotation(new Vector3D(1, 2, 3).Normalized, 0.5).IsRotation);
   Assert.IsTrue(!new Matrix33D(1, 0, 0, 0, 1, 0, 0, 0, -1).IsRotation);
 }
コード例 #8
0
    public void AbsoluteStatic()
    {
      Matrix33D m = new Matrix33D(-1, -2, -3, -4, -5, -6, -7, -8, -9);
      Matrix33D absoluteM = Matrix33D.Absolute(m);

      Assert.AreEqual(1, absoluteM.M00);
      Assert.AreEqual(2, absoluteM.M01);
      Assert.AreEqual(3, absoluteM.M02);
      Assert.AreEqual(4, absoluteM.M10);
      Assert.AreEqual(5, absoluteM.M11);
      Assert.AreEqual(6, absoluteM.M12);
      Assert.AreEqual(7, absoluteM.M20);
      Assert.AreEqual(8, absoluteM.M21);
      Assert.AreEqual(9, absoluteM.M22);

      m = new Matrix33D(1, 2, 3, 4, 5, 6, 7, 8, 9);
      absoluteM = Matrix33D.Absolute(m);
      Assert.AreEqual(1, absoluteM.M00);
      Assert.AreEqual(2, absoluteM.M01);
      Assert.AreEqual(3, absoluteM.M02);
      Assert.AreEqual(4, absoluteM.M10);
      Assert.AreEqual(5, absoluteM.M11);
      Assert.AreEqual(6, absoluteM.M12);
      Assert.AreEqual(7, absoluteM.M20);
      Assert.AreEqual(8, absoluteM.M21);
      Assert.AreEqual(9, absoluteM.M22);
    }
コード例 #9
0
 public void Transposed()
 {
   Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
   Matrix33D mt = new Matrix33D(rowMajor, MatrixOrder.ColumnMajor);
   Assert.AreEqual(mt, m.Transposed);
   Assert.AreEqual(Matrix33D.Identity, Matrix33D.Identity.Transposed);
 }
コード例 #10
0
 public void Trace()
 {
   Matrix33D m = new Matrix33D(new double[3, 3] { { 1, 2, 3 }, 
                                                 { 2, 4, 5 }, 
                                                 { 3, 5, 7 } });
   Assert.AreEqual(12, m.Trace);
 }
コード例 #11
0
 public void GetColumn()
 {
   Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
   Assert.AreEqual(new Vector3D(1.0, 4.0, 7.0), m.GetColumn(0));
   Assert.AreEqual(new Vector3D(2.0, 5.0, 8.0), m.GetColumn(1));
   Assert.AreEqual(new Vector3D(3.0, 6.0, 9.0), m.GetColumn(2));
 }
コード例 #12
0
 public void GetRow()
 {
   Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
   Assert.AreEqual(new Vector3D(1.0, 2.0, 3.0), m.GetRow(0));
   Assert.AreEqual(new Vector3D(4.0, 5.0, 6.0), m.GetRow(1));
   Assert.AreEqual(new Vector3D(7.0, 8.0, 9.0), m.GetRow(2));
 }
コード例 #13
0
        protected override PoseD Read(ContentReader input, PoseD existingInstance)
        {
            Vector3D  position    = input.ReadRawObject <Vector3D>();
            Matrix33D orientation = input.ReadRawObject <Matrix33D>();

            return(new PoseD(position, orientation));
        }
コード例 #14
0
        public void MultiplyMatrix()
        {
            Matrix33D m = new Matrix33D(12, 23, 45,
                                        67, 89, 90,
                                        43, 65, 87);

            Assert.AreEqual(Matrix33D.Zero, Matrix33D.Multiply(m, Matrix33D.Zero));
            Assert.AreEqual(Matrix33D.Zero, Matrix33D.Multiply(Matrix33D.Zero, m));
            Assert.AreEqual(m, Matrix33D.Multiply(m, Matrix33D.Identity));
            Assert.AreEqual(m, Matrix33D.Multiply(Matrix33D.Identity, m));
            Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, Matrix33D.Multiply(m, m.Inverse)));
            Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, Matrix33D.Multiply(m.Inverse, m)));

            Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
            Matrix33D m2 = new Matrix33D(12, 23, 45,
                                         67, 89, 90,
                                         43, 65, 87);
            Matrix33D result = Matrix33D.Multiply(m1, m2);

            for (int column = 0; column < 3; column++)
            {
                for (int row = 0; row < 3; row++)
                {
                    Assert.AreEqual(Vector3D.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]);
                }
            }
        }
コード例 #15
0
        public void Constructors()
        {
            Matrix33D m = new Matrix33D(1.0, 2.0, 3.0f,
                                        4.0, 5.0, 6.0f,
                                        7.0, 8.0, 9.0);

            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(rowMajor[i], m[i]);
            }

            m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(rowMajor[i], m[i]);
            }

            m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(rowMajor[i], m[i]);
            }

            m = new Matrix33D(new List <double>(columnMajor), MatrixOrder.ColumnMajor);
            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(rowMajor[i], m[i]);
            }

            m = new Matrix33D(new List <double>(rowMajor), MatrixOrder.RowMajor);
            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(rowMajor[i], m[i]);
            }

            m = new Matrix33D(new double[3, 3] {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            });
            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(rowMajor[i], m[i]);
            }

            m = new Matrix33D(new double[3][] { new double[3] {
                                                    1, 2, 3
                                                },
                                                new double[3] {
                                                    4, 5, 6
                                                },
                                                new double[3] {
                                                    7, 8, 9
                                                } });
            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(rowMajor[i], m[i]);
            }
        }
コード例 #16
0
        public void CrossProductMatrix()
        {
            Vector3D  v = new Vector3D(-1.0, -2.0, -3.0);
            Vector3D  w = new Vector3D(4.0, 5.0, 6.0);
            Matrix33D m = v.ToCrossProductMatrix();

            Assert.AreEqual(Vector3D.Cross(v, w), v.ToCrossProductMatrix() * w);
        }
コード例 #17
0
 public void Subtraction()
 {
   Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
   Matrix33D m2 = Matrix33D.One;
   Matrix33D result = Matrix33D.Subtract(m1, m2);
   for (int i = 0; i < 9; i++)
     Assert.AreEqual(rowMajor[i] - 1.0, result[i]);
 }
コード例 #18
0
 public void Determinant()
 {
   Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
   Assert.AreEqual(0.0, m.Determinant);
   Assert.AreEqual(0.0, Matrix33D.Zero.Determinant);
   Assert.AreEqual(0.0, Matrix33D.One.Determinant);
   Assert.AreEqual(1.0, Matrix33D.Identity.Determinant);
 }
コード例 #19
0
 public void SubtractionOperator()
 {
   Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
   Matrix33D m2 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor) * 3;
   Matrix33D result = m1 - m2;
   for (int i = 0; i < 9; i++)
     Assert.AreEqual(-rowMajor[i] * 2, result[i]);
 }
コード例 #20
0
 public void Multiplication()
 {
   double s = 0.1234;
   Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
   m = Matrix33D.Multiply(s, m);
   for (int i = 0; i < 9; i++)
     Assert.AreEqual(rowMajor[i] * s, m[i]);
 }
コード例 #21
0
 public void Division()
 {
   double s = 0.1234;
   Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
   m = Matrix33D.Divide(m, s);
   for (int i = 0; i < 9; i++)
     Assert.IsTrue(Numeric.AreEqual(rowMajor[i] / s, m[i]));
 }
コード例 #22
0
        public void Negation()
        {
            Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);

            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(-rowMajor[i], Matrix33D.Negate(m)[i]);
            }
        }
コード例 #23
0
 public void ToArray1D()
 {
   Matrix33D m = new Matrix33D(1, 2, 3, 4, 5, 6, 7, 8, 9);
   double[] array = m.ToArray1D(MatrixOrder.RowMajor);
   for (int i = 0; i < 9; i++)
     Assert.AreEqual(rowMajor[i], array[i]);
   array = m.ToArray1D(MatrixOrder.ColumnMajor);
   for (int i = 0; i < 9; i++)
     Assert.AreEqual(columnMajor[i], array[i]);
 }
コード例 #24
0
        public void FromMatrixWithZeroTrace()
        {
            QuaternionD q;
            Matrix33D   m = new Matrix33D(0, 1, 0,
                                          0, 0, 1,
                                          1, 0, 0);

            q = QuaternionD.CreateRotation(m);
            Assert.IsTrue(QuaternionD.AreNumericallyEqual(new QuaternionD(-0.5, 0.5, 0.5, 0.5), q));
        }
コード例 #25
0
    public void Constants()
    {
      Matrix33D zero = Matrix33D.Zero;
      for (int i = 0; i < 9; i++)
        Assert.AreEqual(0.0, zero[i]);

      Matrix33D one = Matrix33D.One;
      for (int i = 0; i < 9; i++)
        Assert.AreEqual(1.0, one[i]);
    }
コード例 #26
0
 public void Transpose()
 {
   Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
   m.Transpose();
   Matrix33D mt = new Matrix33D(rowMajor, MatrixOrder.ColumnMajor);
   Assert.AreEqual(mt, m);
   Matrix33D i = Matrix33D.Identity;
   i.Transpose();
   Assert.AreEqual(Matrix33D.Identity, i);
 }
コード例 #27
0
 public void InverseWithNearSingularMatrix()
 {
   Matrix33D m = new Matrix33D(0.0001, 0, 0,
                               0, 0.0001, 0,
                               0, 0, 0.0001);
   Vector3D v = Vector3D.One;
   Vector3D w = m * v;
   Assert.IsTrue(Vector3D.AreNumericallyEqual(v, m.Inverse * w));
   Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, m * m.Inverse));
 }
コード例 #28
0
 public void ToList()
 {
   Matrix33D m = new Matrix33D(1, 2, 3, 4, 5, 6, 7, 8, 9);
   IList<double> list = m.ToList(MatrixOrder.RowMajor);
   for (int i = 0; i < 9; i++)
     Assert.AreEqual(rowMajor[i], list[i]);
   list = m.ToList(MatrixOrder.ColumnMajor);
   for (int i = 0; i < 9; i++)
     Assert.AreEqual(columnMajor[i], list[i]);
 }
コード例 #29
0
        /// <summary>
        /// Computes the covariance matrix for a list of 3-dimensional points (double-precision).
        /// </summary>
        /// <param name="points">The points.</param>
        /// <returns>The covariance matrix.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="points"/> is <see langword="null"/>.
        /// </exception>
        public static Matrix33D ComputeCovarianceMatrix(IList <Vector3D> points)
        {
            // Notes: See "Real-Time Collision Detection" p. 93

            if (points == null)
            {
                throw new ArgumentNullException("points");
            }

            int   numberOfPoints        = points.Count;
            float oneOverNumberOfPoints = 1f / numberOfPoints;

            // Compute the center of mass.
            Vector3D centerOfMass = Vector3D.Zero;

            for (int i = 0; i < numberOfPoints; i++)
            {
                centerOfMass += points[i];
            }
            centerOfMass *= oneOverNumberOfPoints;

            // Compute covariance matrix.
            double c00 = 0;
            double c11 = 0;
            double c22 = 0;
            double c01 = 0;
            double c02 = 0;
            double c12 = 0;

            for (int i = 0; i < numberOfPoints; i++)
            {
                // Translate points so that center of mass is at origin.
                Vector3D p = points[i] - centerOfMass;

                // Compute covariance of translated point.
                c00 += p.X * p.X;
                c11 += p.Y * p.Y;
                c22 += p.Z * p.Z;
                c01 += p.X * p.Y;
                c02 += p.X * p.Z;
                c12 += p.Y * p.Z;
            }
            c00 *= oneOverNumberOfPoints;
            c11 *= oneOverNumberOfPoints;
            c22 *= oneOverNumberOfPoints;
            c01 *= oneOverNumberOfPoints;
            c02 *= oneOverNumberOfPoints;
            c12 *= oneOverNumberOfPoints;

            Matrix33D covarianceMatrix = new Matrix33D(c00, c01, c02,
                                                       c01, c11, c12,
                                                       c02, c12, c22);

            return(covarianceMatrix);
        }
コード例 #30
0
    public void Indexer1d()
    {
      Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
      for (int i = 0; i < 9; i++)
        Assert.AreEqual(rowMajor[i], m[i]);

      m = Matrix33D.Zero;
      for (int i = 0; i < 9; i++)
        m[i] = rowMajor[i];
      Assert.AreEqual(new Matrix33D(rowMajor, MatrixOrder.RowMajor), m);
    }
コード例 #31
0
    public void CreateRotationZ()
    {
      double angle = (double)MathHelper.ToRadians(30);
      Matrix33D m = Matrix33D.CreateRotationZ(angle);
      Assert.IsTrue(Vector3D.AreNumericallyEqual(new Vector3D((double)Math.Cos(angle), (double)Math.Sin(angle), 0), m * Vector3D.UnitX));

      QuaternionD q = QuaternionD.CreateRotation(Vector3D.UnitZ, angle);
      Assert.IsTrue(Vector3D.AreNumericallyEqual(q.Rotate(Vector3D.One), m * Vector3D.One));

      Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.CreateRotation(Vector3D.UnitZ, angle), m));
    }
コード例 #32
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void Addition()
 {
     Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       Matrix33D m2 = Matrix33D.One;
       Matrix33D result = Matrix33D.Add(m1, m2);
       for (int i = 0; i < 9; i++)
     Assert.AreEqual(rowMajor[i] + 1.0, result[i]);
 }
コード例 #33
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void InvertException()
 {
     Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       m.Invert();
 }
コード例 #34
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void GetColumnException1()
 {
     Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       m.GetColumn(-1);
 }
コード例 #35
0
ファイル: Matrix44DTest.cs プロジェクト: Zolniu/DigitalRune
 public void SetMinor()
 {
     Matrix44D m = Matrix44D.Zero;
       Matrix33D minor = new Matrix33D(1.0, 2.0, 3.0f,
                             5.0, 6.0, 7.0f,
                             9.0, 10.0, 11.0);
       m.Minor = minor;
       Assert.AreEqual(minor, m.Minor);
 }
コード例 #36
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void MultiplyVectorOperator()
        {
            Vector3D v = new Vector3D(2.34, 3.45, 4.56);
              Assert.AreEqual(v, Matrix33D.Identity * v);
              Assert.AreEqual(Vector3D.Zero, Matrix33D.Zero * v);

              Matrix33D m = new Matrix33D(12, 23, 45,
                                67, 89, 90,
                                43, 65, 87);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(v, m * m.Inverse * v));

              for (int i = 0; i < 3; i++)
            Assert.AreEqual(Vector3D.Dot(m.GetRow(i), v), (m * v)[i]);
        }
コード例 #37
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void Properties()
        {
            Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
              Assert.AreEqual(1.0, m.M00);
              Assert.AreEqual(2.0, m.M01);
              Assert.AreEqual(3.0, m.M02);
              Assert.AreEqual(4.0, m.M10);
              Assert.AreEqual(5.0, m.M11);
              Assert.AreEqual(6.0, m.M12);
              Assert.AreEqual(7.0, m.M20);
              Assert.AreEqual(8.0, m.M21);
              Assert.AreEqual(9.0, m.M22);

              m = Matrix33D.Zero;
              m.M00 = 1.0;
              m.M01 = 2.0;
              m.M02 = 3.0;
              m.M10 = 4.0;
              m.M11 = 5.0;
              m.M12 = 6.0;
              m.M20 = 7.0;
              m.M21 = 8.0;
              m.M22 = 9.0;
              Assert.AreEqual(new Matrix33D(rowMajor, MatrixOrder.RowMajor), m);
        }
コード例 #38
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void IsSymmetric()
        {
            Matrix33D m = new Matrix33D(new double[3, 3] { { 1, 2, 3 },
                                                    { 2, 4, 5 },
                                                    { 3, 5, 7 } });
              Assert.AreEqual(true, m.IsSymmetric);

              m = new Matrix33D(new double[3, 3] { { 1, 2, 3 },
                                          { 4, 5, 2 },
                                          { 7, 4, 1 } });
              Assert.AreEqual(false, m.IsSymmetric);
        }
コード例 #39
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void MultiplicationOperator()
        {
            double s = 0.1234;
              Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
              m = s * m;
              for (int i = 0; i < 9; i++)
            Assert.AreEqual(rowMajor[i] * s, m[i]);

              m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
              m = m * s;
              for (int i = 0; i < 9; i++)
            Assert.AreEqual(rowMajor[i] * s, m[i]);
        }
コード例 #40
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void Indexer1dException4()
 {
     Matrix33D m = new Matrix33D();
       double x = m[9];
 }
コード例 #41
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void IsNaN()
        {
            const int numberOfRows = 3;
              const int numberOfColumns = 3;
              Assert.IsFalse(new Matrix33D().IsNaN);

              for (int r = 0; r < numberOfRows; r++)
              {
            for (int c = 0; c < numberOfColumns; c++)
            {
              Matrix33D m = new Matrix33D();
              m[r, c] = double.NaN;
              Assert.IsTrue(m.IsNaN);
            }
              }
        }
コード例 #42
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void Indexer2d()
 {
     Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
       for (int column = 0; column < 3; column++)
     for (int row = 0; row < 3; row++)
       Assert.AreEqual(columnMajor[column * 3 + row], m[row, column]);
       m = Matrix33D.Zero;
       for (int column = 0; column < 3; column++)
     for (int row = 0; row < 3; row++)
       m[row, column] = (double)(row * 3 + column + 1);
       Assert.AreEqual(new Matrix33D(rowMajor, MatrixOrder.RowMajor), m);
 }
コード例 #43
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void InverseWithNearSingularMatrix()
 {
     Matrix33D m = new Matrix33D(0.0001, 0, 0,
                           0, 0.0001, 0,
                           0, 0, 0.0001);
       Vector3D v = Vector3D.One;
       Vector3D w = m * v;
       Assert.IsTrue(Vector3D.AreNumericallyEqual(v, m.Inverse * w));
       Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, m * m.Inverse));
 }
コード例 #44
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void Invert()
        {
            Assert.AreEqual(Matrix33D.Identity, Matrix33D.Identity.Inverse);

              Matrix33D m = new Matrix33D(1, 2, 3,
                                  2, 5, 8,
                                  7, 6, -1);
              Vector3D v = Vector3D.One;
              Vector3D w = m * v;
              Matrix33D im = m;
              im.Invert();
              Assert.IsTrue(Vector3D.AreNumericallyEqual(v, im * w));
              Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, m * im));
        }
コード例 #45
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void GetRowException2()
 {
     Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       m.GetRow(3);
 }
コード例 #46
0
ファイル: QuaternionDTest.cs プロジェクト: Zolniu/DigitalRune
        public void QuaternionDFromMatrix33()
        {
            Vector3D v = Vector3D.One;
              Matrix33D m = Matrix33D.Identity;
              QuaternionD q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = Matrix33D.CreateRotation(Vector3D.UnitX, 0.3);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = Matrix33D.CreateRotation(Vector3D.UnitY, 1.0);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = Matrix33D.CreateRotation(Vector3D.UnitZ, 4.0);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = Matrix33D.Identity;
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = Matrix33D.CreateRotation(-Vector3D.UnitX, 1.3);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = Matrix33D.CreateRotation(-Vector3D.UnitY, -1.4);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = Matrix33D.CreateRotation(-Vector3D.UnitZ, -0.1);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = new Matrix33D(0, 0, 1,
                        0, -1, 0,
                        1, 0, 0);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));

              m = new Matrix33D(-1, 0, 0,
                         0, 1, 0,
                         0, 0, -1);
              q = QuaternionD.CreateRotation(m);
              Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v)));
        }
コード例 #47
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void GetRow()
 {
     Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       Assert.AreEqual(new Vector3D(1.0, 2.0, 3.0), m.GetRow(0));
       Assert.AreEqual(new Vector3D(4.0, 5.0, 6.0), m.GetRow(1));
       Assert.AreEqual(new Vector3D(7.0, 8.0, 9.0), m.GetRow(2));
 }
コード例 #48
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void Indexer1dException2()
 {
     Matrix33D m = new Matrix33D();
       m[9] = 0.0;
 }
コード例 #49
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void SerializationBinary()
        {
            Matrix33D m1 = new Matrix33D(12, 23, 45,
                                   56, 67, 89,
                                   90, 12, 43.3);
              Matrix33D m2;

              string fileName = "SerializationMatrix33D.bin";

              if (File.Exists(fileName))
            File.Delete(fileName);

              FileStream fs = new FileStream(fileName, FileMode.Create);

              BinaryFormatter formatter = new BinaryFormatter();
              formatter.Serialize(fs, m1);
              fs.Close();

              fs = new FileStream(fileName, FileMode.Open);
              formatter = new BinaryFormatter();
              m2 = (Matrix33D)formatter.Deserialize(fs);
              fs.Close();

              Assert.AreEqual(m1, m2);
        }
コード例 #50
0
ファイル: QuaternionDTest.cs プロジェクト: Zolniu/DigitalRune
 public void FromMatrixWithZeroTrace()
 {
     QuaternionD q;
       Matrix33D m = new Matrix33D(0, 1, 0,
                           0, 0, 1,
                           1, 0, 0);
       q = QuaternionD.CreateRotation(m);
       Assert.IsTrue(QuaternionD.AreNumericallyEqual(new QuaternionD(-0.5, 0.5, 0.5, 0.5), q));
 }
コード例 #51
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void NegationOperator()
 {
     Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       for (int i = 0; i < 9; i++)
     Assert.AreEqual(-rowMajor[i], (-m)[i]);
 }
コード例 #52
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void Indexer1d()
        {
            Matrix33D m = new Matrix33D(rowMajor, MatrixOrder.RowMajor);
              for (int i = 0; i < 9; i++)
            Assert.AreEqual(rowMajor[i], m[i]);

              m = Matrix33D.Zero;
              for (int i = 0; i < 9; i++)
            m[i] = rowMajor[i];
              Assert.AreEqual(new Matrix33D(rowMajor, MatrixOrder.RowMajor), m);
        }
コード例 #53
0
ファイル: Matrix44DTest.cs プロジェクト: Zolniu/DigitalRune
 public void GetMinor()
 {
     Matrix44D m = new Matrix44D(rowMajor, MatrixOrder.RowMajor);
       Matrix33D minor = m.Minor;
       Matrix33D expected = new Matrix33D(1.0, 2.0, 3.0f,
                                5.0, 6.0, 7.0f,
                                9.0, 10.0, 11.0);
       Assert.AreEqual(expected, minor);
 }
コード例 #54
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void HashCode()
 {
     Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       Assert.AreNotEqual(Matrix33D.Identity.GetHashCode(), m.GetHashCode());
 }
コード例 #55
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void MultiplyMatrixOperator()
        {
            Matrix33D m = new Matrix33D(12, 23, 45,
                                67, 89, 90,
                                43, 65, 87);
              Assert.AreEqual(Matrix33D.Zero, m * Matrix33D.Zero);
              Assert.AreEqual(Matrix33D.Zero, Matrix33D.Zero * m);
              Assert.AreEqual(m, m * Matrix33D.Identity);
              Assert.AreEqual(m, Matrix33D.Identity * m);
              Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, m * m.Inverse));
              Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, m.Inverse * m));

              Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
              Matrix33D m2 = new Matrix33D(12, 23, 45,
                                 67, 89, 90,
                                 43, 65, 87);
              Matrix33D result = m1 * m2;
              for (int column = 0; column < 3; column++)
            for (int row = 0; row < 3; row++)
              Assert.AreEqual(Vector3D.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]);
        }
コード例 #56
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
        public void SerializationJson()
        {
            Matrix33D m1 = new Matrix33D(12, 23, 45,
                                  67, 89, 90,
                                  43, 65, 87.3);
              Matrix33D m2;

              string fileName = "SerializationMatrix33D.json";

              if (File.Exists(fileName))
            File.Delete(fileName);

              var serializer = new DataContractJsonSerializer(typeof(Matrix33D));
              using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
            serializer.WriteObject(stream, m1);

              using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            m2 = (Matrix33D)serializer.ReadObject(stream);

              Assert.AreEqual(m1, m2);
        }
コード例 #57
0
ファイル: Ephemeris.cs プロジェクト: Zolniu/DigitalRune
        //--------------------------------------------------------------
        /// <summary>
        /// Computes the derived values, like sun/moon positions, transformation matrices and light
        /// intensities. This method must be called when the location or time has changed.
        /// </summary>
        /// <remarks>
        /// This method must be called when the input properties <see cref="Latitude"/>,
        /// <see cref="Longitude"/>, <see cref="Altitude"/>, or <see cref="Time"/>) have changed.
        /// </remarks>
        public void Update()
        {
            _epoch2000Centuries = ToEpoch2000Centuries(Time, true);
              _epoch1990Days = ToEpoch1990Days(Time, false);

              // To transform from ecliptic to equatorial, we rotate by the obliquity of the ecliptic.
              _e = 0.409093 - 0.000227 * _epoch2000Centuries;
              EclipticToEquatorial = Matrix33D.CreateRotationX(_e);

              // GMST = Greenwich mean sidereal time (mittlere Greenwich-Sternzeit) in radians.
              double gmst = 4.894961 + 230121.675315 * ToEpoch2000Centuries(Time, false);
              EquatorialToGeographic = Matrix33D.CreateRotationZ(-gmst);

              // The earth axis slowly changes over time (precession). The precession movement repeats
              // itself approx. all 26000 years. When we move from to horizontal or geographics,
              // we need to apply the precession.

              // In Game Engine Gems:
              //var Rx = Matrix33D.CreateRotationX(0.1118 * _epoch2000Centuries);
              //var Ry = Matrix33D.CreateRotationY(-0.00972 * _epoch2000Centuries);
              //var Rz = Matrix33D.CreateRotationZ(0.01118 * _epoch2000Centuries);
              //var precession = Rz * (Ry * Rx);

              // In original article:
              var Ry = Matrix33D.CreateRotationY(-0.00972 * _epoch2000Centuries);
              var Rz = Matrix33D.CreateRotationZ(0.01118 * _epoch2000Centuries);
              var precession = Rz * Ry * Rz;

              // In game engine gems precession is applied in EclipticToWorld and in
              // EquatorialToWorld. This makes no sense since precession cannot be valid for both
              // coordinate systems. --> We assume the precession is given in equatorial space.
              //EclipticToWorld = rLat * rLong * EclipticToEquatorial * precession;

              // Latitude rotation
              var rLat = Matrix33D.CreateRotationY(MathHelper.ToRadians(Latitude) - ConstantsD.PiOver2);

              // Longitude rotation
              // LMST = Local mean sidereal time (mittlere Ortssternzeit) in radians.
              double lmst = gmst + MathHelper.ToRadians(Longitude);
              var rLong = Matrix33D.CreateRotationZ(-lmst);

              // Earth radius at the equator. (We assume a perfect sphere. We do not support geodetic
              // systems with imperfect earth spheres.)
              const double earthRadius = 6378.137 * 1000;
              var equatorialToHorizontalTranslation = new Vector3D(0, -earthRadius - Altitude, 0);

              // Switching of the coordinate axes between Equatorial (z up) and Horizontal (y up).
              var axisSwitch = new Matrix33D(0, 1, 0,
                                     0, 0, 1,
                                     1, 0, 0);

              EquatorialToWorld = new Matrix44D(axisSwitch * rLat * rLong * precession,
                                        equatorialToHorizontalTranslation);

              _equatorialToWorldNoPrecession = new Matrix44D(axisSwitch * rLat * rLong,
                                                     equatorialToHorizontalTranslation);

              //WorldToGeographic = EquatorialToGeographic * EquatorialToWorld.Minor.Transposed;

              ComputeSunPosition();
              ComputeMoonPosition();
              ComputeEarthPosition();

              //for (int i = 0; i < NumberOfPlanets; i++)
              //{
              //  var planet = (VisiblePlanets)i;
              //  if (planet != VisiblePlanets.Earth)
              //    ComputePlanetData(planet);
              //}
        }
コード例 #58
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void GetColumn()
 {
     Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       Assert.AreEqual(new Vector3D(1.0, 4.0, 7.0), m.GetColumn(0));
       Assert.AreEqual(new Vector3D(2.0, 5.0, 8.0), m.GetColumn(1));
       Assert.AreEqual(new Vector3D(3.0, 6.0, 9.0), m.GetColumn(2));
 }
コード例 #59
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void EqualityOperators()
 {
     Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       Matrix33D m2 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       Assert.IsTrue(m1 == m2);
       Assert.IsFalse(m1 != m2);
       for (int i = 0; i < 9; i++)
       {
     m2 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
     m2[i] += 0.1;
     Assert.IsFalse(m1 == m2);
     Assert.IsTrue(m1 != m2);
       }
 }
コード例 #60
0
ファイル: Matrix33DTest.cs プロジェクト: Zolniu/DigitalRune
 public void Multiplication()
 {
     double s = 0.1234;
       Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor);
       m = Matrix33D.Multiply(s, m);
       for (int i = 0; i < 9; i++)
     Assert.AreEqual(rowMajor[i] * s, m[i]);
 }