예제 #1
0
        public void CD_GJK_EPA_PenetrationDepth()
        {
            var pa = new Polygon(Diamond.Points.Select(x => 10 * x));
            var pb = new RectangleF(9.5f, -10, 10, 20).ToPolygon();

            var gjk = new GilbertJohnsonKeerthiAlgorithm();

            var simplex = gjk.FindMinkowskiSimplex(pa, pb);
            var epa     = new ExpandingPolytopeAlgorithm();

            var pv = epa.PenetrationDepth(
                v => GilbertJohnsonKeerthiAlgorithm.PolygonSupport(pa, v),
                v => GilbertJohnsonKeerthiAlgorithm.PolygonSupport(pb, v),
                simplex);

            simplex.ContainsOrigin.Should().BeTrue();
            pv.Should().Be(new Vector2(0.5f, 0));
        }
예제 #2
0
        public void CD_GJK_EPA_GradualPenetrationDepth()
        {
            for (float d = 0.05f; d < 1; d += 0.05f)
            {
                var pa = new Polygon(Diamond.Points.Select(x => 10 * x));
                var pb = new RectangleF(10 - d, -10, 10, 20).ToPolygon();

                var gjk = new GilbertJohnsonKeerthiAlgorithm();

                var simplex = gjk.FindMinkowskiSimplex(pa, pb);
                var epa     = new ExpandingPolytopeAlgorithm();

                var pv = epa.PenetrationDepth(
                    v => GilbertJohnsonKeerthiAlgorithm.PolygonSupport(pa, v),
                    v => GilbertJohnsonKeerthiAlgorithm.PolygonSupport(pb, v),
                    simplex);

                simplex.ContainsOrigin.Should().BeTrue($"Collision not detected by Minkowski simplex at {d}.");
                Vector2X.Equals(new Vector2(d, 0), pv.Value, 1e-6f).Should().BeTrue($"Penetration depth test failed at {d}.");
            }
        }