public void Test0()
        {
            var tta = new TriangleTriangleAlgorithm(new CollisionDetection());

            int numberOfContacts = 0;
            int numberOfTests    = 10000;

            RandomHelper.Random = new Random(1234567);
            for (int i = 0; i < numberOfTests; i++)
            {
                // Create two triangles.
                var tA = new Triangle();
                tA.Vertex0 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
                tA.Vertex1 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
                tA.Vertex2 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));

                var tB = new Triangle();
                tB.Vertex0 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
                tB.Vertex1 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
                tB.Vertex2 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));

                var ttTest = GeometryHelper.HaveContact(tA, tB);

                if (ttTest)
                {
                    numberOfContacts++;
                }

                var coA = new CollisionObject(new GeometricObject(new TriangleShape(tA)));
                var coB = new CollisionObject(new GeometricObject(new TriangleShape(tB)));

                var cs = tta.GetContacts(coA, coB);

                Assert.AreEqual(ttTest, cs.HaveContact);

                if (cs.HaveContact)
                {
                    Assert.AreEqual(1, cs.Count);
                    var epsilon = 0.01f;
                    if (!GeometryHelper.IsOver(tA, cs[0].PositionAWorld, epsilon))
                    {
                        Debugger.Break();
                    }
                    if (!GeometryHelper.IsOver(tB, cs[0].PositionBWorld, epsilon))
                    {
                        Debugger.Break();
                    }
                    Assert.IsTrue(GeometryHelper.IsOver(tA, cs[0].PositionAWorld, epsilon));
                    Assert.IsTrue(GeometryHelper.IsOver(tB, cs[0].PositionBWorld, epsilon));
                }
            }

            //Trace.WriteLine("% hits:" + 100f * numberOfContacts / numberOfTests);
        }
        public void TestCoplanar()
        {
            var tta = new TriangleTriangleAlgorithm(new CollisionDetection());
            var gjk = new Gjk(new CollisionDetection());

            int numberOfContacts = 0;
            int numberOfTests    = 1000;

            RandomHelper.Random = new Random(1234567);
            for (int i = 0; i < numberOfTests; i++)
            {
                // Create two triangles.
                var tA = new Triangle();
                tA.Vertex0 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
                tA.Vertex1 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
                tA.Vertex2 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));

                var tB = new Triangle();
                tB.Vertex0 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
                tB.Vertex1 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
                tB.Vertex2 = new Vector3(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));

                var ttTest = GeometryHelper.HaveContact(tA, tB);

                if (ttTest)
                {
                    numberOfContacts++;
                }

                var coA = new CollisionObject(new GeometricObject(new TriangleShape(tA)));
                var coB = new CollisionObject(new GeometricObject(new TriangleShape(tB)));

                var csTta = tta.GetContacts(coA, coB);
                var csGjk = gjk.GetClosestPoints(coA, coB);

                if (csTta.HaveContact != csGjk.HaveContact)
                {
                    Trace.WriteLine("Test failed: " + i + " GJK: " + csGjk.HaveContact + " TTA: " + csTta);
                }

                Assert.AreEqual(ttTest, csGjk.HaveContact);
                Assert.AreEqual(ttTest, csTta.HaveContact);
            }

            //Trace.WriteLine("% hits:" + 100f * numberOfContacts / numberOfTests);
        }
Example #3
0
        public void TestCoplanar()
        {
            var tta = new TriangleTriangleAlgorithm(new CollisionDetection());
              var gjk = new Gjk(new CollisionDetection());

              int numberOfContacts = 0;
              int numberOfTests = 1000;
              RandomHelper.Random = new Random(1234567);
              for (int i = 0; i < numberOfTests; i++)
              {
            // Create two triangles.
            var tA = new Triangle();
            tA.Vertex0 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
            tA.Vertex1 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
            tA.Vertex2 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));

            var tB = new Triangle();
            tB.Vertex0 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
            tB.Vertex1 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));
            tB.Vertex2 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), -290, RandomHelper.Random.NextFloat(-100, 100));

            var ttTest = GeometryHelper.HaveContact(tA, tB);

            if (ttTest)
              numberOfContacts++;

            var coA = new CollisionObject(new GeometricObject(new TriangleShape(tA)));
            var coB = new CollisionObject(new GeometricObject(new TriangleShape(tB)));

            var csTta = tta.GetContacts(coA, coB);
            var csGjk = gjk.GetClosestPoints(coA, coB);

            if (csTta.HaveContact != csGjk.HaveContact)
              Trace.WriteLine("Test failed: " + i + " GJK: " + csGjk.HaveContact + " TTA: " + csTta);

            Assert.AreEqual(ttTest, csGjk.HaveContact);
            Assert.AreEqual(ttTest, csTta.HaveContact);
              }

              //Trace.WriteLine("% hits:" + 100f * numberOfContacts / numberOfTests);
        }
Example #4
0
        public void Test0()
        {
            var tta = new TriangleTriangleAlgorithm(new CollisionDetection());

              int numberOfContacts = 0;
              int numberOfTests = 10000;
              RandomHelper.Random = new Random(1234567);
              for (int i = 0; i < numberOfTests; i++)
              {
            // Create two triangles.
            var tA = new Triangle();
            tA.Vertex0 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
            tA.Vertex1 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
            tA.Vertex2 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));

            var tB = new Triangle();
            tB.Vertex0 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
            tB.Vertex1 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));
            tB.Vertex2 = new Vector3F(RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100), RandomHelper.Random.NextFloat(-100, 100));

            var ttTest = GeometryHelper.HaveContact(tA, tB);

            if (ttTest)
              numberOfContacts++;

            var coA = new CollisionObject(new GeometricObject(new TriangleShape(tA)));
            var coB = new CollisionObject(new GeometricObject(new TriangleShape(tB)));

            var cs = tta.GetContacts(coA, coB);

            Assert.AreEqual(ttTest, cs.HaveContact);

            if (cs.HaveContact)
            {
              Assert.AreEqual(1, cs.Count);
              var epsilon = 0.01f;
              if (!GeometryHelper.IsOver(tA, cs[0].PositionAWorld, epsilon))
            Debugger.Break();
              if (!GeometryHelper.IsOver(tB, cs[0].PositionBWorld, epsilon))
            Debugger.Break();
              Assert.IsTrue(GeometryHelper.IsOver(tA, cs[0].PositionAWorld, epsilon));
              Assert.IsTrue(GeometryHelper.IsOver(tB, cs[0].PositionBWorld, epsilon));
            }
              }

              //Trace.WriteLine("% hits:" + 100f * numberOfContacts / numberOfTests);
        }