Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (5 posts)

math behind 3d non-elastic collision

Last post 6/2/2010 4:55 PM by Torsten Borg. 4 replies.
  • 3/3/2010 12:07 PM

    math behind 3d non-elastic collision

    Hello everyone.
    Hope this will be usefull for many people :)
    First of all excuse me for any language errors ;)

    I want to model a 3d collision, to make it simple - between two spheres. As far as i'm concerned i'v got the physics covered
    just like in here : thttp://forums.xna.com/forums/t/48719.aspx 

    1. we need to calculate the angle of collision  - the dot product comes handy http://msdn.microsoft.com/en-us/library/bb196388.aspx this way we can determine how the object colided
    2. we need to find the vector of 'contact' (the one between the centers)
    3. as i see it we need to calculate how it coresponds to the momentum/velocity vector of object - this should give us the amount of momentum of object A to be transferred to object B - this probably can be done somehow with the dot product ( can it?)
    having the the amounts of momentum to be strnsfered we add them to objects just like it is showned in included above topic.

    All of this is fairli simple in 2d, you can do this on paper but when it comes to 3d vectors it gest me a bit confused.
    Can someone tell me then, how can I calculate in 3d the amount of Momentum vector that should be applied to another object ?  - the number three above.

    the other thing that concerns me is how that model will react if one of the objects is static, and even more: has mass sygnificantly greater than the object that hits it. (as i see it the moving object should bounce of, but according to this model no momentum will be applied to him, as the other object is static - it'll statrt to move after the collision)


  • 3/3/2010 1:30 PM In reply to

    Re: math behind 3d non-elastic collision

    Answer
    Reply Quote
    To be honest, it sounds like your model is pretty spot on. Think about the Law of Conservation of Momentum: m1v1 = m2v2. It states that when the momentum of one object is applied to another, the amount of momentum is equal and related to mass and velocity. This means when two objects collide non-elastically, they swap momentums.

    If one of your objects is static, it has velocity 0 and therefore momentum 0 (since anything times 0 is zero). Now call the static sphere1 and call the moving, less massive sphere sphere2. If we say that mass is not lost by either object in the collision, the law above then describes their impact as this:

    m1v1before = m2v2after      substituting the velocity of the static sphere leads to        m1 * 0 = m2 * v2after implying that v2after = 0

    m2v2before = m1v1after                        solving for v1after leads to                                v1after = (m2v2before) / m1 != 0 since v2before != 0

    So, the lesson here is, no matter how big the static one is, and no matter how slow the moving one is, they always switch when they hit. To clarify though, the magnitude of a vector (in any number of dimensions) is square root of the sums of the components squared:

    |x| = sqrt(x * x)    <- you might have noticed |x| is the same notation as absolute value--no accident
    |(x, y)| = sqrt(x * x + y * y)
    |(x, y, z)| = sqrt(x * x + y * y + z * z)
    .
    .
    .

    And the angle, well that's much more complicated and I can't quite think of it at the moment. If you need to know, reply, and I'll look into it.
  • 3/3/2010 2:12 PM In reply to

    Re: math behind 3d non-elastic collision

    Answer
    Reply Quote
    Yes, you have the physics down pretty good.
    The way I did it when I made this learning project was to convert my momentum vectors from an (X, Y, Z) coordinate system to a ('collisionNormal', BiNormal, 'Tangent') system to resolve collisions. That's kind of my own nomenclature and I didn't concern myself with the bN because pool is essentially a 2d endeavor as far as linear motion is concerned . My 'collisionNormal' is the same as your 'vector of contact'. I converted them just like you with the dot product.

    So now you have a cN component of the momentums.

    Azrael pl:
    Can someone tell me then, how can I calculate in 3d the amount of Momentum vector that should be applied to another object ?
    Both balls must lose there cN components as they can no longer travel 'into' each other anymore, yet 'conservation of energy' requires no loss of combined momentum here. It turns out that as in real life they simply swap cN components. They give up their energy in that direction to each other. This is not dissimilar to simply negating an x or y value in 2d to 'bounce' a ball off a wall. Once swapped, convert momentums back to (X,Y, Z) coordinate system.

    Azrael pl:
    the other thing that concerns me is how that model will react if one of the objects is static, and even more: has mass sygnificantly greater than the object that hits it.
     Now the new momentum divided by mass gives a new velocity in the proper direction. Proper velocity works itself out if you store and manipulate momentum. Per Newton: velocity = momentum / mass. If before the collision, the momentum was zero, after collision it will be in the direction of the other balls cN. If heavy mass, velocity will be low, if light mass, velocity will be fast.

    If it helps, here is the code from the pool game I made... (go easy on me.. I used the word 'lineal' when I meant 'linear' :-)... * embarrassed* ). Also, since pool on a flat level surface is essentially a 2d operation, the 3rd component wasn't needed for my purposes but if you convert the 3d vector from xyz to cN,bN,T, ultimately, you would still just swap cN components like I did & convert back.


  • 3/3/2010 4:44 PM In reply to

    Re: math behind 3d non-elastic collision

    Wow, tank you both very much.
    I've never got such good answers in such a short time :)

    I'll try to adapt Steves code(thanks again there:)), but from what i've already noticed, is that actually dot product should be used in my 3rd step not in first (between collision normal and momentum of the object). So this is the main thing i was not sure of :)

    And Deedub, thanks for reminding me a few things. I also thought about Conservation of Momentum as i think  it'll be usefull when in one  'update'  I'll detect  a collision of more than two objects together. Not keeping track of how many object have been hit would cause a drastic increase in overal energy. At least that's the way i see it :)

    When I'll have some results and if the topic won't be closed by that time i'll make you know how it turned out:)
  • 6/2/2010 4:55 PM In reply to

    Re: math behind 3d non-elastic collision

    Thanks Steve...you finally put me on the right track after Googling and reading a lot of garbish....

Page 1 of 1 (5 posts) Previous Discussion Next Discussion
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG