Advertisement

Collision between two spheres - new velocities?

Started by February 13, 2002 12:38 PM
12 comments, last by BeanDog 23 years ago
That''s a good point. However, just sticking to 3 dimensions and stopping being sarcastic... ;-) sorry guys.

This is the simple code I am doing to find the new ball velocities. bvel and bvel2 are temporary vectors containing the old velocities of the balls. This does not seem to be correct. Could you make sure I got all your v''s separate from your V''s?


D3DXVECTOR3 vCOM = (bvel + bvel2)/2;//velocity of center of mass
D3DXVec3Normalize(&vCOM, &vCOM);

D3DXVECTOR3 vComponent = D3DXVec3Dot(&bvel, &vCOM) * vCOM;

ball->m_vVelocity = 2 * vComponent - bvel;


D3DXVECTOR3 vComponent2 = D3DXVec3Dot(&bvel2, &vCOM) * vCOM;

ball2->m_vVelocity = 2 * vComponent2 - bvel2;




~BenDilts( void );
Perhaps I failed to mention that the balls may not hit directly. Your math only takes into account the direction they are moving in, not the point at which they hit. If two balls at (0,0,0) and (0,1,0) hit eachother, with the bottom one moving up and the bottom one moving down, they should react differently than if two balls at (0,0,0) and (0,.7,.3) collide (OK, not exact numbers, but you get the idea). Is there a way to take this into account?



~BenDilts( void );
Advertisement
I figured it out. Here''s what you do:

D3DXVECTOR3 dist = bpos2 - bpos;
D3DXVec3Normalize(&dist, &dist);
D3DXVECTOR3 cnorm = dist;//normal force DIRECTION affecting ball 1
D3DXVECTOR3 cnorm2 = -dist;//normal force DIRECTION affecting ball 2

//component of ball 1''s velocity pushing in direction cnorm2
//(toward ball 2)
D3DXVECTOR3 comp = D3DXVec3Dot(&bvel, &cnorm2)*cnorm2;

//component of ball 2''s velocity pushing in direction cnorm
//(toward ball 1)
D3DXVECTOR3 comp2 = D3DXVec3Dot(&bvel2, &cnorm)*cnorm;

ball->m_vVelocity = bvel - comp + comp2;
ball2->m_vVelocity = bvel2 - comp2 + comp;

All you do is switch the components of the velocities of the balls in the direction of the normal of the plane of collision.

Thanks for the help.



~BenDilts( void );
I''m not sure why you had a problem with the method I suggested. It is irrelevant at which points on the spheres contact is made as the computation is performed relative to the centre of mass of the system, which will ALWAYS lie at the contact point given two spheres of equal mass and volume. The velocity of each ball can be broken into a component in the direction of the velocity of the centre of mass and a component orthogonal to this. The orthogonal component will not be altered by an elastic collision. The component in the direction of the centre of mass velocity will change sign, since it is relative to the centre of mass velocity. I can only surmise that you did not compute the unit vector for the velocity of the centre of mass correctly.

It is always conceivable that I made a mistake in my maths as I am only human, but looking back over it I cannot find any flaws. It''s good that you found a solution though.

Cheers,

Timkin

This topic is closed to new replies.

Advertisement