1

Determining whether or not there was a collision between two AABB (axis-aligned bounding box) rectangles is trivial:

doRectanglesCollide(r1X, r1Y, r1W, r1H, r2X, r2Y, r2W, r2H) {
  return r1X < r2X + r2W && r1X + r1W > r2X && r1Y < r2Y + r2H && r1Y + r1H > r2Y;
}

Determining whether or not there was a collision between two rotated rectangles is much less efficient.

However, there is a trick. One can rotate both of the rectangles by the same amount such that one of them becomes an AABB rectangle.

At that point, one would simply need a function that determines whether an AABB rectangle and a rotated rectangle intersect. I assume it would be much more efficient than using the Separating Axis Theorem to determine if two rotated rectangles are intersecting, as the latter is a general formula for determining if two arbitrary polygons are intersecting.

So, to rephrase, here is my question: I have two rectangles that are rotated. Rather than using the linked answer, is there not a more efficient algorithm that takes advantage of the fact that one of the rectangles can be made into an AABB rectangle by rotating both of them by -radians? Because at that point it simply becomes the question of whether or not an AABB rectangle and a rotated rectangle are intersecting.

Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
  • 1
    Suggest breaking the problem down into triangle-to-triangle intersections. See related https://stackoverflow.com/questions/2778240/detection-of-triangle-collision-in-2d-space – Trentium Sep 10 '21 at 15:50

0 Answers0