• Support PF! Buy your school textbooks, materials and every day products via PF Here!

Collision of rectangles

  • Thread starter r4nd0m
  • Start date
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
 
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 for: Collision of rectangles

  • Posted
Replies
1
Views
4K
  • Posted
Replies
1
Views
6K
Replies
9
Views
14K
Replies
1
Views
2K
Replies
1
Views
7K
Replies
24
Views
5K
  • Posted
Replies
5
Views
2K
Replies
4
Views
814

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top