View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# 2D rotated rectangle collision detection

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1DaviDeMo  Members

Posted 17 July 2014 - 08:15 AM

Hi,

I have a basic math question. Today I was just like :"Hey, it's a basic AABB collision detection I have to code..." only after some minutes I remembered that my rectangles are rotating...

I have two rectangle.

I know the X and Y coordinates of the center of these two rectangle in the world.

I know the rotation (in rad) of the two rectangle.

I want to know when they are intersecting. I don't need to know where, I just want to know if yes or no :-)

Any idea? I have looked on google but maybe I'm searching the wrong keywords. An external link as a reply would be cool too ;-)

Thank you

### #2Waterlimon  Members

Posted 17 July 2014 - 08:50 AM

I think the tool to use here is the Separating Axis Theorem (SAT). If there is a plane/line that separates two objects, they dont intersect.

Basically, you would take all the planes (/lines) that bound your rectangle (based on the faces of the rectangle),

Then, for each of those, you check if the other box is completely on the 'outside' side of the plane (you can do this by checking each vertex separately).

If the above is true for even a single plane/line, there is no intersection.

This works for any convex shape. It wont get you the point of intersection though, but you didnt need that. Google for an optimal way to implement it, the above was just a vague description of how it works (might not even be exactly correct).

Edited by Waterlimon, 17 July 2014 - 08:53 AM.

o3o

### #3DaviDeMo  Members

Posted 17 July 2014 - 09:17 AM

Oh, great. Thank you for the name of the Theorem.

I have found this that seems cool

http://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169

### #4Glass_Knife  Moderators

Posted 17 July 2014 - 12:37 PM

I think the tool to use here is the Separating Axis Theorem (SAT). If there is a plane/line that separates two objects, they dont intersect.

+1

http://www.gamasutra.com/view/feature/131790/simple_intersection_tests_for_games.php?page=5

Just make sure that you don't take the radius value as a corner.  You must project the height and width onto the axis plane.

Edited by Glass_Knife, 17 July 2014 - 12:43 PM.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Book: http://amzn.com/1305076532

### #5Glass_Knife  Moderators

Posted 17 July 2014 - 12:44 PM

http://www.realtimerendering.com/intersections.html

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming