Index: Trunk/Modules/Annulus/Annulus.UnitTests/SweptCollisionDetection/PolygonvsPolygonTests.cs =================================================================== --- Trunk/Modules/Annulus/Annulus.UnitTests/SweptCollisionDetection/PolygonvsPolygonTests.cs (revision 998) +++ Trunk/Modules/Annulus/Annulus.UnitTests/SweptCollisionDetection/PolygonvsPolygonTests.cs (working copy) @@ -4446,6 +4446,197 @@ CheckEqual(expected, output); } + public void TwoSquaresSpinning() + { + var hSqrt2 = Math.Sqrt(2); + + var polygonSquare = new SimplePolygon(new Vector[] + { + new Vector(-1, 1), + new Vector( 1, 1), + new Vector( 1,-1), + new Vector(-1,-1), + }); + var polygonDiamont = new SimplePolygon(new Vector[] + { + new Vector(0, hSqrt2), + new Vector(hSqrt2, 0), + new Vector(0,-hSqrt2), + new Vector(-hSqrt2,0), + }); + + var input = new PolygonvsPolygon.Input + { + polygon_A = new PolygonvsPolygon.SimplePolygonInMotion + { + polygon = polygonSquare, + motion = new Motion + { + AngularVelocity = Math.PI / 4, + InitialPosition = new Vector(0, hSqrt2*2), + LinearVelocity = new Vector(0, 0), + }, + payload = 7, + }, + + polygon_B = new PolygonvsPolygon.SimplePolygonInMotion + { + polygon = polygonSquare, + motion = new Motion + { + AngularVelocity = Math.PI / 4, + }, + + payload = 25, + }, + + impactWindow = new Interval(0, 8), + }; + + int iterations = 0; + var output = PolygonvsPolygon.FindIntersectionsInWindow(input, ref iterations); + + var expected = new PolygonvsPolygon.Hit[] + { + new PolygonvsPolygon.VertexVertexCollision + { + VertexA = polygonSquare.GetVertex(3), + VertexB = polygonSquare.GetVertex(1), + TOI = 1, + Transition = PolygonvsPolygon.TransitionState.GlancingParallel, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + new PolygonvsPolygon.VertexVertexCollision + { + VertexA = polygonSquare.GetVertex(0), + VertexB = polygonSquare.GetVertex(2), + TOI = 3, + Transition = PolygonvsPolygon.TransitionState.GlancingParallel, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + new PolygonvsPolygon.VertexVertexCollision + { + VertexA = polygonSquare.GetVertex(1), + VertexB = polygonSquare.GetVertex(3), + TOI = 5, + Transition = PolygonvsPolygon.TransitionState.GlancingParallel, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + new PolygonvsPolygon.VertexVertexCollision + { + VertexA = polygonSquare.GetVertex(2), + VertexB = polygonSquare.GetVertex(0), + TOI = 7, + Transition = PolygonvsPolygon.TransitionState.GlancingParallel, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + }; + + CheckEqual(expected, output); + } + + public void SquareInsideSpinning() + { + var hSqrt2 = Math.Sqrt(2); + + var polygonSquare = new SimplePolygon(new Vector[] + { + new Vector(-1, 1), + new Vector( 1, 1), + new Vector( 1,-1), + new Vector(-1,-1), + }); + var polygonBigSquare = new SimplePolygon(new Vector[] + { + new Vector(-2, 2), + new Vector( 2, 2), + new Vector( 2,-2), + new Vector(-2,-2), + }); + + + var input = new PolygonvsPolygon.Input + { + polygon_A = new PolygonvsPolygon.SimplePolygonInMotion + { + polygon = polygonSquare, + motion = new Motion + { + AngularVelocity = Math.PI / 4, + InitialPosition = new Vector(0, hSqrt2), + LinearVelocity = new Vector(0, 0), + }, + payload = 7, + }, + + polygon_B = new PolygonvsPolygon.SimplePolygonInMotion + { + polygon = polygonBigSquare, + motion = new Motion + { + InitialPosition = new Vector(0, 2), + }, + + payload = 25, + }, + + impactWindow = new Interval(0, 8), + }; + + int iterations = 0; + var output = PolygonvsPolygon.FindIntersectionsInWindow(input, ref iterations); + + var expected = new PolygonvsPolygon.Hit[] + { + new PolygonvsPolygon.VertexEdgeCollision + { + VertexA = polygonSquare.GetVertex(3), + EdgeB = polygonBigSquare.GetEdge(2), + TOI = 1, + HitFraction = 0.5, + Transition = PolygonvsPolygon.TransitionState.GlancingInside, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + new PolygonvsPolygon.VertexEdgeCollision + { + VertexA = polygonSquare.GetVertex(0), + EdgeB = polygonBigSquare.GetEdge(2), + TOI = 3, + HitFraction = 0.5, + Transition = PolygonvsPolygon.TransitionState.GlancingInside, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + new PolygonvsPolygon.VertexEdgeCollision + { + VertexA = polygonSquare.GetVertex(1), + EdgeB = polygonBigSquare.GetEdge(2), + TOI = 5, + HitFraction = 0.5, + Transition = PolygonvsPolygon.TransitionState.GlancingInside, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + new PolygonvsPolygon.VertexEdgeCollision + { + VertexA = polygonSquare.GetVertex(2), + EdgeB = polygonBigSquare.GetEdge(2), + TOI = 7, + HitFraction = 0.5, + Transition = PolygonvsPolygon.TransitionState.GlancingInside, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + }; + + CheckEqual(expected, output); + } + public void SquaresSliding() { var polygonSquare = new SimplePolygon(new Vector[] @@ -4522,6 +4713,67 @@ CheckEqual(expected, output); } + public void SquaresJustGlance() + { + var polygonSquare = new SimplePolygon(new Vector[] + { + new Vector(-1, 1), + new Vector( 1, 1), + new Vector( 1,-1), + new Vector(-1,-1), + }); + + var input = new PolygonvsPolygon.Input + { + polygon_A = new PolygonvsPolygon.SimplePolygonInMotion + { + polygon = polygonSquare, + motion = new Motion + { + InitialPosition = new Vector(3, 0), + LinearVelocity = new Vector(-2, 0), + LinearAcceleration = new Vector(1, 0), + }, + payload = 7, + }, + + polygon_B = new PolygonvsPolygon.SimplePolygonInMotion + { + polygon = polygonSquare, + motion = new Motion + { + InitialPosition = new Vector(-3, 0), + LinearVelocity = new Vector(2, 0), + LinearAcceleration = new Vector(-1, 0), + }, + + payload = 25, + }, + + impactWindow = new Interval(0, 8), + }; + + int iterations = 0; + var output = PolygonvsPolygon.FindIntersectionsInWindow(input, ref iterations); + + var expected = new PolygonvsPolygon.Hit[] + { + new PolygonvsPolygon.EdgeEdgeCollision + { + EdgeA = polygonSquare.GetEdge(3), + EdgeB = polygonSquare.GetEdge(1), + TOI = 2, + TrailingHitFraction = new Tuple(0, 1), + LeadingHitFraction = new Tuple(1, 0), + Transition = PolygonvsPolygon.TransitionState.GlancingParallel, + PayloadA = input.polygon_A.payload, + PayloadB = input.polygon_B.payload, + }, + }; + + CheckEqual(expected, output); + } + public void SquaresSlideBack() { var polygonSquare = new SimplePolygon(new Vector[]