Collision of rectangles

  • Thread starter r4nd0m
  • Start date
  • #1
r4nd0m
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 parallel 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
BicycleTree
520
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.
 

Suggested for: Collision of rectangles

Replies
2
Views
312
  • Last Post
Replies
18
Views
653
  • Last Post
Replies
9
Views
119
Replies
2
Views
192
Replies
20
Views
579
Replies
9
Views
327
Replies
16
Views
741
Replies
28
Views
1K
Replies
3
Views
656
Replies
15
Views
323
Top