public void CD_GJKDistanceRectangles() { var pa = new Rectangle(-2, 0, 1, 1).ToPolygon(); var pb = new Rectangle(2, 0, 1, 1).ToPolygon(); var gjk = new GilbertJohnsonKeerthiAlgorithm(); gjk.DistanceBetween(pa, pb).Should().Be(3); }
public void CD_GJKCollisionRectangles() { var pa = new Rectangle(-2, 0, 1, 1).ToPolygon(); var pb = new Rectangle(2, 0, 1, 1).ToPolygon(); var gjk = new GilbertJohnsonKeerthiAlgorithm(); gjk.DistanceBetween(pa, pb).Should().Be(3); gjk.AreColliding(pa, pb).Should().BeFalse(); pb.TranslateSelf(-3.1f * Vector2.UnitX); gjk.DistanceBetween(pa, pb).Should().Be(0); gjk.AreColliding(pa, pb).Should().BeTrue(); }
public void CD_GJKCollisionL() { var pa = TetrisL.Translate(-2 * Vector2.UnitX); var pb = TetrisL.Translate(2 * Vector2.UnitX); var gjk = new GilbertJohnsonKeerthiAlgorithm(); gjk.DistanceBetween(pa, pb).Should().Be(2); gjk.AreColliding(pa, pb).Should().BeFalse(); pb.TranslateSelf(-2.1f * Vector2.UnitX); gjk.DistanceBetween(pa, pb).Should().Be(0); gjk.AreColliding(pa, pb).Should().BeTrue(); }
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)); }
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}."); } }