# Collision of rectangles

#### r4nd0m

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

#### AKG

Homework Helper
A couple ideas here to help you, not much because I'm at work right now. For one, motion is relative, so if you have a velocity vectors v1 and v2, then just treat the second rectangle as motionless and treat the first one as though it were moving at velocity v1 - v2. The two rectangles will intersect if and only if:

a) the vertical distance between the centers of the rectangles is less than or equal to V = 0.5(the vertical height of rectangle 1 + the vertical height of rectangle 2)

AND

b) the horizontal distance between the centers of the rectangles is less than or equal to H = 0.5(the horizontal width of recantle 1 + the horizontal width of rectangle 2)

It should be quite easy to make a program that checks if these conditions are ever met. The plot of horizontal distance between centers over time will look like an absolute value graph (V shape) and same for vertical distance. You will be able to solve for 0, 1, or 2 points in time where the horizontal distance between centers is exactly equal to H. If there are 0 point in time, then no intersection. If there is one, and it occurs at time t, then plug in t in your equation to find the vertical distance, and see if the vertical distance between centers is less than equal to V. If so, then they meet at t, otherwise they don't. If you find two points of time, t and t' (assume t < t'), then do a similar calculation for vertical distance so you find either 0, 1, or 2 points in time when the vertical distance is exaclty equal to V. If 0, no intersection. If 1, and it occurs at time t'', check if t < t'' < t'. If so, then they intersect only once at t'', otherwise never. Finally, say you find two times, t'' and t'''. You want to find the smallest t value that is in both intervals [t,t'] and [t'',t''']. You can figure out how to do that.

### 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
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}