Collision of rectangles

  • Thread starter r4nd0m
  • Start date
  • #1
96
1
I wonder if somebody could help me with this problem I'm solving for my c language class (but it's more a mathematical problem I think).
So we have 2 different rectangles (ABCD and EFGH) in an ortogonal plane, their sides are paralel to the axes of the ortogonal system. Each of this rectangles is given a velocity vector. Now the task is to determine where the first collision will take place (where these two rectangles (their sides or corners) will meet the first time) if it will take place.
Any suggestions?
Can this problem be solved via mathematicl formulas?
thanks a lot
 

Answers and Replies

  • #2
509
0
I would have to think more about this to solve it mathematically, but if you're talking about computing a bounding-box collision when it happens, what you do is check at every step to see if the two boxes have collided. This will happen if and only if the top or bottom line of one box is between the bottom line of the other box and the top line of the other box, AND the left or right line of one box is between the left and right lines of the other box.

This is not totally precise--you could miss a corner collision in between steps, if the steps are large enough and the collision is close enough to the corners. To do it mathematically would require more work.
 

Related Threads on Collision of rectangles

  • Last Post
Replies
1
Views
4K
  • Last Post
Replies
1
Views
6K
  • Last Post
Replies
9
Views
14K
Replies
1
Views
2K
Replies
12
Views
110
Replies
24
Views
5K
Replies
1
Views
8K
  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
2
Views
5K
Replies
4
Views
884
Top