Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Collision with more than two objects at once in code

  1. Sep 23, 2007 #1
    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:

    both collisions have happened at the same time

    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.
  2. jcsd
  3. Sep 23, 2007 #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:

    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?
  4. Sep 23, 2007 #3


    User Avatar
    Science Advisor
    Homework Helper

    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Collision with more than two objects at once in code
  1. More than efficient (Replies: 4)