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

  • Thread starter r4nd0m
  • Start date
  • Tags
    Collision
In summary, the problem involves determining the first collision between two rectangles, each with a given velocity vector, in an orthogonal plane. To solve this, you can treat one rectangle as motionless and the other as moving at the relative velocity. The two rectangles will intersect if the vertical and horizontal distances between their centers are less than or equal to certain values. By plotting these distances over time, you can solve for the points of intersection and determine if they occur within the given intervals.
  • #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
 
Mathematics news on Phys.org
  • #2
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.
 
  • #3


Yes, this problem can be solved using mathematical formulas. To determine the first collision point, you will need to calculate the equations of motion for both rectangles, taking into account their velocities. Then, you can set up a system of equations to find the point where the equations intersect, which would be the first collision point. This can be done using techniques such as finding the intersection of two lines or solving simultaneous equations. Additionally, you will need to consider the dimensions and positions of the rectangles to determine if a collision will actually occur. It may also be helpful to create a visual representation of the problem to better understand the scenario and make calculations easier.
 

1. What is a "collision of rectangles" in science?

A collision of rectangles is a concept in physics that describes the interaction between two rectangular objects. This can occur when the two objects come into contact with each other or when they overlap in space.

2. How is the collision of rectangles calculated?

The collision of rectangles is typically calculated using principles of conservation of momentum and energy. This involves determining the initial velocities and masses of the objects, as well as the forces acting on them during the collision.

3. What factors affect the outcome of a collision between rectangles?

The outcome of a collision between rectangles can be affected by various factors such as the initial velocities and masses of the objects, the angles at which they collide, and the presence of external forces such as friction.

4. What are some real-world applications of the collision of rectangles?

The collision of rectangles has many real-world applications, including in sports such as billiards, where the movement of the balls can be described using principles of collision between rectangles. It is also used in engineering and design to predict the behavior of objects in collisions and prevent potential accidents.

5. Can the collision of rectangles be perfectly elastic?

In theory, the collision of rectangles can be perfectly elastic, meaning that no energy is lost during the collision and the objects bounce off each other with no change in kinetic energy. However, in reality, there will always be some energy loss due to factors such as friction and deformation of the objects.

Similar threads

Replies
32
Views
897
Replies
2
Views
121
  • Introductory Physics Homework Help
Replies
34
Views
676
  • Introductory Physics Homework Help
Replies
2
Views
2K
Replies
1
Views
2K
  • Programming and Computer Science
Replies
8
Views
867
  • General Math
Replies
7
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
15K
  • Differential Equations
Replies
3
Views
232
Replies
6
Views
2K
Back
Top