2D rotated rectangle collision detection

Started by
3 comments, last by Glass_Knife 9 years, 9 months ago

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

Advertisement

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).

o3o

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


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.

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

My Twitter: https://twitter.com/indieprogram

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

Also, if you don't know about this resource, it is invaluable. I found the above link using it.

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

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

My Twitter: https://twitter.com/indieprogram

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

This topic is closed to new replies.

Advertisement