Calculating the First Collision Point of Two Moving Rectangles in C Language

  • Thread starter Thread starter r4nd0m
  • Start date Start date
  • Tags Tags
    Collision
AI Thread Summary
To determine the first collision point of two moving rectangles in C, treat one rectangle as stationary by adjusting the velocity of the other. The rectangles will intersect if the vertical distance between their centers is less than or equal to the combined heights, and the horizontal distance is less than or equal to the combined widths. A program can be created to check these conditions over time, analyzing the distances as functions that resemble absolute value graphs. By solving for points in time where these distances meet the intersection criteria, one can find the exact moment of collision. This approach effectively combines mathematical principles with programming logic to solve the problem.
r4nd0m
Messages
96
Reaction score
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
 
Mathematics news on Phys.org
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 exactly 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.
 
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Thread 'Imaginary Pythagorus'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Back
Top