Collision with more than two objects at once in code

In summary, the conversation discusses a physics problem involving collisions between multiple balls. The question is raised about whether object E will receive any vertical velocity and why. The new velocities of the objects after the collisions are also discussed. The conversation also touches on programming and constructing a physics engine, with the suggestion to look into threading and the reminder that in the real world, collisions do not happen simultaneously but propagate at the speed of sound. The suggestion is made to handle the collisions sequentially by pretending the objects are a small distance apart.
  • #1
Luke_M
10
0
Balls A,B,C,D are traveling at V=1 to the right next to each other like a train they hit ball E whom is stationary. At the exact instant ball F is traveling down and hits A, F is traveling at V=1 but down

Here is a diagram this is birds eye view:

*=collision
both collisions have happened at the same time
|
|
V
F
*
-------->ABCD*E



A: Vx=1 m=10
B: Vx=1 m=10
C: Vx=1 m=20
D: Vx=1 m=10
E: Vx=0 m=60
F: Vy=1 m=10

will object E receive any Vy ?
why not ?
what are the new V's ?
I need to know how to work this out as I am making a physics model in my game.

If you are a programmer maybe you can also answer this question:
In the real world collisions can happen all at once like in my above example. How can I do this in code ? I can only do them sequentially with for loops. is this normal practice in constructing a physics engine. Because if I do the collision between F and A after the other collisions A's new V will incorrectly not be included in the calculation.
Thanks in advance.
 
Physics news on Phys.org
  • #2
For programming I think that you need to take a look at a concept called "threading" not all languages support it, but Java does and I believe C++ does as well.

Here is a great place to start:
http://java.sun.com/docs/books/tutorial/essential/concurrency/

Plus why are you using loops, can't you just use a couple of equations to model this and just put those into your code?
 
  • #3
IN the real world collisions don't happen "all at once". They take a finite amount of time, and the effects propagate through the bodies at the speed of sound, so if one side of a ball collides with something the other side of the ball doesn't "know" anything about that till a finite amount of time later. The typical speed of sound in a solid is a few km/sec, or a few mm per microsecond.

The easy way to program this is to pretend the balls are all a small distance apart. So in your example first, F collides with A and D collides with E (and those two collisions don't interact with each other).

Next, because D has slowed down, C collides with D, and so on.
 

1. What is a collision with multiple objects in code?

A collision with multiple objects in code refers to the scenario where two or more objects in a computer program interact with each other by overlapping or colliding in some way. This can be in the form of physical collisions, such as two objects bumping into each other, or logical collisions, where the objects' properties or attributes affect each other.

2. What are the challenges of implementing collision with multiple objects in code?

One of the main challenges of implementing collision with multiple objects in code is accurately detecting and handling these collisions. This requires precise calculations and efficient algorithms to determine when and how the objects intersect. Additionally, managing the interactions between multiple objects can become complex and lead to unexpected behavior if not carefully designed.

3. How can we optimize collision detection with multiple objects in code?

To optimize collision detection with multiple objects in code, we can use techniques such as spatial partitioning or broad-phase collision detection. These approaches involve dividing the game world into smaller regions or using data structures to quickly narrow down the potential collisions between objects, making the detection process more efficient.

4. What are some common methods for handling collisions with multiple objects in code?

Some common methods for handling collisions with multiple objects in code include using physics engines, implementing collision response algorithms, or using event-based systems. Physics engines can simulate realistic physical interactions between objects, while collision response algorithms determine how the objects should behave after colliding. Event-based systems allow for more flexibility in handling different types of collisions and their effects on the objects involved.

5. How can we prevent objects from overlapping or colliding in code?

To prevent objects from overlapping or colliding in code, we can use collision avoidance techniques, such as the Separating Axis Theorem or velocity-based methods. These involve adjusting the objects' positions or velocities to avoid collisions, rather than handling them after they occur. Additionally, careful design and testing can help identify and fix any potential issues with collisions in the code.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Replies
49
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
841
  • Mechanics
3
Replies
80
Views
10K
Replies
5
Views
2K
Replies
14
Views
7K
Replies
1
Views
775
Replies
19
Views
3K
Replies
24
Views
1K
Back
Top