Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
4 replies to this topic

#1 DaviDeMo   Members   -  Reputation: 118

Like
0Likes
Like

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



Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2601

Like
3Likes
Like

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


#3 DaviDeMo   Members   -  Reputation: 118

Like
0Likes
Like

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



#4 Glass_Knife   Moderators   -  Reputation: 4821

Like
0Likes
Like

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"
Indie Game Programming

#5 Glass_Knife   Moderators   -  Reputation: 4821

Like
0Likes
Like

Posted 17 July 2014 - 12:44 PM

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"
Indie Game Programming




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.



PARTNERS