velocity vector
- by wanderer
Hi,
I am trying to simulate a collision. The collision is shown here http://www.freeimagehosting.net/image.php?c5ae01b476.jpg
A particle falls down on a sphere and a collision between sphere and particle takes place. The sphere always remain stationary and the collision itself is not elastic. So if the particle falls directly n top of sphere, the velocity of particle will become zero. I was trying to set the velocity of particle to be zero after the collision. But that does not give good simulation when the collision does not occur on top of sphere but along the side of sphere.
So now after the collision i need to make sure that the particle has a velocity which is orthogonal to the vector of the point of collision from the center of sphere. The velocity along the vector from center of sphere to point of collision should become zero. How do i do that?
I am a bit mathematically challenged but i think it has something to do with dot product of vectors. Or maybe i am wrong :)
I have the initial velocity vector and 'radiusvector' say :-
1)velocity <-1.03054, -1.56563, 1.33341e-016
2) radius vector <2.04406, 2.19587, 1.0514
Pseudo code for the problem is:
foreach( particle particle in particlesCollections)
{
//sphere.x, sphere.y sphere.z give the center of the sphere
dist = particle.pos-vector(sphere.x,sphere.y,sphere.z);
//detect if a collision has taken place.
if (dist.mag < sphere.radius)
{
rVector=dist/dist.mag*sphere.radius;
particle.pos=vector(sphere.x,sphere.y,sphere.z) + rVector;
//particle.Velocity gives the velocity vector of the particle at the time of collision
//i need to modify particle.Velocity so that the component of velocity that runs along
// with the rvector becomes zero as i have a non elsatic collision. The remaining
//velocity that the particle will have is the one which runs along with tangent to the
//rVector. The sphere remains stationary.
//example values: particle.Velocity == <-1.03054, -1.56563, .006>
//and rVector = <2.04406, 2.19587, 1.0514>
}
}
Thanks