Ejemplo n.º 1
0
        public static void OrthoNormalOrientation()
        {
            // Previous implementation
            Func <Trafo3d, Trafo3d> reference = trafo =>
            {
                var x = trafo.Forward.C0.XYZ.Normalized; // TransformDir(V3f.XAxis)
                var y = trafo.Forward.C1.XYZ.Normalized; // TransformDir(V3f.YAxis)
                var z = trafo.Forward.C2.XYZ.Normalized; // TransformDir(V3f.ZAxis)

                y = z.Cross(x).Normalized;
                z = x.Cross(y).Normalized;

                return(Trafo3d.FromBasis(x, y, z, V3d.Zero));
            };

            var rnd = new RandomSystem(1);

            TrafoTesting.GenericTest(rnd =>
            {
                var trafo = TrafoTesting.GetRandomTrafo(rnd);

                var res     = trafo.GetOrthoNormalOrientation();
                var res_ref = reference(trafo);

                TrafoTesting.AreEqual(res, res_ref);
            });
        }
Ejemplo n.º 2
0
        public static void FromEuler()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var euler = rnd.UniformV3dFull() * Constant.PiTimesFour - Constant.PiTimesTwo;

                var rot = Rot3d.RotationEuler(euler);

                var qx   = Rot3d.RotationX(euler.X);
                var qy   = Rot3d.RotationY(euler.Y);
                var qz   = Rot3d.RotationZ(euler.Z);
                var test = qz * qy * qx;

                TrafoTesting.AreEqual(rot, test);

                var euler2 = rot.GetEulerAngles();
                var rot2   = Rot3d.RotationEuler(euler2);

                var rot2M = (M33d)rot2;
                var rotM  = (M33d)rot;

                if (!Fun.ApproximateEquals(rot2M, rotM, 1e-6))
                {
                    Report.Line("FA");
                }

                Assert.IsTrue(Fun.ApproximateEquals(rot2M, rotM, 1e-6));
            });
        }
Ejemplo n.º 3
0
        public static void MultiplicationScaleTest()
        => TrafoTesting.GenericTest(rnd =>
        {
            var a = TrafoTesting.GetRandomRot2(rnd);
            var b = TrafoTesting.GetRandomScale2(rnd);

            var p = rnd.UniformV2d() * rnd.UniformInt(1000);

            {
                var trafo = a * b;
                var res   = trafo.TransformPos(p);

                var trafoRef = (M33d)a * (M33d)b;
                var resRef   = trafoRef.TransformPos(p);

                TrafoTesting.AreEqual(res, resRef);
            }

            {
                var trafo = b * a;
                var res   = trafo.TransformPos(p);

                var trafoRef = (M33d)b * (M33d)a;
                var resRef   = trafoRef.TransformPos(p);

                TrafoTesting.AreEqual(res, resRef);
            }
        });
Ejemplo n.º 4
0
        public static void MultiplicationFull2x3Test()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var m = TrafoTesting.GetRandom2x3(rnd);
                var r = TrafoTesting.GetRandomRot2(rnd);

                var mr = m * r;
                var rm = r * m;

                var mr_ref = m * (M33d)r;
                var rm_ref = (M23d)r * (M33d)m;

                {
                    var p          = rnd.UniformV2d() * rnd.UniformInt(1000);
                    var res_mr     = mr.TransformPos(p);
                    var res_mr_ref = mr_ref.TransformPos(p);
                    var res_rm     = rm.TransformPos(p);
                    var res_rm_ref = rm_ref.TransformPos(p);

                    TrafoTesting.AreEqual(res_mr, res_mr_ref);
                    TrafoTesting.AreEqual(res_rm, res_rm_ref);
                }
            });
        }
Ejemplo n.º 5
0
        public static void FromM33dAndV3d()
        => TrafoTesting.GenericTest(rnd =>
        {
            var a = TrafoTesting.GetRandomEuclidean(rnd);
            var m = (M33d)a.Rot;
            var t = a.Trans;

            var restored = Euclidean3d.FromM33dAndV3d(m, t);
            TrafoTesting.AreEqual(a, restored);
        });
Ejemplo n.º 6
0
        public static void FromM33dAndV3d()
        => TrafoTesting.GenericTest(rnd =>
        {
            var a   = TrafoTesting.GetRandomSimilarity(rnd);
            var tmp = (M34d)a;
            var m   = (M33d)tmp;
            var t   = tmp.C3;

            var restored = Similarity3d.FromM33dAndV3d(m, t);
            TrafoTesting.AreEqual(a, restored);
        });
Ejemplo n.º 7
0
        public static void DistanceTest()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var delta = (rnd.UniformDouble() - 0.5) * 2.0 * Constant.Pi;
                var r1    = TrafoTesting.GetRandomRot2(rnd);
                var r2    = new Rot2d(r1.Angle + (delta + Constant.PiTimesTwo * rnd.UniformInt(10)));

                var dist = r1.Distance(r2);
                TrafoTesting.AreEqual(dist, Fun.Abs(delta));
            });
        }
Ejemplo n.º 8
0
        public static void MultiplicationAffine3x4Test()
        => TrafoTesting.GenericTest(rnd =>
        {
            var a  = TrafoTesting.GetRandomAffine(rnd);
            var b  = TrafoTesting.GetRandomAffine(rnd);
            var ma = (M34d)a;
            var mb = (M34d)b;

            var a_x_b   = a * b;
            var ma_x_mb = Mat.MultiplyAffine(ma, mb);

            TrafoTesting.AreEqual((M34d)a_x_b, ma_x_mb);
        });
Ejemplo n.º 9
0
        public static void ConsistentWithMatrixScaleTest()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var scale = rnd.UniformV3d() * 10;
                var m     = M33d.Scale(scale);
                var r     = new Scale3d(scale);

                var p    = rnd.UniformV3d() * rnd.UniformInt(1000);
                var res  = m.Transform(p);
                var res2 = r.Transform(p);

                TrafoTesting.AreEqual(res, res2);
            });
        }
Ejemplo n.º 10
0
        public static void ConsistentWithMatrixShiftTest()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var shift = rnd.UniformV3d() * 10;
                var m     = M34d.Translation(shift);
                var r     = new Shift3d(shift);

                var p    = rnd.UniformV3d() * rnd.UniformInt(1000);
                var res  = m.TransformPos(p);
                var res2 = r.Transform(p);

                TrafoTesting.AreEqual(res, res2);
            });
        }
Ejemplo n.º 11
0
        public static void ConsistentWithMatrixRotationTest()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var angle = rnd.UniformDouble() * Constant.PiTimesTwo;
                var m     = M22d.Rotation(angle);
                var r     = new Rot2d(angle);

                var p    = rnd.UniformV2d() * rnd.UniformInt(1000);
                var res  = m.Transform(p);
                var res2 = r.Transform(p);

                TrafoTesting.AreEqual(res, res2);
            });
        }
Ejemplo n.º 12
0
        public static void ConsistentWithMatrixRotationAndShiftTest()
        => TrafoTesting.GenericTest(rnd =>
        {
            var trans = rnd.UniformV3d() * 10;

            var axis  = rnd.UniformV3dDirection();
            var angle = rnd.UniformDouble() * Constant.PiTimesTwo;

            var m = M44d.Translation(trans) * M44d.Rotation(axis, angle);
            var e = new Euclidean3d(Rot3d.Rotation(axis, angle), trans);

            var p    = rnd.UniformV3d() * rnd.UniformInt(1000);
            var res  = m.TransformPos(p);
            var res2 = e.TransformPos(p);

            TrafoTesting.AreEqual(res, res2);
        });
Ejemplo n.º 13
0
        public static void InverseTest()
        => TrafoTesting.GenericTest(rnd =>
        {
            var t = TrafoTesting.GetRandomTrafo(rnd, false);

            var p = rnd.UniformV3d() * rnd.UniformInt(1000);
            var q = t.Forward.TransformPos(p);

            // Inverse property
            var res = t.Inverse.Forward.TransformPos(q);

            // Backward
            var res2 = t.Backward.TransformPos(q);

            TrafoTesting.AreEqual(p, res);
            TrafoTesting.AreEqual(p, res2);
        });
Ejemplo n.º 14
0
        /// <summary>
        /// Tests multiplication of T trafos with their M matrix representations.
        /// </summary>
        public static void GenericMatrixMultiplicationTest <T, M, M2>(
            Func <RandomSystem, T> frnd,
            Func <T, V3d, V3d> trafoTransform,
            Func <M, V3d, V3d> matrixTransform,
            Func <M2, V3d, V3d> matrixTransform2,
            Func <T, V3d, V3d> trafoMul,
            Func <M, V3d, V3d> matrixMul,
            Func <M2, V3d, V3d> matrixMul2,
            bool squareMatrix = true)
        => GenericTest(rnd =>
        {
            dynamic a  = frnd(rnd);
            dynamic b  = frnd(rnd);
            dynamic ma = (M)a;
            dynamic mb = (M)b;

            var a_x_b   = a * b;
            var ma_x_b  = ma * b;
            var a_x_mb  = a * mb;
            var ma_x_mb = (squareMatrix) ? ma * mb : null;

            var p = rnd.UniformV3d() * rnd.UniformInt(1000);

            {
                var res  = trafoTransform(a_x_b, p);
                var res2 = matrixTransform2(ma_x_b, p);
                var res3 = matrixTransform2(a_x_mb, p);
                var res4 = squareMatrix ? matrixTransform(ma_x_mb, p) : res3;

                TrafoTesting.AreEqual(res, res2);
                TrafoTesting.AreEqual(res, res3);
                TrafoTesting.AreEqual(res, res4);
            }

            {
                var res  = trafoMul(a_x_b, p);
                var res2 = matrixMul2(ma_x_b, p);
                var res3 = matrixMul2(a_x_mb, p);
                var res4 = squareMatrix ? matrixMul(ma_x_mb, p) : res3;

                TrafoTesting.AreEqual(res, res2);
                TrafoTesting.AreEqual(res, res3);
                TrafoTesting.AreEqual(res, res4);
            }
        });
Ejemplo n.º 15
0
        public static void InverseTest()
        => TrafoTesting.GenericTest(rnd =>
        {
            var s = TrafoTesting.GetRandomSimilarity(rnd);

            var p = rnd.UniformV3d() * rnd.UniformInt(1000);
            var q = s.TransformPos(p);

            // Inverse property
            var res = s.Inverse.TransformPos(q);

            // Invert method
            Similarity.Invert(ref s);
            var res2 = s.TransformPos(q);

            TrafoTesting.AreEqual(p, res);
            TrafoTesting.AreEqual(p, res2);
        });
Ejemplo n.º 16
0
        public static void InverseTest()
        => TrafoTesting.GenericTest(rnd =>
        {
            var e = TrafoTesting.GetRandomEuclidean(rnd);

            var p = rnd.UniformV3d() * rnd.UniformInt(1000);
            var q = e.TransformPos(p);

            // Inverse property
            var res = e.Inverse.TransformPos(q);

            // Invert method
            Euclidean.Invert(ref e);
            var res2 = e.TransformPos(q);

            TrafoTesting.AreEqual(p, res);
            TrafoTesting.AreEqual(p, res2);
        });
Ejemplo n.º 17
0
        public static void InverseTest()
        => TrafoTesting.GenericTest(rnd =>
        {
            var a = TrafoTesting.GetRandomAffine(rnd);

            var p = rnd.UniformV3d() * rnd.UniformInt(1000);
            var q = a.TransformPos(p);

            // Inverse property
            var res = a.Inverse.TransformPos(q);

            // Invert method
            Affine.Invert(ref a);
            var res2 = a.TransformPos(q);

            TrafoTesting.AreEqual(p, res);
            TrafoTesting.AreEqual(p, res2);
        });
Ejemplo n.º 18
0
        public static void InverseTest()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var r = TrafoTesting.GetRandomRot2(rnd);

                var p = rnd.UniformV2d() * rnd.UniformInt(1000);
                var q = r.Transform(p);

                // Inverse property
                var res = r.Inverse.Transform(q);

                // Invert method
                Rot.Invert(ref r);
                var res2 = r.Transform(q);

                TrafoTesting.AreEqual(p, res);
                TrafoTesting.AreEqual(p, res2);
            });
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Tests multiplication of T trafos with random M matrices.
        /// </summary>
        public static void GenericFullMatrixMultiplicationTest <T, M, MAugmented>(
            Func <RandomSystem, T> frnd,
            Func <RandomSystem, M> frndMatrix,
            Func <M, V3d, V3d> matrixTransform,
            Func <M, V3d, V3d> matrixMul)
        => GenericTest(rnd =>
        {
            dynamic m     = frndMatrix(rnd);
            dynamic t     = frnd(rnd);
            dynamic maugm = (MAugmented)m;
            dynamic maugt = (MAugmented)t;
            dynamic mt    = (M)t;

            var m_x_t = m * t;
            var t_x_m = t * m;

            var m_x_t_ref = m * maugt;
            var t_x_m_ref = mt * maugm;

            var p = rnd.UniformV3d() * rnd.UniformInt(1000);

            {
                var res_mt     = matrixTransform(m_x_t, p);
                var res_mt_ref = matrixTransform(m_x_t_ref, p);
                var res_tm     = matrixTransform(t_x_m, p);
                var res_tm_ref = matrixTransform(t_x_m_ref, p);

                TrafoTesting.AreEqual(res_mt, res_mt_ref);
                TrafoTesting.AreEqual(res_tm, res_tm_ref);
            }

            {
                var res_mt     = matrixMul(m_x_t, p);
                var res_mt_ref = matrixMul(m_x_t_ref, p);
                var res_tm     = matrixMul(t_x_m, p);
                var res_tm_ref = matrixMul(t_x_m_ref, p);

                TrafoTesting.AreEqual(res_mt, res_mt_ref);
                TrafoTesting.AreEqual(res_tm, res_tm_ref);
            }
        });
Ejemplo n.º 20
0
        public static void Multiplication2x3Test()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var r1 = TrafoTesting.GetRandomRot2(rnd);
                var r2 = TrafoTesting.GetRandomRot2(rnd);
                var r  = r1 * r2;
                var rm = (M23d)r1 * r2;
                var mr = r1 * (M23d)r2;

                {
                    var p    = rnd.UniformV2d() * rnd.UniformInt(1000);
                    var res  = r.Transform(p);
                    var res2 = rm.TransformPos(p);
                    var res3 = mr.TransformPos(p);

                    TrafoTesting.AreEqual(res, res2);
                    TrafoTesting.AreEqual(res, res3);
                }
            });
        }
Ejemplo n.º 21
0
        public static void RotationXYZ()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var angle = rnd.UniformDouble() * Constant.PiTimesFour - Constant.PiTimesTwo;

                var rotX1 = Rot3d.RotationX(angle);
                var rotX2 = Rot3d.Rotation(V3d.XAxis, angle);

                TrafoTesting.AreEqual(rotX1, rotX2);

                var rotY1 = Rot3d.RotationY(angle);
                var rotY2 = Rot3d.Rotation(V3d.YAxis, angle);

                TrafoTesting.AreEqual(rotY1, rotY2);

                var rotZ1 = Rot3d.RotationZ(angle);
                var rotZ2 = Rot3d.Rotation(V3d.ZAxis, angle);

                TrafoTesting.AreEqual(rotZ1, rotZ2);
            });
        }
Ejemplo n.º 22
0
        public static void InverseTest()
        {
            TrafoTesting.GenericTest(rnd =>
            {
                var s = TrafoTesting.GetRandomShift3(rnd);

                var p = rnd.UniformV3d() * rnd.UniformInt(1000);
                var q = s.Transform(p);

                // Inverse property
                var res = s.Inverse.Transform(q);

                // InvTransform
                var res2 = s.InvTransform(q);

                // Invert method
                Shift.Invert(ref s);
                var res3 = s.Transform(q);

                TrafoTesting.AreEqual(p, res);
                TrafoTesting.AreEqual(p, res2);
                TrafoTesting.AreEqual(p, res3);
            });
        }