Exemple #1
0
        public void TestQuaternionsSlerp5()
        {
            Random      r  = new Random();
            Quaternions q1 = new Quaternions();

            q1.AxisAngle = new MCvPoint3D64f(0.0, 355.0 / 180 * Math.PI, 0.0);
            Quaternions q2 = new Quaternions();

            q2.AxisAngle = new MCvPoint3D64f(0.0, 5.0 / 180 * Math.PI, 0.0);

            double epsilon = 1.0e-12;
            double x = 0, y = 0, z = 0;

            Quaternions q = q1.Slerp(q2, 0.5);

            q.GetEuler(ref x, ref y, ref z);
            EmguAssert.IsFalse(double.IsNaN(x));
            EmguAssert.IsFalse(double.IsNaN(y));
            EmguAssert.IsFalse(double.IsNaN(z));
            double deltaDegree = Math.Abs(y / Math.PI * 180.0 - 0.0);

            EmguAssert.IsTrue(deltaDegree <= epsilon);

            q = q2.Slerp(q1, 0.5);
            q.GetEuler(ref x, ref y, ref z);
            EmguAssert.IsFalse(double.IsNaN(x));
            EmguAssert.IsFalse(double.IsNaN(y));
            EmguAssert.IsFalse(double.IsNaN(z));
            deltaDegree = Math.Abs(y / Math.PI * 180.0 - 0.0);
            EmguAssert.IsTrue(deltaDegree <= epsilon);
        }
Exemple #2
0
        public void TestQuaternionsSlerp3()
        {
            Random      r  = new Random();
            Quaternions q1 = new Quaternions();

            q1.AxisAngle = new MCvPoint3D64f(0.0, 30.0 / 180 * Math.PI, 0.0);
            Quaternions q2 = new Quaternions();

            q2.AxisAngle = new MCvPoint3D64f(0.0, 40.0 / 180 * Math.PI, 0.0);

            double epsilon = 1.0e-12;
            double x = 0, y = 0, z = 0;

            Quaternions q = q1.Slerp(q2, 0.5);

            q.GetEuler(ref x, ref y, ref z);
            double deltaDegree = Math.Abs(y / Math.PI * 180.0 - 35.0);

            EmguAssert.IsTrue(deltaDegree <= epsilon);

            q = q1.Slerp(q2, 0.8);
            q.GetEuler(ref x, ref y, ref z);
            deltaDegree = Math.Abs(y / Math.PI * 180.0 - 38.0);
            EmguAssert.IsTrue(deltaDegree <= epsilon);

            q = q1.Slerp(q2, 0.15);
            q.GetEuler(ref x, ref y, ref z);
            deltaDegree = Math.Abs(y / Math.PI * 180.0 - 31.5);
            EmguAssert.IsTrue(deltaDegree <= epsilon);
        }
Exemple #3
0
        public void TestQuaternionEulerAngleAndRotate()
        {
            double      epsilon = 1.0e-12;
            Random      r = new Random();
            Quaternions q1 = new Quaternions();
            double      roll1 = r.NextDouble(), pitch1 = r.NextDouble(), yaw1 = r.NextDouble();
            double      roll2 = 0, pitch2 = 0, yaw2 = 0;

            q1.SetEuler(roll1, pitch1, yaw1);
            q1.GetEuler(ref roll2, ref pitch2, ref yaw2);
            EmguAssert.IsTrue(Math.Abs(roll1 - roll2) < epsilon);
            EmguAssert.IsTrue(Math.Abs(pitch1 - pitch2) < epsilon);
            EmguAssert.IsTrue(Math.Abs(yaw1 - yaw2) < epsilon);

            Quaternions q2 = new Quaternions();

            q2.SetEuler(r.NextDouble(), r.NextDouble(), r.NextDouble());

            MCvPoint3D64f p = new MCvPoint3D64f(r.NextDouble() * 10, r.NextDouble() * 10, r.NextDouble() * 10);

            MCvPoint3D64f delta = (q1 * q2).RotatePoint(p) - q1.RotatePoint(q2.RotatePoint(p));

            EmguAssert.IsTrue(delta.X < epsilon);
            EmguAssert.IsTrue(delta.Y < epsilon);
            EmguAssert.IsTrue(delta.Z < epsilon);
        }
Exemple #4
0
        public void TestQuaternions1()
        {
            Quaternions q       = new Quaternions();
            double      epsilon = 1.0e-10;

            Matrix <double> point = new Matrix <double>(3, 1);

            point.SetRandNormal(new MCvScalar(), new MCvScalar(20));
            using (Matrix <double> pt1 = new Matrix <double>(3, 1))
                using (Matrix <double> pt2 = new Matrix <double>(3, 1))
                    using (Matrix <double> pt3 = new Matrix <double>(3, 1))
                    {
                        double x1 = 1.0, y1 = 0.2, z1 = 0.1;
                        double x2 = 0.0, y2 = 0.0, z2 = 0.0;

                        q.SetEuler(x1, y1, z1);
                        q.GetEuler(ref x2, ref y2, ref z2);

                        EmguAssert.IsTrue(
                            Math.Abs(x2 - x1) < epsilon &&
                            Math.Abs(y2 - y1) < epsilon &&
                            Math.Abs(z2 - z1) < epsilon);

                        q.RotatePoints(point, pt1);

                        Matrix <double> rMat = new Matrix <double>(3, 3);
                        q.GetRotationMatrix(rMat);
                        CvInvoke.Gemm(rMat, point, 1.0, null, 0.0, pt2, Emgu.CV.CvEnum.GemmType.Default);

                        CvInvoke.AbsDiff(pt1, pt2, pt3);

                        EmguAssert.IsTrue(
                            pt3[0, 0] < epsilon &&
                            pt3[1, 0] < epsilon &&
                            pt3[2, 0] < epsilon);
                    }

            double rotationAngle = 0.2;

            q.SetEuler(rotationAngle, 0.0, 0.0);
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);
            q.SetEuler(0.0, rotationAngle, 0.0);
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);
            q.SetEuler(0.0, 0.0, rotationAngle);
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);

            q = q * q;
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle / 2.0 - rotationAngle) < epsilon);

            q.SetEuler(0.2, 0.1, 0.05);
            double t = q.RotationAngle;

            q = q * q;
            EmguAssert.IsTrue(Math.Abs(q.RotationAngle / 2.0 - t) < epsilon);
        }
      public void TestQuaternions1()
      {
         Quaternions q = new Quaternions();
         double epsilon = 1.0e-10;

         Matrix<double> point = new Matrix<double>(3, 1);
         point.SetRandNormal(new MCvScalar(), new MCvScalar(20));
         using (Matrix<double> pt1 = new Matrix<double>(3, 1))
         using (Matrix<double> pt2 = new Matrix<double>(3, 1))
         using (Matrix<double> pt3 = new Matrix<double>(3, 1))
         {
            double x1 = 1.0, y1 = 0.2, z1 = 0.1;
            double x2 = 0.0, y2 = 0.0, z2 = 0.0;

            q.SetEuler(x1, y1, z1);
            q.GetEuler(ref x2, ref y2, ref z2);

            EmguAssert.IsTrue(
               Math.Abs(x2 - x1) < epsilon &&
               Math.Abs(y2 - y1) < epsilon &&
               Math.Abs(z2 - z1) < epsilon);

            q.RotatePoints(point, pt1);

            Matrix<double> rMat = new Matrix<double>(3, 3);
            q.GetRotationMatrix(rMat);
            CvInvoke.Gemm(rMat, point, 1.0, null, 0.0, pt2, Emgu.CV.CvEnum.GemmType.Default);

            CvInvoke.AbsDiff(pt1, pt2, pt3);

            EmguAssert.IsTrue(
               pt3[0, 0] < epsilon &&
               pt3[1, 0] < epsilon &&
               pt3[2, 0] < epsilon);

         }

         double rotationAngle = 0.2;
         q.SetEuler(rotationAngle, 0.0, 0.0);
         EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);
         q.SetEuler(0.0, rotationAngle, 0.0);
         EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);
         q.SetEuler(0.0, 0.0, rotationAngle);
         EmguAssert.IsTrue(Math.Abs(q.RotationAngle - rotationAngle) < epsilon);

         q = q * q;
         EmguAssert.IsTrue(Math.Abs(q.RotationAngle / 2.0 - rotationAngle) < epsilon);

         q.SetEuler(0.2, 0.1, 0.05);
         double t = q.RotationAngle;
         q = q * q;
         EmguAssert.IsTrue(Math.Abs(q.RotationAngle / 2.0 - t) < epsilon);

      }
      public void TestQuaternionEulerAngleAndRotate()
      {
         double epsilon = 1.0e-12;
         Random r = new Random();
         Quaternions q1 = new Quaternions();
         double roll1 = r.NextDouble(), pitch1 = r.NextDouble(), yaw1 = r.NextDouble();
         double roll2 = 0, pitch2 = 0, yaw2 = 0;
         q1.SetEuler(roll1, pitch1, yaw1);
         q1.GetEuler(ref roll2, ref pitch2, ref yaw2);
         EmguAssert.IsTrue(Math.Abs(roll1 - roll2) < epsilon);
         EmguAssert.IsTrue(Math.Abs(pitch1 - pitch2) < epsilon);
         EmguAssert.IsTrue(Math.Abs(yaw1 - yaw2) < epsilon);

         Quaternions q2 = new Quaternions();
         q2.SetEuler(r.NextDouble(), r.NextDouble(), r.NextDouble());

         MCvPoint3D64f p = new MCvPoint3D64f(r.NextDouble() * 10, r.NextDouble() * 10, r.NextDouble() * 10);

         MCvPoint3D64f delta = (q1 * q2).RotatePoint(p) - q1.RotatePoint(q2.RotatePoint(p));

         EmguAssert.IsTrue(delta.X < epsilon);
         EmguAssert.IsTrue(delta.Y < epsilon);
         EmguAssert.IsTrue(delta.Z < epsilon);

      }